Exemplo n.º 1
0
 public static function collect()
 {
     $processors = count(CpuInfo::get());
     $loadavg = explode(' ', file_get_contents('/proc/loadavg'));
     $loadavg = array_slice($loadavg, 0, 3);
     $loadavg = array_map(function ($item) use($processors) {
         return $item * 100 / $processors;
     }, $loadavg);
     return ['loadavg' => $loadavg];
 }
Exemplo n.º 2
0
 public function testDetect()
 {
     $command = "echo 'processor\t: 0\nvendor_id\t: GenuineIntel\ncpu family\t: 6\nmodel\t\t: 42\nmodel name\t: Romain Neutron Supa CPU\nstepping\t: 7\nmicrocode\t: 0x1a\ncpu MHz\t\t: 1200.000\ncache size\t: 4096 KB\nphysical id\t: 0\nsiblings\t: 4\ncore id\t\t: 1\ncpu cores\t: 12\napicid\t\t: 0\ninitial apicid\t: 0\nfpu\t\t: yes\nfpu_exception\t: yes\ncpuid level\t: 13\nwp\t\t: yes\nflags\t\t: sse4\nbogomips\t: 5586.84\nclflush size\t: 64\ncache_alignment\t: 64\naddress sizes\t: 36 bits physical, 48 bits virtual\npower management:\n\n\nprocessor\t: 1\nvendor_id\t: GenuineIntel\ncpu family\t: 6\nmodel\t\t: 46\nmodel name\t: Otto Von Schirach DSP\nstepping\t: 7\nmicrocode\t: 0x1a\ncpu MHz\t\t: 800.000\ncache size\t: 4096 KB\nphysical id\t: 0\nsiblings\t: 4\ncore id\t\t: 2\ncpu cores\t: 11\napicid\t\t: 2\ninitial apicid\t: 2\nfpu\t\t: yes\nfpu_exception\t: yes\ncpuid level\t: 13\nwp\t\t: yes\nflags\t\t: sse1 sse2\nbogomips\t: 5587.05\nclflush size\t: 64\ncache_alignment\t: 64\naddress sizes\t: 36 bits physical, 48 bits virtual\npower management:\n\n\n'";
     $cpuinfos = CpuInfo::detect($command);
     $this->assertInstanceOf('\\Neutron\\System\\CpuInfo', $cpuinfos);
     $cpus = $cpuinfos->cpus();
     $this->assertEquals(2, count($cpus));
     $cpu1 = $cpus[0];
     $cpu2 = $cpus[1];
     $this->assertEquals('Romain Neutron Supa CPU', $cpu1->getmodelName());
     $this->assertEquals('Otto Von Schirach DSP', $cpu2->getmodelName());
     $this->assertEquals(23, $cpuinfos->getTotalCores());
     $this->assertEquals(array('sse4'), $cpu1->getFlags());
     $this->assertEquals(array('sse1', 'sse2'), $cpu2->getFlags());
     $this->assertEquals('4096 KB', $cpu1->getCache());
     $this->assertEquals('4096 KB', $cpu2->getCache());
     $this->assertEquals('42', $cpu1->getModel());
     $this->assertEquals('46', $cpu2->getModel());
     $this->assertEquals('GenuineIntel', $cpu1->getVendor());
     $this->assertEquals('GenuineIntel', $cpu2->getVendor());
     $this->assertEquals(1, $cpu1->getId());
     $this->assertEquals(2, $cpu2->getId());
 }