function testCreationOfSnapShots()
 {
     $this->assertEmpty(self::$initSnap->timePassed());
     $this->assertNotEmpty(self::$initSnap->numClassesDeclaredSincePreviousSnapshot());
     $this->assertNotEmpty(self::$initSnap->numFilesIncludedSincePreviousSnapshot());
     usleep(100);
     $snapShot = new PerformanceSnapshot(self::$initSnap);
     $this->assertNotEmpty($snapShot->timePassed());
     $bytes = str_repeat('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 10000);
     $snapShot = new PerformanceSnapshot(self::$initSnap);
     $this->assertNotEmpty($snapShot->memoryAllocationDifference());
 }
 /**
  * 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);
 }
Esempio n. 3
0
 /**
  * @param PerformanceSnapshotInterface $snapshot
  * @param $snapshotName
  */
 private function keepTrackOfPeakingMemoryAllocation(PerformanceSnapshotInterface $snapshot, $snapshotName)
 {
     if ($snapshot->peakMemoryAllocated() > $this->highestMemoryPeak) {
         $this->highestMemoryPeak = $snapshot->peakMemoryAllocated();
         $this->nameOfSnapShotThatHasMemoryPeak = $snapshotName;
     }
 }