9
9
# Company : Code24 BV, The Netherlands #
10
10
# Author : Sergey Dryabzhinsky #
11
11
# Company : Rusoft Ltd, Russia #
12
- # Date : MAy 01 , 2019 #
13
- # Version : 1.0.33 #
12
+ # Date : May 10 , 2019 #
13
+ # Version : 1.0.34 #
14
14
# License : Creative Commons CC-BY license #
15
15
# Website : https://github.com/rusoft/php-simple-benchmark-script #
16
16
# Website : https://git.rusoft.ru/open-source/php-simple-benchmark-script #
17
17
# #
18
18
################################################################################
19
19
*/
20
20
21
- $ scriptVersion = '1.0.33 ' ;
21
+ $ scriptVersion = '1.0.34 ' ;
22
22
23
23
ini_set ('display_errors ' , 0 );
24
24
ini_set ('error_log ' , null );
272
272
// Special for nginx
273
273
header ('X-Accel-Buffering: no ' );
274
274
275
+ if (file_exists ('/usr/bin/taskset ' )) {
276
+ shell_exec ('/usr/bin/taskset -c -p 0 ' . getmypid ());
277
+ }
278
+
275
279
/** ------------------------------- Main Constants ------------------------------- */
276
280
277
281
$ line = str_pad ("- " , 91 , "- " );
@@ -502,13 +506,17 @@ function getCpuInfo($fireUpCpu = false)
502
506
{
503
507
$ cpu = array (
504
508
'model ' => '' ,
509
+ 'vendor ' => '' ,
505
510
'cores ' => 0 ,
506
511
'mhz ' => 0.0 ,
512
+ 'max-mhz ' => 0.0 ,
513
+ 'min-mhz ' => 0.0 ,
507
514
'mips ' => 0.0
508
515
);
509
516
510
517
if (!is_readable ('/proc/cpuinfo ' )) {
511
518
$ cpu ['model ' ] = 'Unknown ' ;
519
+ $ cpu ['vendor ' ] = 'Unknown ' ;
512
520
$ cpu ['cores ' ] = 1 ;
513
521
return $ cpu ;
514
522
}
@@ -518,6 +526,9 @@ function getCpuInfo($fireUpCpu = false)
518
526
$ i = 30000000 ;
519
527
while ($ i --) ;
520
528
}
529
+ if (file_exists ('/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ' )) {
530
+ $ cpu ['mhz ' ] = ((int )file_get_contents ('/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ' ))/1000.0 ;
531
+ }
521
532
522
533
// Code from https://github.com/jrgp/linfo/blob/master/src/Linfo/OS/Linux.php
523
534
// Adopted
@@ -553,7 +564,8 @@ function getCpuInfo($fireUpCpu = false)
553
564
$ cpu ['mhz ' ] = (int )hexdec ($ value ) / 1000000.0 ;
554
565
}
555
566
break ;
556
- case 'bogomips ' : // twice of MHz usualy
567
+ case 'bogomips ' : // twice of MHz usualy on Intel/Amd
568
+ case 'BogoMIPS ' : // twice of MHz usualy on Intel/Amd
557
569
if (empty ($ cpu ['mhz ' ])) {
558
570
$ cpu ['mhz ' ] = (float )$ value / 2.0 ;
559
571
}
@@ -570,6 +582,57 @@ function getCpuInfo($fireUpCpu = false)
570
582
}
571
583
}
572
584
585
+ // Raspberry Pi or other ARM board etc.
586
+ $ cpuData = explode ("\n" , shell_exec ('lscpu ' ));
587
+ foreach ($ cpuData as $ line ) {
588
+ $ line = explode (': ' , $ line , 2 );
589
+
590
+ if (!array_key_exists (1 , $ line )) {
591
+ continue ;
592
+ }
593
+
594
+ $ key = trim ($ line [0 ]);
595
+ $ value = trim ($ line [1 ]);
596
+
597
+ // What we want are bogomips, MHz, processor, and Model.
598
+ switch ($ key ) {
599
+ // CPU model
600
+ case 'Model name ' :
601
+ if (empty ($ cpu ['model ' ])) {
602
+ $ cpu ['model ' ] = $ value ;
603
+ }
604
+ break ;
605
+ // cores
606
+ case 'CPU(s) ' :
607
+ if (empty ($ cpu ['cores ' ])) {
608
+ $ cpu ['cores ' ] = (int )$ value ;
609
+ }
610
+ break ;
611
+ // MHz
612
+ case 'CPU max MHz ' :
613
+ if (empty ($ cpu ['max-mhz ' ])) {
614
+ $ cpu ['max-mhz ' ] = (int )$ value ;
615
+ }
616
+ break ;
617
+ case 'CPU min MHz ' :
618
+ if (empty ($ cpu ['min-mhz ' ])) {
619
+ $ cpu ['min-mhz ' ] = (int )$ value ;
620
+ }
621
+ break ;
622
+ // vendor
623
+ case 'Vendor ID ' :
624
+ if (empty ($ cpu ['vendor ' ])) {
625
+ $ cpu ['vendor ' ] = $ value ;
626
+ }
627
+ break ;
628
+ }
629
+ }
630
+
631
+ if ($ cpu ['vendor ' ] == 'ARM ' ) {
632
+ // Unusable
633
+ $ cpu ['mips ' ] = 0 ;
634
+ }
635
+
573
636
return $ cpu ;
574
637
}
575
638
@@ -654,10 +717,18 @@ function mymemory_usage()
654
717
655
718
$ cpuInfo = getCpuInfo ();
656
719
// CPU throttling?
657
- if (abs ($ cpuInfo ['mips ' ] - $ cpuInfo ['mhz ' ]) > 300 ) {
658
- print ("<pre> \n<<< WARNING >>> \nCPU is in powersaving mode? Set CPU governor to 'performance'! \n Fire up CPU and recalculate MHz! \n</pre> " . PHP_EOL );
659
- // TIME WASTED HERE
660
- $ cpuInfo = getCpuInfo (true );
720
+ if ($ cpuInfo ['mips ' ] && $ cpuInfo ['mhz ' ]) {
721
+ if (abs ($ cpuInfo ['mips ' ] - $ cpuInfo ['mhz ' ]) > 300 ) {
722
+ print ("<pre> \n<<< WARNING >>> \nCPU is in powersaving mode? Set CPU governor to 'performance'! \n Fire up CPU and recalculate MHz! \n</pre> " . PHP_EOL );
723
+ // TIME WASTED HERE
724
+ $ cpuInfo = getCpuInfo (true );
725
+ }
726
+ } else if ($ cpuInfo ['max-mhz ' ] && $ cpuInfo ['mhz ' ]) {
727
+ if (abs ($ cpuInfo ['max-mhz ' ] - $ cpuInfo ['mhz ' ]) > 300 ) {
728
+ print ("<pre> \n<<< WARNING >>> \nCPU is in powersaving mode? Set CPU governor to 'performance'! \n Fire up CPU and recalculate MHz! \n</pre> " . PHP_EOL );
729
+ // TIME WASTED HERE
730
+ $ cpuInfo = getCpuInfo (true );
731
+ }
661
732
}
662
733
663
734
$ memoryLimit = min (getPhpMemoryLimitBytes (), getSystemMemoryFreeLimitBytes ());
0 commit comments