-
-
Notifications
You must be signed in to change notification settings - Fork 296
/
cpu.js
1704 lines (1614 loc) · 59.8 KB
/
cpu.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'use strict';
// @ts-check
// ==================================================================================
// cpu.js
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2022
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
// ==================================================================================
// 4. CPU
// ----------------------------------------------------------------------------------
const os = require('os');
const exec = require('child_process').exec;
const execSync = require('child_process').execSync;
const fs = require('fs');
const util = require('./util');
let _platform = process.platform;
const _linux = (_platform === 'linux' || _platform === 'android');
const _darwin = (_platform === 'darwin');
const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
const _netbsd = (_platform === 'netbsd');
const _sunos = (_platform === 'sunos');
let _cpu_speed = 0;
let _current_cpu = {
user: 0,
nice: 0,
system: 0,
idle: 0,
irq: 0,
load: 0,
tick: 0,
ms: 0,
currentLoad: 0,
currentLoadUser: 0,
currentLoadSystem: 0,
currentLoadNice: 0,
currentLoadIdle: 0,
currentLoadIrq: 0,
rawCurrentLoad: 0,
rawCurrentLoadUser: 0,
rawCurrentLoadSystem: 0,
rawCurrentLoadNice: 0,
rawCurrentLoadIdle: 0,
rawCurrentLoadIrq: 0
};
let _cpus = [];
let _corecount = 0;
const AMDBaseFrequencies = {
'8346': '1.8',
'8347': '1.9',
'8350': '2.0',
'8354': '2.2',
'8356|SE': '2.4',
'8356': '2.3',
'8360': '2.5',
'2372': '2.1',
'2373': '2.1',
'2374': '2.2',
'2376': '2.3',
'2377': '2.3',
'2378': '2.4',
'2379': '2.4',
'2380': '2.5',
'2381': '2.5',
'2382': '2.6',
'2384': '2.7',
'2386': '2.8',
'2387': '2.8',
'2389': '2.9',
'2393': '3.1',
'8374': '2.2',
'8376': '2.3',
'8378': '2.4',
'8379': '2.4',
'8380': '2.5',
'8381': '2.5',
'8382': '2.6',
'8384': '2.7',
'8386': '2.8',
'8387': '2.8',
'8389': '2.9',
'8393': '3.1',
'2419EE': '1.8',
'2423HE': '2.0',
'2425HE': '2.1',
'2427': '2.2',
'2431': '2.4',
'2435': '2.6',
'2439SE': '2.8',
'8425HE': '2.1',
'8431': '2.4',
'8435': '2.6',
'8439SE': '2.8',
'4122': '2.2',
'4130': '2.6',
'4162EE': '1.7',
'4164EE': '1.8',
'4170HE': '2.1',
'4174HE': '2.3',
'4176HE': '2.4',
'4180': '2.6',
'4184': '2.8',
'6124HE': '1.8',
'6128HE': '2.0',
'6132HE': '2.2',
'6128': '2.0',
'6134': '2.3',
'6136': '2.4',
'6140': '2.6',
'6164HE': '1.7',
'6166HE': '1.8',
'6168': '1.9',
'6172': '2.1',
'6174': '2.2',
'6176': '2.3',
'6176SE': '2.3',
'6180SE': '2.5',
'3250': '2.5',
'3260': '2.7',
'3280': '2.4',
'4226': '2.7',
'4228': '2.8',
'4230': '2.9',
'4234': '3.1',
'4238': '3.3',
'4240': '3.4',
'4256': '1.6',
'4274': '2.5',
'4276': '2.6',
'4280': '2.8',
'4284': '3.0',
'6204': '3.3',
'6212': '2.6',
'6220': '3.0',
'6234': '2.4',
'6238': '2.6',
'6262HE': '1.6',
'6272': '2.1',
'6274': '2.2',
'6276': '2.3',
'6278': '2.4',
'6282SE': '2.6',
'6284SE': '2.7',
'6308': '3.5',
'6320': '2.8',
'6328': '3.2',
'6338P': '2.3',
'6344': '2.6',
'6348': '2.8',
'6366': '1.8',
'6370P': '2.0',
'6376': '2.3',
'6378': '2.4',
'6380': '2.5',
'6386': '2.8',
'FX|4100': '3.6',
'FX|4120': '3.9',
'FX|4130': '3.8',
'FX|4150': '3.8',
'FX|4170': '4.2',
'FX|6100': '3.3',
'FX|6120': '3.6',
'FX|6130': '3.6',
'FX|6200': '3.8',
'FX|8100': '2.8',
'FX|8120': '3.1',
'FX|8140': '3.2',
'FX|8150': '3.6',
'FX|8170': '3.9',
'FX|4300': '3.8',
'FX|4320': '4.0',
'FX|4350': '4.2',
'FX|6300': '3.5',
'FX|6350': '3.9',
'FX|8300': '3.3',
'FX|8310': '3.4',
'FX|8320': '3.5',
'FX|8350': '4.0',
'FX|8370': '4.0',
'FX|9370': '4.4',
'FX|9590': '4.7',
'FX|8320E': '3.2',
'FX|8370E': '3.3',
// ZEN Desktop CPUs
'1200': '3.1',
'Pro 1200': '3.1',
'1300X': '3.5',
'Pro 1300': '3.5',
'1400': '3.2',
'1500X': '3.5',
'Pro 1500': '3.5',
'1600': '3.2',
'1600X': '3.6',
'Pro 1600': '3.2',
'1700': '3.0',
'Pro 1700': '3.0',
'1700X': '3.4',
'Pro 1700X': '3.4',
'1800X': '3.6',
'1900X': '3.8',
'1920': '3.2',
'1920X': '3.5',
'1950X': '3.4',
// ZEN Desktop APUs
'200GE': '3.2',
'Pro 200GE': '3.2',
'220GE': '3.4',
'240GE': '3.5',
'3000G': '3.5',
'300GE': '3.4',
'3050GE': '3.4',
'2200G': '3.5',
'Pro 2200G': '3.5',
'2200GE': '3.2',
'Pro 2200GE': '3.2',
'2400G': '3.6',
'Pro 2400G': '3.6',
'2400GE': '3.2',
'Pro 2400GE': '3.2',
// ZEN Mobile APUs
'Pro 200U': '2.3',
'300U': '2.4',
'2200U': '2.5',
'3200U': '2.6',
'2300U': '2.0',
'Pro 2300U': '2.0',
'2500U': '2.0',
'Pro 2500U': '2.2',
'2600H': '3.2',
'2700U': '2.0',
'Pro 2700U': '2.2',
'2800H': '3.3',
// ZEN Server Processors
'7351': '2.4',
'7351P': '2.4',
'7401': '2.0',
'7401P': '2.0',
'7551P': '2.0',
'7551': '2.0',
'7251': '2.1',
'7261': '2.5',
'7281': '2.1',
'7301': '2.2',
'7371': '3.1',
'7451': '2.3',
'7501': '2.0',
'7571': '2.2',
'7601': '2.2',
// ZEN Embedded Processors
'V1500B': '2.2',
'V1780B': '3.35',
'V1202B': '2.3',
'V1404I': '2.0',
'V1605B': '2.0',
'V1756B': '3.25',
'V1807B': '3.35',
'3101': '2.1',
'3151': '2.7',
'3201': '1.5',
'3251': '2.5',
'3255': '2.5',
'3301': '2.0',
'3351': '1.9',
'3401': '1.85',
'3451': '2.15',
// ZEN+ Desktop
'1200|AF': '3.1',
'2300X': '3.5',
'2500X': '3.6',
'2600': '3.4',
'2600E': '3.1',
'1600|AF': '3.2',
'2600X': '3.6',
'2700': '3.2',
'2700E': '2.8',
'Pro 2700': '3.2',
'2700X': '3.7',
'Pro 2700X': '3.6',
'2920X': '3.5',
'2950X': '3.5',
'2970WX': '3.0',
'2990WX': '3.0',
// ZEN+ Desktop APU
'Pro 300GE': '3.4',
'Pro 3125GE': '3.4',
'3150G': '3.5',
'Pro 3150G': '3.5',
'3150GE': '3.3',
'Pro 3150GE': '3.3',
'3200G': '3.6',
'Pro 3200G': '3.6',
'3200GE': '3.3',
'Pro 3200GE': '3.3',
'3350G': '3.6',
'Pro 3350G': '3.6',
'3350GE': '3.3',
'Pro 3350GE': '3.3',
'3400G': '3.7',
'Pro 3400G': '3.7',
'3400GE': '3.3',
'Pro 3400GE': '3.3',
// ZEN+ Mobile
'3300U': '2.1',
'PRO 3300U': '2.1',
'3450U': '2.1',
'3500U': '2.1',
'PRO 3500U': '2.1',
'3500C': '2.1',
'3550H': '2.1',
'3580U': '2.1',
'3700U': '2.3',
'PRO 3700U': '2.3',
'3700C': '2.3',
'3750H': '2.3',
'3780U': '2.3',
// ZEN2 Desktop CPUS
'3100': '3.6',
'3300X': '3.8',
'3500': '3.6',
'3500X': '3.6',
'3600': '3.6',
'Pro 3600': '3.6',
'3600X': '3.8',
'3600XT': '3.8',
'Pro 3700': '3.6',
'3700X': '3.6',
'3800X': '3.9',
'3800XT': '3.9',
'3900': '3.1',
'Pro 3900': '3.1',
'3900X': '3.8',
'3900XT': '3.8',
'3950X': '3.5',
'3960X': '3.8',
'3970X': '3.7',
'3990X': '2.9',
'3945WX': '4.0',
'3955WX': '3.9',
'3975WX': '3.5',
'3995WX': '2.7',
// ZEN2 Desktop APUs
'4300GE': '3.5',
'Pro 4300GE': '3.5',
'4300G': '3.8',
'Pro 4300G': '3.8',
'4600GE': '3.3',
'Pro 4650GE': '3.3',
'4600G': '3.7',
'Pro 4650G': '3.7',
'4700GE': '3.1',
'Pro 4750GE': '3.1',
'4700G': '3.6',
'Pro 4750G': '3.6',
'4300U': '2.7',
'4450U': '2.5',
'Pro 4450U': '2.5',
'4500U': '2.3',
'4600U': '2.1',
'PRO 4650U': '2.1',
'4680U': '2.1',
'4600HS': '3.0',
'4600H': '3.0',
'4700U': '2.0',
'PRO 4750U': '1.7',
'4800U': '1.8',
'4800HS': '2.9',
'4800H': '2.9',
'4900HS': '3.0',
'4900H': '3.3',
'5300U': '2.6',
'5500U': '2.1',
'5700U': '1.8',
// ZEN2 - EPYC
'7232P': '3.1',
'7302P': '3.0',
'7402P': '2.8',
'7502P': '2.5',
'7702P': '2.0',
'7252': '3.1',
'7262': '3.2',
'7272': '2.9',
'7282': '2.8',
'7302': '3.0',
'7352': '2.3',
'7402': '2.8',
'7452': '2.35',
'7502': '2.5',
'7532': '2.4',
'7542': '2.9',
'7552': '2.2',
'7642': '2.3',
'7662': '2.0',
'7702': '2.0',
'7742': '2.25',
'7H12': '2.6',
'7F32': '3.7',
'7F52': '3.5',
'7F72': '3.2',
// Epyc (Milan)
'7763': '2.45',
'7713': '2.0',
'7713P': '2.0',
'7663': '2.0',
'7643': '2.3',
'75F3': '2.95',
'7543': '2.8',
'7543P': '2.8',
'7513': '2.6',
'7453': '2.75',
'74F3': '3.2',
'7443': '2.85',
'7443P': '2.85',
'7413': '2.65',
'73F3': '3.5',
'7343': '3.2',
'7313': '3.0',
'7313P': '3.0',
'72F3': '3.7',
// ZEN3
'5600X': '3.7',
'5800X': '3.8',
'5900X': '3.7',
'5950X': '3.4'
};
const socketTypes = {
1: 'Other',
2: 'Unknown',
3: 'Daughter Board',
4: 'ZIF Socket',
5: 'Replacement/Piggy Back',
6: 'None',
7: 'LIF Socket',
8: 'Slot 1',
9: 'Slot 2',
10: '370 Pin Socket',
11: 'Slot A',
12: 'Slot M',
13: '423',
14: 'A (Socket 462)',
15: '478',
16: '754',
17: '940',
18: '939',
19: 'mPGA604',
20: 'LGA771',
21: 'LGA775',
22: 'S1',
23: 'AM2',
24: 'F (1207)',
25: 'LGA1366',
26: 'G34',
27: 'AM3',
28: 'C32',
29: 'LGA1156',
30: 'LGA1567',
31: 'PGA988A',
32: 'BGA1288',
33: 'rPGA988B',
34: 'BGA1023',
35: 'BGA1224',
36: 'LGA1155',
37: 'LGA1356',
38: 'LGA2011',
39: 'FS1',
40: 'FS2',
41: 'FM1',
42: 'FM2',
43: 'LGA2011-3',
44: 'LGA1356-3',
45: 'LGA1150',
46: 'BGA1168',
47: 'BGA1234',
48: 'BGA1364',
49: 'AM4',
50: 'LGA1151',
51: 'BGA1356',
52: 'BGA1440',
53: 'BGA1515',
54: 'LGA3647-1',
55: 'SP3',
56: 'SP3r2',
57: 'LGA2066',
58: 'BGA1392',
59: 'BGA1510',
60: 'BGA1528',
61: 'LGA4189',
62: 'LGA1200',
63: 'LGA4677',
};
const socketTypesByName = {
'LGA1150': 'i7-5775C i3-4340 i3-4170 G3250 i3-4160T i3-4160 E3-1231 G3258 G3240 i7-4790S i7-4790K i7-4790 i5-4690K i5-4690 i5-4590T i5-4590S i5-4590 i5-4460 i3-4360 i3-4150 G1820 G3420 G3220 i7-4771 i5-4440 i3-4330 i3-4130T i3-4130 E3-1230 i7-4770S i7-4770K i7-4770 i5-4670K i5-4670 i5-4570T i5-4570S i5-4570 i5-4430',
'LGA1151': 'i9-9900KS E-2288G E-2224 G5420 i9-9900T i9-9900 i7-9700T i7-9700F i7-9700E i7-9700 i5-9600 i5-9500T i5-9500F i5-9500 i5-9400T i3-9350K i3-9300 i3-9100T i3-9100F i3-9100 G4930 i9-9900KF i7-9700KF i5-9600KF i5-9400F i5-9400 i3-9350KF i9-9900K i7-9700K i5-9600K G5500 G5400 i7-8700T i7-8086K i5-8600 i5-8500T i5-8500 i5-8400T i3-8300 i3-8100T G4900 i7-8700K i7-8700 i5-8600K i5-8400 i3-8350K i3-8100 E3-1270 G4600 G4560 i7-7700T i7-7700K i7-7700 i5-7600K i5-7600 i5-7500T i5-7500 i5-7400 i3-7350K i3-7300 i3-7100T i3-7100 G3930 G3900 G4400 i7-6700T i7-6700K i7-6700 i5-6600K i5-6600 i5-6500T i5-6500 i5-6400T i5-6400 i3-6300 i3-6100T i3-6100 E3-1270 E3-1270 T4500 T4400',
'1155': 'G440 G460 G465 G470 G530T G540T G550T G1610T G1620T G530 G540 G1610 G550 G1620 G555 G1630 i3-2100T i3-2120T i3-3220T i3-3240T i3-3250T i3-2100 i3-2105 i3-2102 i3-3210 i3-3220 i3-2125 i3-2120 i3-3225 i3-2130 i3-3245 i3-3240 i3-3250 i5-3570T i5-2500T i5-2400S i5-2405S i5-2390T i5-3330S i5-2500S i5-3335S i5-2300 i5-3450S i5-3340S i5-3470S i5-3475S i5-3470T i5-2310 i5-3550S i5-2320 i5-3330 i5-3350P i5-3450 i5-2400 i5-3340 i5-3570S i5-2380P i5-2450P i5-3470 i5-2500K i5-3550 i5-2500 i5-3570 i5-3570K i5-2550K i7-3770T i7-2600S i7-3770S i7-2600K i7-2600 i7-3770 i7-3770K i7-2700K G620T G630T G640T G2020T G645T G2100T G2030T G622 G860T G620 G632 G2120T G630 G640 G2010 G840 G2020 G850 G645 G2030 G860 G2120 G870 G2130 G2140 E3-1220L E3-1220L E3-1260L E3-1265L E3-1220 E3-1225 E3-1220 E3-1235 E3-1225 E3-1230 E3-1230 E3-1240 E3-1245 E3-1270 E3-1275 E3-1240 E3-1245 E3-1270 E3-1280 E3-1275 E3-1290 E3-1280 E3-1290'
};
function getSocketTypesByName(str) {
let result = '';
for (const key in socketTypesByName) {
const names = socketTypesByName[key].split(' ');
names.forEach(element => {
if (str.indexOf(element) >= 0) {
result = key;
}
});
}
return result;
}
function cpuManufacturer(str) {
let result = str;
str = str.toLowerCase();
if (str.indexOf('intel') >= 0) { result = 'Intel'; }
if (str.indexOf('amd') >= 0) { result = 'AMD'; }
if (str.indexOf('qemu') >= 0) { result = 'QEMU'; }
if (str.indexOf('hygon') >= 0) { result = 'Hygon'; }
if (str.indexOf('centaur') >= 0) { result = 'WinChip/Via'; }
if (str.indexOf('vmware') >= 0) { result = 'VMware'; }
if (str.indexOf('Xen') >= 0) { result = 'Xen Hypervisor'; }
if (str.indexOf('tcg') >= 0) { result = 'QEMU'; }
if (str.indexOf('apple') >= 0) { result = 'Apple'; }
return result;
}
function cpuBrandManufacturer(res) {
res.brand = res.brand.replace(/\(R\)+/g, '®').replace(/\s+/g, ' ').trim();
res.brand = res.brand.replace(/\(TM\)+/g, '™').replace(/\s+/g, ' ').trim();
res.brand = res.brand.replace(/\(C\)+/g, '©').replace(/\s+/g, ' ').trim();
res.brand = res.brand.replace(/CPU+/g, '').replace(/\s+/g, ' ').trim();
res.manufacturer = cpuManufacturer(res.brand);
let parts = res.brand.split(' ');
parts.shift();
res.brand = parts.join(' ');
return res;
}
function getAMDSpeed(brand) {
let result = '0';
for (let key in AMDBaseFrequencies) {
if ({}.hasOwnProperty.call(AMDBaseFrequencies, key)) {
let parts = key.split('|');
let found = 0;
parts.forEach(item => {
if (brand.indexOf(item) > -1) {
found++;
}
});
if (found === parts.length) {
result = AMDBaseFrequencies[key];
}
}
}
return parseFloat(result);
}
// --------------------------
// CPU - brand, speed
function getCpu() {
return new Promise((resolve) => {
process.nextTick(() => {
const UNKNOWN = 'unknown';
let result = {
manufacturer: UNKNOWN,
brand: UNKNOWN,
vendor: '',
family: '',
model: '',
stepping: '',
revision: '',
voltage: '',
speed: 0,
speedMin: 0,
speedMax: 0,
governor: '',
cores: util.cores(),
physicalCores: util.cores(),
performanceCores: util.cores(),
efficiencyCores: 0,
processors: 1,
socket: '',
flags: '',
virtualization: false,
cache: {}
};
cpuFlags().then(flags => {
result.flags = flags;
result.virtualization = flags.indexOf('vmx') > -1 || flags.indexOf('svm') > -1;
if (_darwin) {
exec('sysctl machdep.cpu hw.cpufrequency_max hw.cpufrequency_min hw.packages hw.physicalcpu_max hw.ncpu hw.tbfrequency hw.cpufamily hw.cpusubfamily', function (error, stdout) {
let lines = stdout.toString().split('\n');
const modelline = util.getValue(lines, 'machdep.cpu.brand_string');
const modellineParts = modelline.split('@');
result.brand = modellineParts[0].trim();
const speed = modellineParts[1] ? modellineParts[1].trim() : '0';
result.speed = parseFloat(speed.replace(/GHz+/g, ''));
let tbFrequency = util.getValue(lines, 'hw.tbfrequency') / 1000000000.0;
tbFrequency = tbFrequency < 0.1 ? tbFrequency * 100 : tbFrequency;
result.speed = result.speed === 0 ? tbFrequency : result.speed;
_cpu_speed = result.speed;
result = cpuBrandManufacturer(result);
result.speedMin = util.getValue(lines, 'hw.cpufrequency_min') ? (util.getValue(lines, 'hw.cpufrequency_min') / 1000000000.0) : result.speed;
result.speedMax = util.getValue(lines, 'hw.cpufrequency_max') ? (util.getValue(lines, 'hw.cpufrequency_max') / 1000000000.0) : result.speed;
result.vendor = util.getValue(lines, 'machdep.cpu.vendor') || 'Apple';
result.family = util.getValue(lines, 'machdep.cpu.family') || util.getValue(lines, 'hw.cpufamily');
result.model = util.getValue(lines, 'machdep.cpu.model');
result.stepping = util.getValue(lines, 'machdep.cpu.stepping') || util.getValue(lines, 'hw.cpusubfamily');
result.virtualization = true;
const countProcessors = util.getValue(lines, 'hw.packages');
const countCores = util.getValue(lines, 'hw.physicalcpu_max');
const countThreads = util.getValue(lines, 'hw.ncpu');
if (os.arch() === 'arm64') {
const clusters = execSync('ioreg -c IOPlatformDevice -d 3 -r | grep cluster-type').toString().split('\n');
const efficiencyCores = clusters.filter(line => line.indexOf('"E"') >= 0).length;
const performanceCores = clusters.filter(line => line.indexOf('"P"') >= 0).length;
result.socket = 'SOC';
result.efficiencyCores = efficiencyCores;
result.performanceCores = performanceCores;
}
if (countProcessors) {
result.processors = parseInt(countProcessors) || 1;
}
if (countCores && countThreads) {
result.cores = parseInt(countThreads) || util.cores();
result.physicalCores = parseInt(countCores) || util.cores();
}
cpuCache().then((res) => {
result.cache = res;
resolve(result);
});
});
}
if (_linux) {
let modelline = '';
let lines = [];
if (os.cpus()[0] && os.cpus()[0].model) { modelline = os.cpus()[0].model; }
exec('export LC_ALL=C; lscpu; echo -n "Governor: "; cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 2>/dev/null; echo; unset LC_ALL', function (error, stdout) {
if (!error) {
lines = stdout.toString().split('\n');
}
modelline = util.getValue(lines, 'model name') || modelline;
const modellineParts = modelline.split('@');
result.brand = modellineParts[0].trim();
result.speed = modellineParts[1] ? parseFloat(modellineParts[1].trim()) : 0;
if (result.speed === 0 && (result.brand.indexOf('AMD') > -1 || result.brand.toLowerCase().indexOf('ryzen') > -1)) {
result.speed = getAMDSpeed(result.brand);
}
if (result.speed === 0) {
const current = getCpuCurrentSpeedSync();
if (current.avg !== 0) { result.speed = current.avg; }
}
_cpu_speed = result.speed;
result.speedMin = Math.round(parseFloat(util.getValue(lines, 'cpu min mhz').replace(/,/g, '.')) / 10.0) / 100;
result.speedMax = Math.round(parseFloat(util.getValue(lines, 'cpu max mhz').replace(/,/g, '.')) / 10.0) / 100;
result = cpuBrandManufacturer(result);
result.vendor = cpuManufacturer(util.getValue(lines, 'vendor id'));
result.family = util.getValue(lines, 'cpu family');
result.model = util.getValue(lines, 'model:');
result.stepping = util.getValue(lines, 'stepping');
result.revision = util.getValue(lines, 'cpu revision');
result.cache.l1d = util.getValue(lines, 'l1d cache');
if (result.cache.l1d) { result.cache.l1d = parseInt(result.cache.l1d) * (result.cache.l1d.indexOf('M') !== -1 ? 1024 * 1024 : (result.cache.l1d.indexOf('K') !== -1 ? 1024 : 1)); }
result.cache.l1i = util.getValue(lines, 'l1i cache');
if (result.cache.l1i) { result.cache.l1i = parseInt(result.cache.l1i) * (result.cache.l1i.indexOf('M') !== -1 ? 1024 * 1024 : (result.cache.l1i.indexOf('K') !== -1 ? 1024 : 1)); }
result.cache.l2 = util.getValue(lines, 'l2 cache');
if (result.cache.l2) { result.cache.l2 = parseInt(result.cache.l2) * (result.cache.l2.indexOf('M') !== -1 ? 1024 * 1024 : (result.cache.l2.indexOf('K') !== -1 ? 1024 : 1)); }
result.cache.l3 = util.getValue(lines, 'l3 cache');
if (result.cache.l3) { result.cache.l3 = parseInt(result.cache.l3) * (result.cache.l3.indexOf('M') !== -1 ? 1024 * 1024 : (result.cache.l3.indexOf('K') !== -1 ? 1024 : 1)); }
const threadsPerCore = util.getValue(lines, 'thread(s) per core') || '1';
const processors = util.getValue(lines, 'socket(s)') || '1';
let threadsPerCoreInt = parseInt(threadsPerCore, 10); // threads per code (normally only for performance cores)
let processorsInt = parseInt(processors, 10) || 1; // number of sockets / processor units in machine (normally 1)
const coresPerSocket = parseInt(util.getValue(lines, 'core(s) per socket'), 10); // number of cores (e.g. 16 on i12900)
result.physicalCores = coresPerSocket ? coresPerSocket * processorsInt : result.cores / threadsPerCoreInt;
result.performanceCores = threadsPerCoreInt > 1 ? result.cores - result.physicalCores : result.cores;
result.efficiencyCores = threadsPerCoreInt > 1 ? result.cores - (threadsPerCoreInt * result.performanceCores) : 0;
result.processors = processorsInt;
result.governor = util.getValue(lines, 'governor') || '';
// Test Raspberry
if (result.vendor === 'ARM') {
const linesRpi = fs.readFileSync('/proc/cpuinfo').toString().split('\n');
const rPIRevision = util.decodePiCpuinfo(linesRpi);
if (rPIRevision.model.toLowerCase().indexOf('raspberry') >= 0) {
result.family = result.manufacturer;
result.manufacturer = rPIRevision.manufacturer;
result.brand = rPIRevision.processor;
result.revision = rPIRevision.revisionCode;
result.socket = 'SOC';
}
}
// socket type
let lines2 = [];
exec('export LC_ALL=C; dmidecode –t 4 2>/dev/null | grep "Upgrade: Socket"; unset LC_ALL', function (error2, stdout2) {
lines2 = stdout2.toString().split('\n');
if (lines2 && lines2.length) {
result.socket = util.getValue(lines2, 'Upgrade').replace('Socket', '').trim() || result.socket;
}
resolve(result);
});
});
}
if (_freebsd || _openbsd || _netbsd) {
let modelline = '';
let lines = [];
if (os.cpus()[0] && os.cpus()[0].model) { modelline = os.cpus()[0].model; }
exec('export LC_ALL=C; dmidecode -t 4; dmidecode -t 7 unset LC_ALL', function (error, stdout) {
let cache = [];
if (!error) {
const data = stdout.toString().split('# dmidecode');
const processor = data.length > 1 ? data[1] : '';
cache = data.length > 2 ? data[2].split('Cache Information') : [];
lines = processor.split('\n');
}
result.brand = modelline.split('@')[0].trim();
result.speed = modelline.split('@')[1] ? parseFloat(modelline.split('@')[1].trim()) : 0;
if (result.speed === 0 && (result.brand.indexOf('AMD') > -1 || result.brand.toLowerCase().indexOf('ryzen') > -1)) {
result.speed = getAMDSpeed(result.brand);
}
if (result.speed === 0) {
const current = getCpuCurrentSpeedSync();
if (current.avg !== 0) { result.speed = current.avg; }
}
_cpu_speed = result.speed;
result.speedMin = result.speed;
result.speedMax = Math.round(parseFloat(util.getValue(lines, 'max speed').replace(/Mhz/g, '')) / 10.0) / 100;
result = cpuBrandManufacturer(result);
result.vendor = cpuManufacturer(util.getValue(lines, 'manufacturer'));
let sig = util.getValue(lines, 'signature');
sig = sig.split(',');
for (let i = 0; i < sig.length; i++) {
sig[i] = sig[i].trim();
}
result.family = util.getValue(sig, 'Family', ' ', true);
result.model = util.getValue(sig, 'Model', ' ', true);
result.stepping = util.getValue(sig, 'Stepping', ' ', true);
result.revision = '';
const voltage = parseFloat(util.getValue(lines, 'voltage'));
result.voltage = isNaN(voltage) ? '' : voltage.toFixed(2);
for (let i = 0; i < cache.length; i++) {
lines = cache[i].split('\n');
let cacheType = util.getValue(lines, 'Socket Designation').toLowerCase().replace(' ', '-').split('-');
cacheType = cacheType.length ? cacheType[0] : '';
const sizeParts = util.getValue(lines, 'Installed Size').split(' ');
let size = parseInt(sizeParts[0], 10);
const unit = sizeParts.length > 1 ? sizeParts[1] : 'kb';
size = size * (unit === 'kb' ? 1024 : (unit === 'mb' ? 1024 * 1024 : (unit === 'gb' ? 1024 * 1024 * 1024 : 1)));
if (cacheType) {
if (cacheType === 'l1') {
result.cache[cacheType + 'd'] = size / 2;
result.cache[cacheType + 'i'] = size / 2;
} else {
result.cache[cacheType] = size;
}
}
}
// socket type
result.socket = util.getValue(lines, 'Upgrade').replace('Socket', '').trim();
// # threads / # cores
const threadCount = util.getValue(lines, 'thread count').trim();
const coreCount = util.getValue(lines, 'core count').trim();
if (coreCount && threadCount) {
result.cores = parseInt(threadCount, 10);
result.physicalCores = parseInt(coreCount, 10);
}
resolve(result);
});
}
if (_sunos) {
resolve(result);
}
if (_windows) {
try {
const workload = [];
workload.push(util.powerShell('Get-CimInstance Win32_processor | select Name, Revision, L2CacheSize, L3CacheSize, Manufacturer, MaxClockSpeed, Description, UpgradeMethod, Caption, NumberOfLogicalProcessors, NumberOfCores | fl'));
workload.push(util.powerShell('Get-CimInstance Win32_CacheMemory | select CacheType,InstalledSize,Level | fl'));
workload.push(util.powerShell('(Get-CimInstance Win32_ComputerSystem).HypervisorPresent'));
Promise.all(
workload
).then((data) => {
let lines = data[0].split('\r\n');
let name = util.getValue(lines, 'name', ':') || '';
if (name.indexOf('@') >= 0) {
result.brand = name.split('@')[0].trim();
result.speed = name.split('@')[1] ? parseFloat(name.split('@')[1].trim()) : 0;
_cpu_speed = result.speed;
} else {
result.brand = name.trim();
result.speed = 0;
}
result = cpuBrandManufacturer(result);
result.revision = util.getValue(lines, 'revision', ':');
result.cache.l1d = 0;
result.cache.l1i = 0;
result.cache.l2 = util.getValue(lines, 'l2cachesize', ':');
result.cache.l3 = util.getValue(lines, 'l3cachesize', ':');
if (result.cache.l2) { result.cache.l2 = parseInt(result.cache.l2, 10) * 1024; }
if (result.cache.l3) { result.cache.l3 = parseInt(result.cache.l3, 10) * 1024; }
result.vendor = util.getValue(lines, 'manufacturer', ':');
result.speedMax = Math.round(parseFloat(util.getValue(lines, 'maxclockspeed', ':').replace(/,/g, '.')) / 10.0) / 100;
if (result.speed === 0 && (result.brand.indexOf('AMD') > -1 || result.brand.toLowerCase().indexOf('ryzen') > -1)) {
result.speed = getAMDSpeed(result.brand);
}
if (result.speed === 0) {
result.speed = result.speedMax;
}
result.speedMin = result.speed;
let description = util.getValue(lines, 'description', ':').split(' ');
for (let i = 0; i < description.length; i++) {
if (description[i].toLowerCase().startsWith('family') && (i + 1) < description.length && description[i + 1]) {
result.family = description[i + 1];
}
if (description[i].toLowerCase().startsWith('model') && (i + 1) < description.length && description[i + 1]) {
result.model = description[i + 1];
}
if (description[i].toLowerCase().startsWith('stepping') && (i + 1) < description.length && description[i + 1]) {
result.stepping = description[i + 1];
}
}
// socket type
const socketId = util.getValue(lines, 'UpgradeMethod', ':');
if (socketTypes[socketId]) {
result.socket = socketTypes[socketId];
}
const socketByName = getSocketTypesByName(name);
if (socketByName) {
result.socket = socketByName;
}
// # threads / # cores
const countProcessors = util.countLines(lines, 'Caption');
const countThreads = util.getValue(lines, 'NumberOfLogicalProcessors', ':');
const countCores = util.getValue(lines, 'NumberOfCores', ':');
if (countProcessors) {
result.processors = parseInt(countProcessors) || 1;
}
if (countCores && countThreads) {
result.cores = parseInt(countThreads) || util.cores();
result.physicalCores = parseInt(countCores) || util.cores();
}
if (countProcessors > 1) {
result.cores = result.cores * countProcessors;
result.physicalCores = result.physicalCores * countProcessors;
}
const parts = data[1].split(/\n\s*\n/);
parts.forEach(function (part) {
lines = part.split('\r\n');
const cacheType = util.getValue(lines, 'CacheType');
const level = util.getValue(lines, 'Level');
const installedSize = util.getValue(lines, 'InstalledSize');
// L1 Instructions
if (level === '3' && cacheType === '3') {
result.cache.l1i = parseInt(installedSize, 10);
}
// L1 Data
if (level === '3' && cacheType === '4') {
result.cache.l1d = parseInt(installedSize, 10);
}
// L1 all
if (level === '3' && cacheType === '5' && !result.cache.l1i && !result.cache.l1d) {
result.cache.l1i = parseInt(installedSize, 10) / 2;
result.cache.l1d = parseInt(installedSize, 10) / 2;
}
});
const hyperv = data[2] ? data[2].toString().toLowerCase() : '';
result.virtualization = hyperv.indexOf('true') !== -1;
resolve(result);
});
} catch (e) {
resolve(result);
}
}
});
});
});
}
// --------------------------
// CPU - Processor Data
function cpu(callback) {
return new Promise((resolve) => {
process.nextTick(() => {
getCpu().then(result => {
if (callback) { callback(result); }
resolve(result);
});
});
});
}
exports.cpu = cpu;
// --------------------------
// CPU - current speed - in GHz
function getCpuCurrentSpeedSync() {
let cpus = os.cpus();
let minFreq = 999999999;
let maxFreq = 0;
let avgFreq = 0;
let cores = [];
if (cpus && cpus.length) {
for (let i in cpus) {
if ({}.hasOwnProperty.call(cpus, i)) {
let freq = cpus[i].speed > 100 ? (cpus[i].speed + 1) / 1000 : cpus[i].speed / 10;
avgFreq = avgFreq + freq;
if (freq > maxFreq) { maxFreq = freq; }
if (freq < minFreq) { minFreq = freq; }
cores.push(parseFloat(freq.toFixed(2)));
}
}
avgFreq = avgFreq / cpus.length;
return {
min: parseFloat(minFreq.toFixed(2)),
max: parseFloat(maxFreq.toFixed(2)),
avg: parseFloat((avgFreq).toFixed(2)),
cores: cores
};
} else {
return {
min: 0,
max: 0,
avg: 0,
cores: cores
};
}
}
function cpuCurrentSpeed(callback) {
return new Promise((resolve) => {
process.nextTick(() => {
let result = getCpuCurrentSpeedSync();
if (result.avg === 0 && _cpu_speed !== 0) {
const currCpuSpeed = parseFloat(_cpu_speed);
result = {
min: currCpuSpeed,
max: currCpuSpeed,
avg: currCpuSpeed,
cores: []
};
}
if (callback) { callback(result); }
resolve(result);
});
});
}
exports.cpuCurrentSpeed = cpuCurrentSpeed;
// --------------------------
// CPU - temperature
// if sensors are installed
function cpuTemperature(callback) {