/** * PerformanceSnapshot constructor. * @param PerformanceSnapshotInterface|null $prev */ public function __construct(PerformanceSnapshotInterface $prev = null) { $this->created = Utils::getMicroTime(); if ($prev instanceof PerformanceSnapshotInterface) { $this->timePassed = bcsub($this->creationTime(), $prev->creationTime(), 4); } else { $prev = new PerformanceSnapshotNullObject(); $this->timePassed = 0; } $this->numClassesDeclaredTotal = count(get_declared_classes()); $this->numFilesIncludedTotal = count(get_included_files()); $this->numClassesDeclared = $this->numClassesDeclaredTotal - $prev->numTotalClassesDeclared(); $this->numFilesIncluded = $this->numFilesIncludedTotal - $prev->numTotalFilesIncluded(); $this->memoryAllocated = round(memory_get_usage() / 1024 / 1024, 4); $this->memoryAllocatedDiff = bcsub($this->memoryAllocated, $prev->memoryAllocated(), 4); }
/** * PerformanceSnapshot constructor. * @param PerformanceInfoInterface|null $prev */ public function __construct(PerformanceInfoInterface $prev = null) { $timePassed = 0; $creationTime = Utils::getMicroTime(); if ($prev instanceof PerformanceInfoInterface) { $timePassed = bcsub($creationTime, $prev->creationTime(), 4); } else { $prev = new NullPerformanceInfoObject(); } $numClassesDeclared = count(get_declared_classes()); $numFilesIncluded = count(get_included_files()); $this->numClassesDeclaredSincePreviousSnapShot = $numClassesDeclared - $prev->numClassesDeclared(); $this->numFilesIncludedSincePreviousSnapShot = $numFilesIncluded - $prev->numFilesIncluded(); $memoryAllocated = Utils::toMegaBytes(memory_get_usage()); $this->memoryAllocatedDiff = bcsub($memoryAllocated, $prev->memoryAllocated(), 4); parent::__construct($creationTime, $timePassed, $numClassesDeclared, $numFilesIncluded, $memoryAllocated); }
/** * @inheritDoc */ public function getPerformanceInfo() { return new PerformanceInfo(Utils::getMicroTime(), bcsub(Utils::getMicroTime(), $this->startTime, 4), count(get_declared_classes()), count(get_included_files()), round(memory_get_usage() / 1024 / 1024, 4)); }