@depup/systeminformation 5.31.4-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cpu.js ADDED
@@ -0,0 +1,2237 @@
1
+ 'use strict';
2
+ // @ts-check
3
+ // ==================================================================================
4
+ // cpu.js
5
+ // ----------------------------------------------------------------------------------
6
+ // Description: System Information - library
7
+ // for Node.js
8
+ // Copyright: (c) 2014 - 2026
9
+ // Author: Sebastian Hildebrandt
10
+ // ----------------------------------------------------------------------------------
11
+ // License: MIT
12
+ // ==================================================================================
13
+ // 4. CPU
14
+ // ----------------------------------------------------------------------------------
15
+
16
+ const os = require('os');
17
+ const exec = require('child_process').exec;
18
+ const execSync = require('child_process').execSync;
19
+ const fs = require('fs');
20
+ const util = require('./util');
21
+
22
+ const _platform = process.platform;
23
+
24
+ const _linux = _platform === 'linux' || _platform === 'android';
25
+ const _darwin = _platform === 'darwin';
26
+ const _windows = _platform === 'win32';
27
+ const _freebsd = _platform === 'freebsd';
28
+ const _openbsd = _platform === 'openbsd';
29
+ const _netbsd = _platform === 'netbsd';
30
+ const _sunos = _platform === 'sunos';
31
+
32
+ let _cpu_speed = 0;
33
+ let _current_cpu = {
34
+ user: 0,
35
+ nice: 0,
36
+ system: 0,
37
+ idle: 0,
38
+ irq: 0,
39
+ steal: 0,
40
+ guest: 0,
41
+ load: 0,
42
+ tick: 0,
43
+ ms: 0,
44
+ currentLoad: 0,
45
+ currentLoadUser: 0,
46
+ currentLoadSystem: 0,
47
+ currentLoadNice: 0,
48
+ currentLoadIdle: 0,
49
+ currentLoadIrq: 0,
50
+ currentLoadSteal: 0,
51
+ currentLoadGuest: 0,
52
+ rawCurrentLoad: 0,
53
+ rawCurrentLoadUser: 0,
54
+ rawCurrentLoadSystem: 0,
55
+ rawCurrentLoadNice: 0,
56
+ rawCurrentLoadIdle: 0,
57
+ rawCurrentLoadIrq: 0,
58
+ rawCurrentLoadSteal: 0,
59
+ rawCurrentLoadGuest: 0
60
+ };
61
+ let _cpus = [];
62
+ let _corecount = 0;
63
+
64
+ const AMDBaseFrequencies = {
65
+ 8346: '1.8',
66
+ 8347: '1.9',
67
+ 8350: '2.0',
68
+ 8354: '2.2',
69
+ '8356|SE': '2.4',
70
+ 8356: '2.3',
71
+ 8360: '2.5',
72
+ 2372: '2.1',
73
+ 2373: '2.1',
74
+ 2374: '2.2',
75
+ 2376: '2.3',
76
+ 2377: '2.3',
77
+ 2378: '2.4',
78
+ 2379: '2.4',
79
+ 2380: '2.5',
80
+ 2381: '2.5',
81
+ 2382: '2.6',
82
+ 2384: '2.7',
83
+ 2386: '2.8',
84
+ 2387: '2.8',
85
+ 2389: '2.9',
86
+ 2393: '3.1',
87
+ 8374: '2.2',
88
+ 8376: '2.3',
89
+ 8378: '2.4',
90
+ 8379: '2.4',
91
+ 8380: '2.5',
92
+ 8381: '2.5',
93
+ 8382: '2.6',
94
+ 8384: '2.7',
95
+ 8386: '2.8',
96
+ 8387: '2.8',
97
+ 8389: '2.9',
98
+ 8393: '3.1',
99
+ '2419EE': '1.8',
100
+ '2423HE': '2.0',
101
+ '2425HE': '2.1',
102
+ 2427: '2.2',
103
+ 2431: '2.4',
104
+ 2435: '2.6',
105
+ '2439SE': '2.8',
106
+ '8425HE': '2.1',
107
+ 8431: '2.4',
108
+ 8435: '2.6',
109
+ '8439SE': '2.8',
110
+ 4122: '2.2',
111
+ 4130: '2.6',
112
+ '4162EE': '1.7',
113
+ '4164EE': '1.8',
114
+ '4170HE': '2.1',
115
+ '4174HE': '2.3',
116
+ '4176HE': '2.4',
117
+ 4180: '2.6',
118
+ 4184: '2.8',
119
+ '6124HE': '1.8',
120
+ '6128HE': '2.0',
121
+ '6132HE': '2.2',
122
+ 6128: '2.0',
123
+ 6134: '2.3',
124
+ 6136: '2.4',
125
+ 6140: '2.6',
126
+ '6164HE': '1.7',
127
+ '6166HE': '1.8',
128
+ 6168: '1.9',
129
+ 6172: '2.1',
130
+ 6174: '2.2',
131
+ 6176: '2.3',
132
+ '6176SE': '2.3',
133
+ '6180SE': '2.5',
134
+ 3250: '2.5',
135
+ 3260: '2.7',
136
+ 3280: '2.4',
137
+ 4226: '2.7',
138
+ 4228: '2.8',
139
+ 4230: '2.9',
140
+ 4234: '3.1',
141
+ 4238: '3.3',
142
+ 4240: '3.4',
143
+ 4256: '1.6',
144
+ 4274: '2.5',
145
+ 4276: '2.6',
146
+ 4280: '2.8',
147
+ 4284: '3.0',
148
+ 6204: '3.3',
149
+ 6212: '2.6',
150
+ 6220: '3.0',
151
+ 6234: '2.4',
152
+ 6238: '2.6',
153
+ '6262HE': '1.6',
154
+ 6272: '2.1',
155
+ 6274: '2.2',
156
+ 6276: '2.3',
157
+ 6278: '2.4',
158
+ '6282SE': '2.6',
159
+ '6284SE': '2.7',
160
+ 6308: '3.5',
161
+ 6320: '2.8',
162
+ 6328: '3.2',
163
+ '6338P': '2.3',
164
+ 6344: '2.6',
165
+ 6348: '2.8',
166
+ 6366: '1.8',
167
+ '6370P': '2.0',
168
+ 6376: '2.3',
169
+ 6378: '2.4',
170
+ 6380: '2.5',
171
+ 6386: '2.8',
172
+ 'FX|4100': '3.6',
173
+ 'FX|4120': '3.9',
174
+ 'FX|4130': '3.8',
175
+ 'FX|4150': '3.8',
176
+ 'FX|4170': '4.2',
177
+ 'FX|6100': '3.3',
178
+ 'FX|6120': '3.6',
179
+ 'FX|6130': '3.6',
180
+ 'FX|6200': '3.8',
181
+ 'FX|8100': '2.8',
182
+ 'FX|8120': '3.1',
183
+ 'FX|8140': '3.2',
184
+ 'FX|8150': '3.6',
185
+ 'FX|8170': '3.9',
186
+ 'FX|4300': '3.8',
187
+ 'FX|4320': '4.0',
188
+ 'FX|4350': '4.2',
189
+ 'FX|6300': '3.5',
190
+ 'FX|6350': '3.9',
191
+ 'FX|8300': '3.3',
192
+ 'FX|8310': '3.4',
193
+ 'FX|8320': '3.5',
194
+ 'FX|8350': '4.0',
195
+ 'FX|8370': '4.0',
196
+ 'FX|9370': '4.4',
197
+ 'FX|9590': '4.7',
198
+ 'FX|8320E': '3.2',
199
+ 'FX|8370E': '3.3',
200
+
201
+ // ZEN Desktop CPUs
202
+ 1200: '3.1',
203
+ 'Pro 1200': '3.1',
204
+ '1300X': '3.5',
205
+ 'Pro 1300': '3.5',
206
+ 1400: '3.2',
207
+ '1500X': '3.5',
208
+ 'Pro 1500': '3.5',
209
+ 1600: '3.2',
210
+ '1600X': '3.6',
211
+ 'Pro 1600': '3.2',
212
+ 1700: '3.0',
213
+ 'Pro 1700': '3.0',
214
+ '1700X': '3.4',
215
+ 'Pro 1700X': '3.4',
216
+ '1800X': '3.6',
217
+ '1900X': '3.8',
218
+ 1920: '3.2',
219
+ '1920X': '3.5',
220
+ '1950X': '3.4',
221
+
222
+ // ZEN Desktop APUs
223
+ '200GE': '3.2',
224
+ 'Pro 200GE': '3.2',
225
+ '220GE': '3.4',
226
+ '240GE': '3.5',
227
+ '3000G': '3.5',
228
+ '300GE': '3.4',
229
+ '3050GE': '3.4',
230
+ '2200G': '3.5',
231
+ 'Pro 2200G': '3.5',
232
+ '2200GE': '3.2',
233
+ 'Pro 2200GE': '3.2',
234
+ '2400G': '3.6',
235
+ 'Pro 2400G': '3.6',
236
+ '2400GE': '3.2',
237
+ 'Pro 2400GE': '3.2',
238
+
239
+ // ZEN Mobile APUs
240
+ 'Pro 200U': '2.3',
241
+ '300U': '2.4',
242
+ '2200U': '2.5',
243
+ '3200U': '2.6',
244
+ '2300U': '2.0',
245
+ 'Pro 2300U': '2.0',
246
+ '2500U': '2.0',
247
+ 'Pro 2500U': '2.2',
248
+ '2600H': '3.2',
249
+ '2700U': '2.0',
250
+ 'Pro 2700U': '2.2',
251
+ '2800H': '3.3',
252
+
253
+ // ZEN Server Processors
254
+ 7351: '2.4',
255
+ '7351P': '2.4',
256
+ 7401: '2.0',
257
+ '7401P': '2.0',
258
+ '7551P': '2.0',
259
+ 7551: '2.0',
260
+ 7251: '2.1',
261
+ 7261: '2.5',
262
+ 7281: '2.1',
263
+ 7301: '2.2',
264
+ 7371: '3.1',
265
+ 7451: '2.3',
266
+ 7501: '2.0',
267
+ 7571: '2.2',
268
+ 7601: '2.2',
269
+
270
+ // ZEN Embedded Processors
271
+ V1500B: '2.2',
272
+ V1780B: '3.35',
273
+ V1202B: '2.3',
274
+ V1404I: '2.0',
275
+ V1605B: '2.0',
276
+ V1756B: '3.25',
277
+ V1807B: '3.35',
278
+
279
+ 3101: '2.1',
280
+ 3151: '2.7',
281
+ 3201: '1.5',
282
+ 3251: '2.5',
283
+ 3255: '2.5',
284
+ 3301: '2.0',
285
+ 3351: '1.9',
286
+ 3401: '1.85',
287
+ 3451: '2.15',
288
+
289
+ // ZEN+ Desktop
290
+ '1200|AF': '3.1',
291
+ '2300X': '3.5',
292
+ '2500X': '3.6',
293
+ 2600: '3.4',
294
+ '2600E': '3.1',
295
+ '1600|AF': '3.2',
296
+ '2600X': '3.6',
297
+ 2700: '3.2',
298
+ '2700E': '2.8',
299
+ 'Pro 2700': '3.2',
300
+ '2700X': '3.7',
301
+ 'Pro 2700X': '3.6',
302
+ '2920X': '3.5',
303
+ '2950X': '3.5',
304
+ '2970WX': '3.0',
305
+ '2990WX': '3.0',
306
+
307
+ // ZEN+ Desktop APU
308
+ 'Pro 300GE': '3.4',
309
+ 'Pro 3125GE': '3.4',
310
+ '3150G': '3.5',
311
+ 'Pro 3150G': '3.5',
312
+ '3150GE': '3.3',
313
+ 'Pro 3150GE': '3.3',
314
+ '3200G': '3.6',
315
+ 'Pro 3200G': '3.6',
316
+ '3200GE': '3.3',
317
+ 'Pro 3200GE': '3.3',
318
+ '3350G': '3.6',
319
+ 'Pro 3350G': '3.6',
320
+ '3350GE': '3.3',
321
+ 'Pro 3350GE': '3.3',
322
+ '3400G': '3.7',
323
+ 'Pro 3400G': '3.7',
324
+ '3400GE': '3.3',
325
+ 'Pro 3400GE': '3.3',
326
+
327
+ // ZEN+ Mobile
328
+ '3300U': '2.1',
329
+ 'PRO 3300U': '2.1',
330
+ '3450U': '2.1',
331
+ '3500U': '2.1',
332
+ 'PRO 3500U': '2.1',
333
+ '3500C': '2.1',
334
+ '3550H': '2.1',
335
+ '3580U': '2.1',
336
+ '3700U': '2.3',
337
+ 'PRO 3700U': '2.3',
338
+ '3700C': '2.3',
339
+ '3750H': '2.3',
340
+ '3780U': '2.3',
341
+
342
+ // ZEN2 Desktop CPUS
343
+ 3100: '3.6',
344
+ '3300X': '3.8',
345
+ 3500: '3.6',
346
+ '3500X': '3.6',
347
+ 3600: '3.6',
348
+ 'Pro 3600': '3.6',
349
+ '3600X': '3.8',
350
+ '3600XT': '3.8',
351
+ 'Pro 3700': '3.6',
352
+ '3700X': '3.6',
353
+ '3800X': '3.9',
354
+ '3800XT': '3.9',
355
+ 3900: '3.1',
356
+ 'Pro 3900': '3.1',
357
+ '3900X': '3.8',
358
+ '3900XT': '3.8',
359
+ '3950X': '3.5',
360
+ '3960X': '3.8',
361
+ '3970X': '3.7',
362
+ '3990X': '2.9',
363
+ '3945WX': '4.0',
364
+ '3955WX': '3.9',
365
+ '3975WX': '3.5',
366
+ '3995WX': '2.7',
367
+
368
+ // ZEN2 Desktop APUs
369
+ '4300GE': '3.5',
370
+ 'Pro 4300GE': '3.5',
371
+ '4300G': '3.8',
372
+ 'Pro 4300G': '3.8',
373
+ '4600GE': '3.3',
374
+ 'Pro 4650GE': '3.3',
375
+ '4600G': '3.7',
376
+ 'Pro 4650G': '3.7',
377
+ '4700GE': '3.1',
378
+ 'Pro 4750GE': '3.1',
379
+ '4700G': '3.6',
380
+ 'Pro 4750G': '3.6',
381
+ '4300U': '2.7',
382
+ '4450U': '2.5',
383
+ 'Pro 4450U': '2.5',
384
+ '4500U': '2.3',
385
+ '4600U': '2.1',
386
+ 'PRO 4650U': '2.1',
387
+ '4680U': '2.1',
388
+ '4600HS': '3.0',
389
+ '4600H': '3.0',
390
+ '4700U': '2.0',
391
+ 'PRO 4750U': '1.7',
392
+ '4800U': '1.8',
393
+ '4800HS': '2.9',
394
+ '4800H': '2.9',
395
+ '4900HS': '3.0',
396
+ '4900H': '3.3',
397
+ '5300U': '2.6',
398
+ '5500U': '2.1',
399
+ '5700U': '1.8',
400
+
401
+ // ZEN2 - EPYC
402
+ '7232P': '3.1',
403
+ '7302P': '3.0',
404
+ '7402P': '2.8',
405
+ '7502P': '2.5',
406
+ '7702P': '2.0',
407
+ 7252: '3.1',
408
+ 7262: '3.2',
409
+ 7272: '2.9',
410
+ 7282: '2.8',
411
+ 7302: '3.0',
412
+ 7352: '2.3',
413
+ 7402: '2.8',
414
+ 7452: '2.35',
415
+ 7502: '2.5',
416
+ 7532: '2.4',
417
+ 7542: '2.9',
418
+ 7552: '2.2',
419
+ 7642: '2.3',
420
+ 7662: '2.0',
421
+ 7702: '2.0',
422
+ 7742: '2.25',
423
+ '7H12': '2.6',
424
+ '7F32': '3.7',
425
+ '7F52': '3.5',
426
+ '7F72': '3.2',
427
+
428
+ // Epyc (Milan)
429
+
430
+ '7773X': '2.2',
431
+ 7763: '2.45',
432
+ 7713: '2.0',
433
+ '7713P': '2.0',
434
+ 7663: '2.0',
435
+ 7643: '2.3',
436
+ '7573X': '2.8',
437
+ '75F3': '2.95',
438
+ 7543: '2.8',
439
+ '7543P': '2.8',
440
+ 7513: '2.6',
441
+ '7473X': '2.8',
442
+ 7453: '2.75',
443
+ '74F3': '3.2',
444
+ 7443: '2.85',
445
+ '7443P': '2.85',
446
+ 7413: '2.65',
447
+ '7373X': '3.05',
448
+ '73F3': '3.5',
449
+ 7343: '3.2',
450
+ 7313: '3.0',
451
+ '7313P': '3.0',
452
+ '72F3': '3.7',
453
+
454
+ // ZEN3
455
+ '5600X': '3.7',
456
+ '5800X': '3.8',
457
+ '5900X': '3.7',
458
+ '5950X': '3.4',
459
+ '5945WX': '4.1',
460
+ '5955WX': '4.0',
461
+ '5965WX': '3.8',
462
+ '5975WX': '3.6',
463
+ '5995WX': '2.7',
464
+
465
+ '7960X': '4.2',
466
+ '7970X': '4.0',
467
+ '7980X': '3.2',
468
+
469
+ '7965WX': '4.2',
470
+ '7975WX': '4.0',
471
+ '7985WX': '3.2',
472
+ '7995WX': '2.5',
473
+
474
+ // ZEN4
475
+ 9754: '2.25',
476
+ '9754S': '2.25',
477
+ 9734: '2.2',
478
+ '9684X': '2.55',
479
+ '9384X': '3.1',
480
+ '9184X': '3.55',
481
+ '9654P': '2.4',
482
+ 9654: '2.4',
483
+ 9634: '2.25',
484
+ '9554P': '3.1',
485
+ 9554: '3.1',
486
+ 9534: '2.45',
487
+ '9474F': '3.6',
488
+ '9454P': '2.75',
489
+ 9454: '2.75',
490
+ '9374F': '3.85',
491
+ '9354P': '3.25',
492
+ 9354: '3.25',
493
+ 9334: '2.7',
494
+ '9274F': '4.05',
495
+ 9254: '2.9',
496
+ 9224: '2.5',
497
+ '9174F': '4.1',
498
+ 9124: '3.0',
499
+
500
+ // Epyc 4th gen
501
+ '4124P': '3.8',
502
+ '4244P': '3.8',
503
+ '4344P': '3.8',
504
+ '4364P': '4.5',
505
+ '4464P': '3.7',
506
+ '4484PX': '4.4',
507
+ '4564P': '4.5',
508
+ '4584PX': '4.2',
509
+ '8024P': '2.4',
510
+ '8024PN': '2.05',
511
+ '8124P': '2.45',
512
+ '8124PN': '2.0',
513
+ '8224P': '2.55',
514
+ '8224PN': '2.0',
515
+ '8324P': '2.65',
516
+ '8324PN': '2.05',
517
+ '8434P': '2.5',
518
+ '8434PN': '2.0',
519
+ '8534P': '2.3',
520
+ '8534PN': '2.0',
521
+
522
+ // Epyc 5th gen
523
+ 9115: '2.6',
524
+ 9135: '3.65',
525
+ '9175F': '4.2',
526
+ 9255: '3.25',
527
+ '9275F': '4.1',
528
+ 9335: '3.0',
529
+ '9355P': '3.55',
530
+ 9355: '3.55',
531
+ '9375F': '3.8',
532
+ 9365: '3.4',
533
+ '9455P': '3.15',
534
+ 9455: '3.15',
535
+ '9475F': '3.65',
536
+ 9535: '2.4',
537
+ '9555P': '3.2',
538
+ 9555: '3.2',
539
+ '9575F': '3.3',
540
+ 9565: '3.15',
541
+ '9655P': '2.5',
542
+ 9655: '2.5',
543
+ 9755: '2.7',
544
+ '4245P': '3.9',
545
+ '4345P': '3.8',
546
+ '4465P': '3.4',
547
+ '4545P': '3.0',
548
+ '4565P': '4.3',
549
+ '4585PX': '4.3',
550
+ '5900XT': '3.3',
551
+ 5900: '3.0',
552
+ 5945: '3.0',
553
+ '5800X3D': '3.4',
554
+ '5800XT': '3.8',
555
+ 5800: '3.4',
556
+ '5700X3D': '3.0',
557
+ '5700X': '3.4',
558
+ 5845: '3.4',
559
+ '5600X3D': '3.3',
560
+ '5600XT': '3.7',
561
+ '5600T': '3.5',
562
+ 5600: '3.5',
563
+ '5600F': '3.0',
564
+ 5645: '3.7',
565
+ '5500X3D': '3.0',
566
+ '5980HX': '3.3',
567
+ '5980HS': '3.0',
568
+ '5900HX': '3.3',
569
+ '5900HS': '3.0',
570
+ '5800H': '3.2',
571
+ '5800HS': '2.8',
572
+ '5800U': '1.9',
573
+ '5600H': '3.3',
574
+ '5600HS': '3.0',
575
+ '5600U': '2.3',
576
+ '5560U': '2.3',
577
+ '5400U': '2.7',
578
+ '5825U': '2.0',
579
+ '5625U': '2.3',
580
+ '5425U': '2.7',
581
+ '5125C': '3.0',
582
+ '7730U': '2.0',
583
+ '7530U': '2.0',
584
+ '7430U': '2.3',
585
+ '7330U': '2.3',
586
+ 7203: '2.8',
587
+ 7303: '2.4',
588
+ '7663P': '2.0',
589
+ '6980HX': '3.3',
590
+ '6980HS': '3.3',
591
+ '6900HX': '3.3',
592
+ '6900HS': '3.3',
593
+ '6800H': '3.2',
594
+ '6800HS': '3.2',
595
+ '6800U': '2.7',
596
+ '6600H': '3.3',
597
+ '6600HS': '3.3',
598
+ '6600U': '2.9',
599
+ '7735HS': '3.2',
600
+ '7735H': '3.2',
601
+ '7736U': '2.7',
602
+ '7735U': '2.7',
603
+ '7435HS': '3.1',
604
+ '7435H': '3.1',
605
+ '7535HS': '3.3',
606
+ '7535H': '3.3',
607
+ '7535U': '2.9',
608
+ '7235HS': '3.2',
609
+ '7235H': '3.2',
610
+ '7335U': '3.0',
611
+ 270: '4.0',
612
+ 260: '3.8',
613
+ 250: '3.3',
614
+ 240: '4.3',
615
+ 230: '3.5',
616
+ 220: '3.0',
617
+ 210: '2.8',
618
+ '8945HS': '4.0',
619
+ '8845HS': '3.8',
620
+ '8840HS': '3.3',
621
+ '8840U': '3.3',
622
+ '8645HS': '4.3',
623
+ '8640HS': '3.5',
624
+ '8640U': '3.5',
625
+ '8540U': '3.0',
626
+ '8440U': '2.8',
627
+ '9950X3D': '4.3',
628
+ '9950X': '4.3',
629
+ '9900X3D': '4.4',
630
+ '9900X': '4.4',
631
+ '9800X3D': '4.7',
632
+ '9700X': '3.8',
633
+ '9700F': '3.8',
634
+ '9600X': '3.9',
635
+ 9600: '3.8',
636
+ '9500F': '3.8',
637
+ '9995WX': '2.5',
638
+ '9985WX': '3.2',
639
+ '9975WX': '4.0',
640
+ '9965WX': '4.2',
641
+ '9955WX': '4.5',
642
+ '9945WX': '4.7',
643
+ '9980X': '3.2',
644
+ '9970X': '4.0',
645
+ '9960X': '4.2',
646
+ 'PRO HX375': '2.0',
647
+ HX375: '2.0',
648
+ 'PRO HX370': '2.0',
649
+ HX370: '2.0',
650
+ 365: '2.0',
651
+ 'PRO 360': '2.0',
652
+ 350: '2.0',
653
+ 'PRO 350': '2.0',
654
+ 340: '2.0',
655
+ 'PRO 340': '2.0',
656
+ 330: '2.0',
657
+ 395: '3.0',
658
+ 'PRO 395': '3.0',
659
+ 390: '3.2',
660
+ 'PRO 390': '3.2',
661
+ 385: '3.6',
662
+ 'PRO 385': '3.6',
663
+ 'PRO 380': '3.6',
664
+ '9955HX3D': '2.3',
665
+ '9955HX': '2.5',
666
+ '9850HX': '3.0',
667
+ 9015: '3.6',
668
+ 9965: '2.25',
669
+ 9845: '2.1',
670
+ 9825: '2.2',
671
+ 9745: '2.4',
672
+ 9645: '2.3'
673
+ };
674
+
675
+ const socketTypes = {
676
+ 1: 'Other',
677
+ 2: 'Unknown',
678
+ 3: 'Daughter Board',
679
+ 4: 'ZIF Socket',
680
+ 5: 'Replacement/Piggy Back',
681
+ 6: 'None',
682
+ 7: 'LIF Socket',
683
+ 8: 'Slot 1',
684
+ 9: 'Slot 2',
685
+ 10: '370 Pin Socket',
686
+ 11: 'Slot A',
687
+ 12: 'Slot M',
688
+ 13: '423',
689
+ 14: 'A (Socket 462)',
690
+ 15: '478',
691
+ 16: '754',
692
+ 17: '940',
693
+ 18: '939',
694
+ 19: 'mPGA604',
695
+ 20: 'LGA771',
696
+ 21: 'LGA775',
697
+ 22: 'S1',
698
+ 23: 'AM2',
699
+ 24: 'F (1207)',
700
+ 25: 'LGA1366',
701
+ 26: 'G34',
702
+ 27: 'AM3',
703
+ 28: 'C32',
704
+ 29: 'LGA1156',
705
+ 30: 'LGA1567',
706
+ 31: 'PGA988A',
707
+ 32: 'BGA1288',
708
+ 33: 'rPGA988B',
709
+ 34: 'BGA1023',
710
+ 35: 'BGA1224',
711
+ 36: 'LGA1155',
712
+ 37: 'LGA1356',
713
+ 38: 'LGA2011',
714
+ 39: 'FS1',
715
+ 40: 'FS2',
716
+ 41: 'FM1',
717
+ 42: 'FM2',
718
+ 43: 'LGA2011-3',
719
+ 44: 'LGA1356-3',
720
+ 45: 'LGA1150',
721
+ 46: 'BGA1168',
722
+ 47: 'BGA1234',
723
+ 48: 'BGA1364',
724
+ 49: 'AM4',
725
+ 50: 'LGA1151',
726
+ 51: 'BGA1356',
727
+ 52: 'BGA1440',
728
+ 53: 'BGA1515',
729
+ 54: 'LGA3647-1',
730
+ 55: 'SP3',
731
+ 56: 'SP3r2',
732
+ 57: 'LGA2066',
733
+ 58: 'BGA1392',
734
+ 59: 'BGA1510',
735
+ 60: 'BGA1528',
736
+ 61: 'LGA4189',
737
+ 62: 'LGA1200',
738
+ 63: 'LGA4677',
739
+ 64: 'LGA1700',
740
+ 65: 'BGA1744',
741
+ 66: 'BGA1781',
742
+ 67: 'BGA1211',
743
+ 68: 'BGA2422',
744
+ 69: 'LGA1211',
745
+ 70: 'LGA2422',
746
+ 71: 'LGA5773',
747
+ 72: 'BGA5773',
748
+ 73: 'AM5',
749
+ 74: 'SP5',
750
+ 75: 'SP6',
751
+ 76: 'BGA883',
752
+ 77: 'BGA1190',
753
+ 78: 'BGA4129',
754
+ 79: 'LGA4710',
755
+ 80: 'LGA7529',
756
+ 81: 'BGA1964',
757
+ 82: 'BGA1792',
758
+ 83: 'BGA2049',
759
+ 84: 'BGA2551',
760
+ 85: 'LGA1851',
761
+ 86: 'BGA2114',
762
+ 87: 'BGA2833'
763
+ };
764
+
765
+ const socketTypesByName = {
766
+ LGA1150:
767
+ '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',
768
+ LGA1151:
769
+ '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',
770
+ 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'
771
+ };
772
+
773
+ function getSocketTypesByName(str) {
774
+ let result = '';
775
+ for (const key in socketTypesByName) {
776
+ const names = socketTypesByName[key].split(' ');
777
+ names.forEach((element) => {
778
+ if (str.indexOf(element) >= 0) {
779
+ result = key;
780
+ }
781
+ });
782
+ }
783
+ return result;
784
+ }
785
+
786
+ function cpuManufacturer(str) {
787
+ let result = str;
788
+ str = str.toLowerCase();
789
+
790
+ if (str.indexOf('intel') >= 0) {
791
+ result = 'Intel';
792
+ }
793
+ if (str.indexOf('amd') >= 0) {
794
+ result = 'AMD';
795
+ }
796
+ if (str.indexOf('qemu') >= 0) {
797
+ result = 'QEMU';
798
+ }
799
+ if (str.indexOf('hygon') >= 0) {
800
+ result = 'Hygon';
801
+ }
802
+ if (str.indexOf('centaur') >= 0) {
803
+ result = 'WinChip/Via';
804
+ }
805
+ if (str.indexOf('vmware') >= 0) {
806
+ result = 'VMware';
807
+ }
808
+ if (str.indexOf('Xen') >= 0) {
809
+ result = 'Xen Hypervisor';
810
+ }
811
+ if (str.indexOf('tcg') >= 0) {
812
+ result = 'QEMU';
813
+ }
814
+ if (str.indexOf('apple') >= 0) {
815
+ result = 'Apple';
816
+ }
817
+ if (str.indexOf('sifive') >= 0) {
818
+ result = 'SiFive';
819
+ }
820
+ if (str.indexOf('thead') >= 0) {
821
+ result = 'T-Head';
822
+ }
823
+ if (str.indexOf('andestech') >= 0) {
824
+ result = 'Andes Technology';
825
+ }
826
+
827
+ return result;
828
+ }
829
+
830
+ function cpuBrandManufacturer(res) {
831
+ res.brand = res.brand
832
+ .replace(/\(R\)+/g, '®')
833
+ .replace(/\s+/g, ' ')
834
+ .trim();
835
+ res.brand = res.brand
836
+ .replace(/\(TM\)+/g, '™')
837
+ .replace(/\s+/g, ' ')
838
+ .trim();
839
+ res.brand = res.brand
840
+ .replace(/\(C\)+/g, '©')
841
+ .replace(/\s+/g, ' ')
842
+ .trim();
843
+ res.brand = res.brand.replace(/CPU+/g, '').replace(/\s+/g, ' ').trim();
844
+ res.manufacturer = cpuManufacturer(res.brand);
845
+
846
+ let parts = res.brand.split(' ');
847
+ parts.shift();
848
+ res.brand = parts.join(' ');
849
+ return res;
850
+ }
851
+
852
+ function getAMDSpeed(brand) {
853
+ let result = '0';
854
+ for (let key in AMDBaseFrequencies) {
855
+ if ({}.hasOwnProperty.call(AMDBaseFrequencies, key)) {
856
+ let parts = key.split('|');
857
+ let found = 0;
858
+ parts.forEach((item) => {
859
+ if (brand.indexOf(item) > -1) {
860
+ found++;
861
+ }
862
+ });
863
+ if (found === parts.length) {
864
+ result = AMDBaseFrequencies[key];
865
+ }
866
+ }
867
+ }
868
+ return parseFloat(result);
869
+ }
870
+
871
+ // --------------------------
872
+ // CPU - brand, speed
873
+
874
+ function getCpu() {
875
+ return new Promise((resolve) => {
876
+ process.nextTick(() => {
877
+ const UNKNOWN = 'unknown';
878
+ let result = {
879
+ manufacturer: UNKNOWN,
880
+ brand: UNKNOWN,
881
+ vendor: '',
882
+ family: '',
883
+ model: '',
884
+ stepping: '',
885
+ revision: '',
886
+ voltage: '',
887
+ speed: 0,
888
+ speedMin: 0,
889
+ speedMax: 0,
890
+ governor: '',
891
+ cores: util.cores(),
892
+ physicalCores: util.cores(),
893
+ performanceCores: util.cores(),
894
+ efficiencyCores: 0,
895
+ processors: 1,
896
+ socket: '',
897
+ flags: '',
898
+ virtualization: false,
899
+ cache: {}
900
+ };
901
+ cpuFlags().then((flags) => {
902
+ result.flags = flags;
903
+ result.virtualization = flags.indexOf('vmx') > -1 || flags.indexOf('svm') > -1;
904
+ if (_darwin) {
905
+ exec('sysctl machdep.cpu hw.cpufrequency_max hw.cpufrequency_min hw.packages hw.physicalcpu_max hw.ncpu hw.tbfrequency hw.cpufamily hw.cpusubfamily', (error, stdout) => {
906
+ const lines = stdout.toString().split('\n');
907
+ const modelline = util.getValue(lines, 'machdep.cpu.brand_string');
908
+ const modellineParts = modelline.split('@');
909
+ result.brand = modellineParts[0].trim();
910
+ const speed = modellineParts[1] ? modellineParts[1].trim() : '0';
911
+ result.speed = parseFloat(speed.replace(/GHz+/g, ''));
912
+ let tbFrequency = util.getValue(lines, 'hw.tbfrequency') / 1000000000.0;
913
+ tbFrequency = tbFrequency < 0.1 ? tbFrequency * 100 : tbFrequency;
914
+ result.speed = result.speed === 0 ? tbFrequency : result.speed;
915
+
916
+ _cpu_speed = result.speed;
917
+ result = cpuBrandManufacturer(result);
918
+ result.speedMin = util.getValue(lines, 'hw.cpufrequency_min') ? util.getValue(lines, 'hw.cpufrequency_min') / 1000000000.0 : result.speed;
919
+ result.speedMax = util.getValue(lines, 'hw.cpufrequency_max') ? util.getValue(lines, 'hw.cpufrequency_max') / 1000000000.0 : result.speed;
920
+ result.vendor = util.getValue(lines, 'machdep.cpu.vendor') || 'Apple';
921
+ result.family = util.getValue(lines, 'machdep.cpu.family') || util.getValue(lines, 'hw.cpufamily');
922
+ result.model = util.getValue(lines, 'machdep.cpu.model');
923
+ result.stepping = util.getValue(lines, 'machdep.cpu.stepping') || util.getValue(lines, 'hw.cpusubfamily');
924
+ result.virtualization = true;
925
+ const countProcessors = util.getValue(lines, 'hw.packages');
926
+ const countCores = util.getValue(lines, 'hw.physicalcpu_max');
927
+ const countThreads = util.getValue(lines, 'hw.ncpu');
928
+ if (os.arch() === 'arm64') {
929
+ result.socket = 'SOC';
930
+ try {
931
+ const clusters = execSync('ioreg -c IOPlatformDevice -d 3 -r | grep cluster-type').toString().split('\n');
932
+ const efficiencyCores = clusters.filter((line) => line.indexOf('"E"') >= 0).length;
933
+ const performanceCores = clusters.filter((line) => line.indexOf('"P"') >= 0).length;
934
+ result.efficiencyCores = efficiencyCores;
935
+ result.performanceCores = performanceCores;
936
+ } catch {
937
+ util.noop();
938
+ }
939
+ }
940
+ if (countProcessors) {
941
+ result.processors = parseInt(countProcessors, 10) || 1;
942
+ }
943
+ if (countCores && countThreads) {
944
+ result.cores = parseInt(countThreads) || util.cores();
945
+ result.physicalCores = parseInt(countCores) || util.cores();
946
+ }
947
+ cpuCache().then((res) => {
948
+ result.cache = res;
949
+ resolve(result);
950
+ });
951
+ });
952
+ }
953
+ if (_linux) {
954
+ let modelline = '';
955
+ let lines = [];
956
+ if (os.cpus()[0] && os.cpus()[0].model) {
957
+ modelline = os.cpus()[0].model;
958
+ }
959
+ 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', (error, stdout) => {
960
+ if (!error) {
961
+ lines = stdout.toString().split('\n');
962
+ }
963
+ modelline = util.getValue(lines, 'model name') || modelline;
964
+ modelline = util.getValue(lines, 'bios model name') || modelline;
965
+ modelline = util.cleanString(modelline);
966
+ const modellineParts = modelline.split('@');
967
+ result.brand = modellineParts[0].trim();
968
+ if (result.brand.indexOf('Unknown') >= 0) {
969
+ result.brand = result.brand.split('Unknown')[0].trim();
970
+ }
971
+ result.speed = modellineParts[1] ? parseFloat(modellineParts[1].trim()) : 0;
972
+ if (result.speed === 0 && (result.brand.indexOf('AMD') > -1 || result.brand.toLowerCase().indexOf('ryzen') > -1)) {
973
+ result.speed = getAMDSpeed(result.brand);
974
+ }
975
+ if (result.speed === 0) {
976
+ const current = getCpuCurrentSpeedSync();
977
+ if (current.avg !== 0) {
978
+ result.speed = current.avg;
979
+ }
980
+ }
981
+ _cpu_speed = result.speed;
982
+ result.speedMin = Math.round(parseFloat(util.getValue(lines, 'cpu min mhz').replace(/,/g, '.')) / 10.0) / 100;
983
+ result.speedMax = Math.round(parseFloat(util.getValue(lines, 'cpu max mhz').replace(/,/g, '.')) / 10.0) / 100;
984
+
985
+ result = cpuBrandManufacturer(result);
986
+ result.vendor = cpuManufacturer(util.getValue(lines, 'vendor id'));
987
+
988
+ result.family = util.getValue(lines, 'cpu family');
989
+ result.model = util.getValue(lines, 'model:');
990
+ result.stepping = util.getValue(lines, 'stepping');
991
+ result.revision = util.getValue(lines, 'cpu revision');
992
+ result.cache.l1d = util.getValue(lines, 'l1d cache');
993
+ if (result.cache.l1d) {
994
+ result.cache.l1d = parseInt(result.cache.l1d) * (result.cache.l1d.indexOf('M') !== -1 ? 1024 * 1024 : result.cache.l1d.indexOf('K') !== -1 ? 1024 : 1);
995
+ }
996
+ result.cache.l1i = util.getValue(lines, 'l1i cache');
997
+ if (result.cache.l1i) {
998
+ result.cache.l1i = parseInt(result.cache.l1i) * (result.cache.l1i.indexOf('M') !== -1 ? 1024 * 1024 : result.cache.l1i.indexOf('K') !== -1 ? 1024 : 1);
999
+ }
1000
+ result.cache.l2 = util.getValue(lines, 'l2 cache');
1001
+ if (result.cache.l2) {
1002
+ result.cache.l2 = parseInt(result.cache.l2) * (result.cache.l2.indexOf('M') !== -1 ? 1024 * 1024 : result.cache.l2.indexOf('K') !== -1 ? 1024 : 1);
1003
+ }
1004
+ result.cache.l3 = util.getValue(lines, 'l3 cache');
1005
+ if (result.cache.l3) {
1006
+ result.cache.l3 = parseInt(result.cache.l3) * (result.cache.l3.indexOf('M') !== -1 ? 1024 * 1024 : result.cache.l3.indexOf('K') !== -1 ? 1024 : 1);
1007
+ }
1008
+
1009
+ const threadsPerCore = util.getValue(lines, 'thread(s) per core') || '1';
1010
+ const processors = util.getValue(lines, 'socket(s)') || '1';
1011
+ const threadsPerCoreInt = parseInt(threadsPerCore, 10); // threads per code (normally only for performance cores)
1012
+ const processorsInt = parseInt(processors, 10) || 1; // number of sockets / processor units in machine (normally 1)
1013
+ const coresPerSocket = parseInt(util.getValue(lines, 'core(s) per socket'), 10); // number of cores (e.g. 16 on i12900)
1014
+ result.physicalCores = coresPerSocket ? coresPerSocket * processorsInt : result.cores / threadsPerCoreInt;
1015
+ result.performanceCores = threadsPerCoreInt > 1 ? result.cores - result.physicalCores : result.cores;
1016
+ result.efficiencyCores = threadsPerCoreInt > 1 ? result.cores - threadsPerCoreInt * result.performanceCores : 0;
1017
+ result.processors = processorsInt;
1018
+ result.governor = util.getValue(lines, 'governor') || '';
1019
+
1020
+ // Test Raspberry
1021
+ if (result.vendor === 'ARM' && util.isRaspberry()) {
1022
+ const rPIRevision = util.decodePiCpuinfo();
1023
+ result.family = result.manufacturer;
1024
+ result.manufacturer = rPIRevision.manufacturer;
1025
+ result.brand = rPIRevision.processor;
1026
+ result.revision = rPIRevision.revisionCode;
1027
+ result.socket = 'SOC';
1028
+ }
1029
+
1030
+ // Test RISC-V
1031
+ if (util.getValue(lines, 'architecture') === 'riscv64') {
1032
+ const linesRiscV = fs.readFileSync('/proc/cpuinfo').toString().split('\n');
1033
+ const uarch = util.getValue(linesRiscV, 'uarch') || '';
1034
+ if (uarch.indexOf(',') > -1) {
1035
+ const split = uarch.split(',');
1036
+ result.manufacturer = cpuManufacturer(split[0]);
1037
+ result.brand = split[1];
1038
+ }
1039
+ }
1040
+
1041
+ // socket type
1042
+ let lines2 = [];
1043
+ exec('export LC_ALL=C; dmidecode –t 4 2>/dev/null | grep "Upgrade: Socket"; unset LC_ALL', (error2, stdout2) => {
1044
+ lines2 = stdout2.toString().split('\n');
1045
+ if (lines2 && lines2.length) {
1046
+ result.socket = util.getValue(lines2, 'Upgrade').replace('Socket', '').trim() || result.socket;
1047
+ }
1048
+ resolve(result);
1049
+ });
1050
+ });
1051
+ }
1052
+ if (_freebsd || _openbsd || _netbsd) {
1053
+ let modelline = '';
1054
+ let lines = [];
1055
+ if (os.cpus()[0] && os.cpus()[0].model) {
1056
+ modelline = os.cpus()[0].model;
1057
+ }
1058
+ exec('export LC_ALL=C; dmidecode -t 4; dmidecode -t 7 unset LC_ALL', (error, stdout) => {
1059
+ let cache = [];
1060
+ if (!error) {
1061
+ const data = stdout.toString().split('# dmidecode');
1062
+ const processor = data.length > 1 ? data[1] : '';
1063
+ cache = data.length > 2 ? data[2].split('Cache Information') : [];
1064
+
1065
+ lines = processor.split('\n');
1066
+ }
1067
+ result.brand = modelline.split('@')[0].trim();
1068
+ result.speed = modelline.split('@')[1] ? parseFloat(modelline.split('@')[1].trim()) : 0;
1069
+ if (result.speed === 0 && (result.brand.indexOf('AMD') > -1 || result.brand.toLowerCase().indexOf('ryzen') > -1)) {
1070
+ result.speed = getAMDSpeed(result.brand);
1071
+ }
1072
+ if (result.speed === 0) {
1073
+ const current = getCpuCurrentSpeedSync();
1074
+ if (current.avg !== 0) {
1075
+ result.speed = current.avg;
1076
+ }
1077
+ }
1078
+ _cpu_speed = result.speed;
1079
+ result.speedMin = result.speed;
1080
+ result.speedMax = Math.round(parseFloat(util.getValue(lines, 'max speed').replace(/Mhz/g, '')) / 10.0) / 100;
1081
+
1082
+ result = cpuBrandManufacturer(result);
1083
+ result.vendor = cpuManufacturer(util.getValue(lines, 'manufacturer'));
1084
+ let sig = util.getValue(lines, 'signature');
1085
+ sig = sig.split(',');
1086
+ for (let i = 0; i < sig.length; i++) {
1087
+ sig[i] = sig[i].trim();
1088
+ }
1089
+ result.family = util.getValue(sig, 'Family', ' ', true);
1090
+ result.model = util.getValue(sig, 'Model', ' ', true);
1091
+ result.stepping = util.getValue(sig, 'Stepping', ' ', true);
1092
+ result.revision = '';
1093
+ const voltage = parseFloat(util.getValue(lines, 'voltage'));
1094
+ result.voltage = isNaN(voltage) ? '' : voltage.toFixed(2);
1095
+ for (let i = 0; i < cache.length; i++) {
1096
+ lines = cache[i].split('\n');
1097
+ let cacheType = util.getValue(lines, 'Socket Designation').toLowerCase().replace(' ', '-').split('-');
1098
+ cacheType = cacheType.length ? cacheType[0] : '';
1099
+ const sizeParts = util.getValue(lines, 'Installed Size').split(' ');
1100
+ let size = parseInt(sizeParts[0], 10);
1101
+ const unit = sizeParts.length > 1 ? sizeParts[1] : 'kb';
1102
+ size = size * (unit === 'kb' ? 1024 : unit === 'mb' ? 1024 * 1024 : unit === 'gb' ? 1024 * 1024 * 1024 : 1);
1103
+ if (cacheType) {
1104
+ if (cacheType === 'l1') {
1105
+ result.cache[cacheType + 'd'] = size / 2;
1106
+ result.cache[cacheType + 'i'] = size / 2;
1107
+ } else {
1108
+ result.cache[cacheType] = size;
1109
+ }
1110
+ }
1111
+ }
1112
+ // socket type
1113
+ result.socket = util.getValue(lines, 'Upgrade').replace('Socket', '').trim();
1114
+ // # threads / # cores
1115
+ const threadCount = util.getValue(lines, 'thread count').trim();
1116
+ const coreCount = util.getValue(lines, 'core count').trim();
1117
+ if (coreCount && threadCount) {
1118
+ result.cores = parseInt(threadCount, 10);
1119
+ result.physicalCores = parseInt(coreCount, 10);
1120
+ }
1121
+ resolve(result);
1122
+ });
1123
+ }
1124
+ if (_sunos) {
1125
+ resolve(result);
1126
+ }
1127
+ if (_windows) {
1128
+ try {
1129
+ const workload = [];
1130
+ workload.push(
1131
+ util.powerShell(
1132
+ 'Get-CimInstance Win32_processor | select Name, Revision, L2CacheSize, L3CacheSize, Manufacturer, MaxClockSpeed, Description, UpgradeMethod, Caption, NumberOfLogicalProcessors, NumberOfCores | fl'
1133
+ )
1134
+ );
1135
+ workload.push(util.powerShell('Get-CimInstance Win32_CacheMemory | select CacheType,InstalledSize,Level | fl'));
1136
+ workload.push(util.powerShell('(Get-CimInstance Win32_ComputerSystem).HypervisorPresent'));
1137
+
1138
+ Promise.all(workload).then((data) => {
1139
+ let lines = data[0].split('\r\n');
1140
+ let name = util.getValue(lines, 'name', ':') || '';
1141
+ if (name.indexOf('@') >= 0) {
1142
+ result.brand = name.split('@')[0].trim();
1143
+ result.speed = name.split('@')[1] ? parseFloat(name.split('@')[1].trim()) : 0;
1144
+ _cpu_speed = result.speed;
1145
+ } else {
1146
+ result.brand = name.trim();
1147
+ result.speed = 0;
1148
+ }
1149
+ result = cpuBrandManufacturer(result);
1150
+ result.revision = util.getValue(lines, 'revision', ':');
1151
+ result.vendor = util.getValue(lines, 'manufacturer', ':');
1152
+ result.speedMax = Math.round(parseFloat(util.getValue(lines, 'maxclockspeed', ':').replace(/,/g, '.')) / 10.0) / 100;
1153
+ if (result.speed === 0 && (result.brand.indexOf('AMD') > -1 || result.brand.toLowerCase().indexOf('ryzen') > -1)) {
1154
+ result.speed = getAMDSpeed(result.brand);
1155
+ }
1156
+ if (result.speed === 0) {
1157
+ result.speed = result.speedMax;
1158
+ }
1159
+ result.speedMin = result.speed;
1160
+
1161
+ let description = util.getValue(lines, 'description', ':').split(' ');
1162
+ for (let i = 0; i < description.length; i++) {
1163
+ if (description[i].toLowerCase().startsWith('family') && i + 1 < description.length && description[i + 1]) {
1164
+ result.family = description[i + 1];
1165
+ }
1166
+ if (description[i].toLowerCase().startsWith('model') && i + 1 < description.length && description[i + 1]) {
1167
+ result.model = description[i + 1];
1168
+ }
1169
+ if (description[i].toLowerCase().startsWith('stepping') && i + 1 < description.length && description[i + 1]) {
1170
+ result.stepping = description[i + 1];
1171
+ }
1172
+ }
1173
+ // socket type
1174
+ const socketId = util.getValue(lines, 'UpgradeMethod', ':');
1175
+ if (socketTypes[socketId]) {
1176
+ result.socket = socketTypes[socketId];
1177
+ }
1178
+ const socketByName = getSocketTypesByName(name);
1179
+ if (socketByName) {
1180
+ result.socket = socketByName;
1181
+ }
1182
+ // # threads / # cores
1183
+ const countProcessors = util.countLines(lines, 'Caption');
1184
+ const countThreads = util.getValue(lines, 'NumberOfLogicalProcessors', ':');
1185
+ const countCores = util.getValue(lines, 'NumberOfCores', ':');
1186
+ if (countProcessors) {
1187
+ result.processors = parseInt(countProcessors) || 1;
1188
+ }
1189
+ if (countCores && countThreads) {
1190
+ result.cores = parseInt(countThreads) || util.cores();
1191
+ result.physicalCores = parseInt(countCores) || util.cores();
1192
+ }
1193
+ if (countProcessors > 1) {
1194
+ result.cores = result.cores * countProcessors;
1195
+ result.physicalCores = result.physicalCores * countProcessors;
1196
+ }
1197
+ result.cache = parseWinCache(data[0], data[1]);
1198
+ const hyperv = data[2] ? data[2].toString().toLowerCase() : '';
1199
+ result.virtualization = hyperv.indexOf('true') !== -1;
1200
+
1201
+ resolve(result);
1202
+ });
1203
+ } catch (e) {
1204
+ resolve(result);
1205
+ }
1206
+ }
1207
+ });
1208
+ });
1209
+ });
1210
+ }
1211
+
1212
+ // --------------------------
1213
+ // CPU - Processor Data
1214
+
1215
+ function cpu(callback) {
1216
+ return new Promise((resolve) => {
1217
+ process.nextTick(() => {
1218
+ getCpu().then((result) => {
1219
+ if (callback) {
1220
+ callback(result);
1221
+ }
1222
+ resolve(result);
1223
+ });
1224
+ });
1225
+ });
1226
+ }
1227
+
1228
+ exports.cpu = cpu;
1229
+
1230
+ // --------------------------
1231
+ // CPU - current speed - in GHz
1232
+
1233
+ function getCpuCurrentSpeedSync() {
1234
+ const cpus = os.cpus();
1235
+ let minFreq = 999999999;
1236
+ let maxFreq = 0;
1237
+ let avgFreq = 0;
1238
+ const cores = [];
1239
+ const speeds = [];
1240
+
1241
+ if (cpus && cpus.length && Object.prototype.hasOwnProperty.call(cpus[0], 'speed')) {
1242
+ for (let i in cpus) {
1243
+ speeds.push(cpus[i].speed > 100 ? (cpus[i].speed + 1) / 1000 : cpus[i].speed / 10);
1244
+ }
1245
+ } else if (_linux) {
1246
+ try {
1247
+ const speedStrings = execSync('cat /proc/cpuinfo | grep "cpu MHz" | cut -d " " -f 3', util.execOptsLinux)
1248
+ .toString()
1249
+ .split('\n')
1250
+ .filter((line) => line.length > 0);
1251
+ for (let i in speedStrings) {
1252
+ speeds.push(Math.floor(parseInt(speedStrings[i], 10) / 10) / 100);
1253
+ }
1254
+ } catch {
1255
+ util.noop();
1256
+ }
1257
+ }
1258
+
1259
+ if (speeds && speeds.length) {
1260
+ try {
1261
+ for (const i in speeds) {
1262
+ avgFreq = avgFreq + speeds[i];
1263
+ if (speeds[i] > maxFreq) {
1264
+ maxFreq = speeds[i];
1265
+ }
1266
+ if (speeds[i] < minFreq) {
1267
+ minFreq = speeds[i];
1268
+ }
1269
+ cores.push(parseFloat(speeds[i].toFixed(2)));
1270
+ }
1271
+ avgFreq = avgFreq / speeds.length;
1272
+ return {
1273
+ min: parseFloat(minFreq.toFixed(2)),
1274
+ max: parseFloat(maxFreq.toFixed(2)),
1275
+ avg: parseFloat(avgFreq.toFixed(2)),
1276
+ cores: cores
1277
+ };
1278
+ } catch (e) {
1279
+ return {
1280
+ min: 0,
1281
+ max: 0,
1282
+ avg: 0,
1283
+ cores: cores
1284
+ };
1285
+ }
1286
+ } else {
1287
+ return {
1288
+ min: 0,
1289
+ max: 0,
1290
+ avg: 0,
1291
+ cores: cores
1292
+ };
1293
+ }
1294
+ }
1295
+
1296
+ function cpuCurrentSpeed(callback) {
1297
+ return new Promise((resolve) => {
1298
+ process.nextTick(() => {
1299
+ let result = getCpuCurrentSpeedSync();
1300
+ if (result.avg === 0 && _cpu_speed !== 0) {
1301
+ const currCpuSpeed = parseFloat(_cpu_speed);
1302
+ result = {
1303
+ min: currCpuSpeed,
1304
+ max: currCpuSpeed,
1305
+ avg: currCpuSpeed,
1306
+ cores: []
1307
+ };
1308
+ }
1309
+ if (callback) {
1310
+ callback(result);
1311
+ }
1312
+ resolve(result);
1313
+ });
1314
+ });
1315
+ }
1316
+
1317
+ exports.cpuCurrentSpeed = cpuCurrentSpeed;
1318
+
1319
+ // --------------------------
1320
+ // CPU - temperature
1321
+ // if sensors are installed
1322
+
1323
+ function cpuTemperature(callback) {
1324
+ return new Promise((resolve) => {
1325
+ process.nextTick(() => {
1326
+ let result = {
1327
+ main: null,
1328
+ cores: [],
1329
+ max: null,
1330
+ socket: [],
1331
+ chipset: null
1332
+ };
1333
+ if (_linux) {
1334
+ // CPU Chipset, Socket
1335
+ try {
1336
+ const cmd = 'cat /sys/class/thermal/thermal_zone*/type 2>/dev/null; echo "-----"; cat /sys/class/thermal/thermal_zone*/temp 2>/dev/null;';
1337
+ const parts = execSync(cmd, util.execOptsLinux).toString().split('-----\n');
1338
+ if (parts.length === 2) {
1339
+ const lines = parts[0].split('\n');
1340
+ const lines2 = parts[1].split('\n');
1341
+ for (let i = 0; i < lines.length; i++) {
1342
+ const line = lines[i].trim();
1343
+ if (line.startsWith('acpi') && lines2[i]) {
1344
+ result.socket.push(Math.round(parseInt(lines2[i], 10) / 100) / 10);
1345
+ }
1346
+ if (line.startsWith('pch') && lines2[i]) {
1347
+ result.chipset = Math.round(parseInt(lines2[i], 10) / 100) / 10;
1348
+ }
1349
+ }
1350
+ }
1351
+ } catch (e) {
1352
+ util.noop();
1353
+ }
1354
+
1355
+ const cmd =
1356
+ 'for mon in /sys/class/hwmon/hwmon*; do for label in "$mon"/temp*_label; do if [ -f $label ]; then value=${label%_*}_input; echo $(cat "$label")___$(cat "$value"); fi; done; done;';
1357
+ try {
1358
+ exec(cmd, (error, stdout) => {
1359
+ stdout = stdout.toString();
1360
+ const tdiePos = stdout.toLowerCase().indexOf('tdie');
1361
+ if (tdiePos !== -1) {
1362
+ stdout = stdout.substring(tdiePos);
1363
+ }
1364
+ const lines = stdout.split('\n');
1365
+ let tctl = 0;
1366
+ lines.forEach((line) => {
1367
+ const parts = line.split('___');
1368
+ const label = parts[0];
1369
+ const value = parts.length > 1 && parts[1] ? parts[1] : '0';
1370
+ if (value && label && label.toLowerCase() === 'tctl') {
1371
+ tctl = result.main = Math.round(parseInt(value, 10) / 100) / 10;
1372
+ }
1373
+ if (value && (label === undefined || (label && label.toLowerCase().startsWith('core')))) {
1374
+ result.cores.push(Math.round(parseInt(value, 10) / 100) / 10);
1375
+ } else if (value && label && result.main === null && (label.toLowerCase().indexOf('package') >= 0 || label.toLowerCase().indexOf('physical') >= 0 || label.toLowerCase() === 'tccd1')) {
1376
+ result.main = Math.round(parseInt(value, 10) / 100) / 10;
1377
+ }
1378
+ });
1379
+ if (tctl && result.main === null) {
1380
+ result.main = tctl;
1381
+ }
1382
+
1383
+ if (result.cores.length > 0) {
1384
+ if (result.main === null) {
1385
+ result.main = Math.round(result.cores.reduce((a, b) => a + b, 0) / result.cores.length);
1386
+ }
1387
+ let maxtmp = Math.max.apply(Math, result.cores);
1388
+ result.max = maxtmp > result.main ? maxtmp : result.main;
1389
+ }
1390
+ if (result.main !== null) {
1391
+ if (result.max === null) {
1392
+ result.max = result.main;
1393
+ }
1394
+ if (callback) {
1395
+ callback(result);
1396
+ }
1397
+ resolve(result);
1398
+ return;
1399
+ }
1400
+ exec('sensors', (error, stdout) => {
1401
+ if (!error) {
1402
+ const lines = stdout.toString().split('\n');
1403
+ let tdieTemp = null;
1404
+ let newSectionStarts = true;
1405
+ let section = '';
1406
+ lines.forEach((line) => {
1407
+ // determine section
1408
+ if (line.trim() === '') {
1409
+ newSectionStarts = true;
1410
+ } else if (newSectionStarts) {
1411
+ if (line.trim().toLowerCase().startsWith('acpi')) {
1412
+ section = 'acpi';
1413
+ }
1414
+ if (line.trim().toLowerCase().startsWith('pch')) {
1415
+ section = 'pch';
1416
+ }
1417
+ if (line.trim().toLowerCase().startsWith('core')) {
1418
+ section = 'core';
1419
+ }
1420
+ if (line.trim().toLowerCase().startsWith('k10temp')) {
1421
+ section = 'coreAMD';
1422
+ }
1423
+ newSectionStarts = false;
1424
+ }
1425
+ const regex = /[+-]([^°]*)/g;
1426
+ const temps = line.match(regex);
1427
+ const firstPart = line.split(':')[0].toUpperCase();
1428
+ if (section === 'acpi') {
1429
+ // socket temp
1430
+ if (firstPart.indexOf('TEMP') !== -1) {
1431
+ result.socket.push(parseFloat(temps));
1432
+ }
1433
+ } else if (section === 'pch') {
1434
+ // chipset temp
1435
+ if (firstPart.indexOf('TEMP') !== -1 && !result.chipset) {
1436
+ result.chipset = parseFloat(temps);
1437
+ }
1438
+ }
1439
+ // cpu temp
1440
+ if (firstPart.indexOf('PHYSICAL') !== -1 || firstPart.indexOf('PACKAGE') !== -1 || (section === 'coreAMD' && firstPart.indexOf('TDIE') !== -1) || firstPart.indexOf('TEMP') !== -1) {
1441
+ result.main = parseFloat(temps);
1442
+ }
1443
+ if (firstPart.indexOf('CORE ') !== -1) {
1444
+ result.cores.push(parseFloat(temps));
1445
+ }
1446
+ if (firstPart.indexOf('TDIE') !== -1 && tdieTemp === null) {
1447
+ tdieTemp = parseFloat(temps);
1448
+ }
1449
+ });
1450
+ if (result.cores.length > 0) {
1451
+ result.main = Math.round(result.cores.reduce((a, b) => a + b, 0) / result.cores.length);
1452
+ const maxtmp = Math.max.apply(Math, result.cores);
1453
+ result.max = maxtmp > result.main ? maxtmp : result.main;
1454
+ } else {
1455
+ if (result.main === null && tdieTemp !== null) {
1456
+ result.main = tdieTemp;
1457
+ result.max = tdieTemp;
1458
+ }
1459
+ }
1460
+ if (result.main !== null && result.max === null) {
1461
+ result.max = result.main;
1462
+ }
1463
+ if (result.main !== null || result.max !== null) {
1464
+ if (callback) {
1465
+ callback(result);
1466
+ }
1467
+ resolve(result);
1468
+ return;
1469
+ }
1470
+ }
1471
+ fs.stat('/sys/class/thermal/thermal_zone0/temp', (err) => {
1472
+ if (err === null) {
1473
+ fs.readFile('/sys/class/thermal/thermal_zone0/temp', (error, stdout) => {
1474
+ if (!error) {
1475
+ const lines = stdout.toString().split('\n');
1476
+ if (lines.length > 0) {
1477
+ result.main = parseFloat(lines[0]) / 1000.0;
1478
+ result.max = result.main;
1479
+ }
1480
+ }
1481
+ if (callback) {
1482
+ callback(result);
1483
+ }
1484
+ resolve(result);
1485
+ });
1486
+ } else {
1487
+ exec('/opt/vc/bin/vcgencmd measure_temp', (error, stdout) => {
1488
+ if (!error) {
1489
+ const lines = stdout.toString().split('\n');
1490
+ if (lines.length > 0 && lines[0].indexOf('=')) {
1491
+ result.main = parseFloat(lines[0].split('=')[1]);
1492
+ result.max = result.main;
1493
+ }
1494
+ }
1495
+ if (callback) {
1496
+ callback(result);
1497
+ }
1498
+ resolve(result);
1499
+ });
1500
+ }
1501
+ });
1502
+ });
1503
+ });
1504
+ } catch {
1505
+ if (callback) {
1506
+ callback(result);
1507
+ }
1508
+ resolve(result);
1509
+ }
1510
+ }
1511
+ if (_freebsd || _openbsd || _netbsd) {
1512
+ exec('sysctl dev.cpu | grep temp', (error, stdout) => {
1513
+ if (!error) {
1514
+ const lines = stdout.toString().split('\n');
1515
+ let sum = 0;
1516
+ lines.forEach((line) => {
1517
+ const parts = line.split(':');
1518
+ if (parts.length > 1) {
1519
+ const temp = parseFloat(parts[1].replace(',', '.'));
1520
+ if (temp > result.max) {
1521
+ result.max = temp;
1522
+ }
1523
+ sum = sum + temp;
1524
+ result.cores.push(temp);
1525
+ }
1526
+ });
1527
+ if (result.cores.length) {
1528
+ result.main = Math.round((sum / result.cores.length) * 100) / 100;
1529
+ }
1530
+ }
1531
+ if (callback) {
1532
+ callback(result);
1533
+ }
1534
+ resolve(result);
1535
+ });
1536
+ }
1537
+ if (_darwin) {
1538
+ try {
1539
+ const osxTemp = require('osx-temperature-sensor');
1540
+ result = osxTemp.cpuTemperature();
1541
+ if (result.main) {
1542
+ // round to 2 digits
1543
+ result.main = Math.round(result.main * 100) / 100;
1544
+ }
1545
+ if (result.max) {
1546
+ result.max = Math.round(result.max * 100) / 100;
1547
+ }
1548
+ if (result && result.cores && result.cores.length) {
1549
+ for (let i = 0; i < result.cores.length; i++) {
1550
+ result.cores[i] = Math.round(result.cores[i] * 100) / 100;
1551
+ }
1552
+ }
1553
+ } catch {
1554
+ util.noop();
1555
+ }
1556
+ try {
1557
+ const macosTemp = require('macos-temperature-sensor');
1558
+ const res = macosTemp.temperature();
1559
+ if (res.cpu) {
1560
+ // round to 2 digits
1561
+ result.main = Math.round(res.cpu * 100) / 100;
1562
+ result.max = result.main;
1563
+ }
1564
+ if (res.soc) {
1565
+ // round to 2 digits
1566
+ result.chipset = Math.round(res.soc * 100) / 100;
1567
+ }
1568
+ if (res && res.cpuDieTemps.length) {
1569
+ for (const temp of res.cpuDieTemps) {
1570
+ result.cores.push(Math.round(temp * 100) / 100);
1571
+ }
1572
+ }
1573
+ } catch {
1574
+ util.noop();
1575
+ }
1576
+
1577
+ if (callback) {
1578
+ callback(result);
1579
+ }
1580
+ resolve(result);
1581
+ }
1582
+ if (_sunos) {
1583
+ if (callback) {
1584
+ callback(result);
1585
+ }
1586
+ resolve(result);
1587
+ }
1588
+ if (_windows) {
1589
+ try {
1590
+ util.powerShell('Get-CimInstance MSAcpi_ThermalZoneTemperature -Namespace "root/wmi" | Select CurrentTemperature').then((stdout, error) => {
1591
+ if (!error) {
1592
+ let sum = 0;
1593
+ const lines = stdout
1594
+ .split('\r\n')
1595
+ .filter((line) => line.trim() !== '')
1596
+ .filter((line, idx) => idx > 0);
1597
+ lines.forEach((line) => {
1598
+ const value = (parseInt(line, 10) - 2732) / 10;
1599
+ if (!isNaN(value)) {
1600
+ sum = sum + value;
1601
+ if (value > result.max) {
1602
+ result.max = value;
1603
+ }
1604
+ result.cores.push(value);
1605
+ }
1606
+ });
1607
+ if (result.cores.length) {
1608
+ result.main = sum / result.cores.length;
1609
+ }
1610
+ }
1611
+ if (callback) {
1612
+ callback(result);
1613
+ }
1614
+ resolve(result);
1615
+ });
1616
+ } catch {
1617
+ if (callback) {
1618
+ callback(result);
1619
+ }
1620
+ resolve(result);
1621
+ }
1622
+ }
1623
+ });
1624
+ });
1625
+ }
1626
+
1627
+ exports.cpuTemperature = cpuTemperature;
1628
+
1629
+ // --------------------------
1630
+ // CPU Flags
1631
+
1632
+ function cpuFlags(callback) {
1633
+ return new Promise((resolve) => {
1634
+ process.nextTick(() => {
1635
+ let result = '';
1636
+ if (_windows) {
1637
+ try {
1638
+ exec('reg query "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0" /v FeatureSet', util.execOptsWin, (error, stdout) => {
1639
+ if (!error) {
1640
+ let flag_hex = stdout.split('0x').pop().trim();
1641
+ let flag_bin_unpadded = parseInt(flag_hex, 16).toString(2);
1642
+ let flag_bin = '0'.repeat(32 - flag_bin_unpadded.length) + flag_bin_unpadded;
1643
+ // empty flags are the reserved fields in the CPUID feature bit list
1644
+ // as found on wikipedia:
1645
+ // https://en.wikipedia.org/wiki/CPUID
1646
+ let all_flags = [
1647
+ 'fpu',
1648
+ 'vme',
1649
+ 'de',
1650
+ 'pse',
1651
+ 'tsc',
1652
+ 'msr',
1653
+ 'pae',
1654
+ 'mce',
1655
+ 'cx8',
1656
+ 'apic',
1657
+ '',
1658
+ 'sep',
1659
+ 'mtrr',
1660
+ 'pge',
1661
+ 'mca',
1662
+ 'cmov',
1663
+ 'pat',
1664
+ 'pse-36',
1665
+ 'psn',
1666
+ 'clfsh',
1667
+ '',
1668
+ 'ds',
1669
+ 'acpi',
1670
+ 'mmx',
1671
+ 'fxsr',
1672
+ 'sse',
1673
+ 'sse2',
1674
+ 'ss',
1675
+ 'htt',
1676
+ 'tm',
1677
+ 'ia64',
1678
+ 'pbe'
1679
+ ];
1680
+ for (let f = 0; f < all_flags.length; f++) {
1681
+ if (flag_bin[f] === '1' && all_flags[f] !== '') {
1682
+ result += ' ' + all_flags[f];
1683
+ }
1684
+ }
1685
+ result = result.trim().toLowerCase();
1686
+ }
1687
+ if (callback) {
1688
+ callback(result);
1689
+ }
1690
+ resolve(result);
1691
+ });
1692
+ } catch {
1693
+ if (callback) {
1694
+ callback(result);
1695
+ }
1696
+ resolve(result);
1697
+ }
1698
+ }
1699
+ if (_linux) {
1700
+ try {
1701
+ exec('export LC_ALL=C; lscpu; unset LC_ALL', (error, stdout) => {
1702
+ if (!error) {
1703
+ let lines = stdout.toString().split('\n');
1704
+ lines.forEach((line) => {
1705
+ if (line.split(':')[0].toUpperCase().indexOf('FLAGS') !== -1) {
1706
+ result = line.split(':')[1].trim().toLowerCase();
1707
+ }
1708
+ });
1709
+ }
1710
+ if (!result) {
1711
+ fs.readFile('/proc/cpuinfo', (error, stdout) => {
1712
+ if (!error) {
1713
+ let lines = stdout.toString().split('\n');
1714
+ result = util.getValue(lines, 'features', ':', true).toLowerCase();
1715
+ }
1716
+ if (callback) {
1717
+ callback(result);
1718
+ }
1719
+ resolve(result);
1720
+ });
1721
+ } else {
1722
+ if (callback) {
1723
+ callback(result);
1724
+ }
1725
+ resolve(result);
1726
+ }
1727
+ });
1728
+ } catch {
1729
+ if (callback) {
1730
+ callback(result);
1731
+ }
1732
+ resolve(result);
1733
+ }
1734
+ }
1735
+ if (_freebsd || _openbsd || _netbsd) {
1736
+ exec('export LC_ALL=C; dmidecode -t 4 2>/dev/null; unset LC_ALL', (error, stdout) => {
1737
+ const flags = [];
1738
+ if (!error) {
1739
+ const parts = stdout.toString().split('\tFlags:');
1740
+ const lines = parts.length > 1 ? parts[1].split('\tVersion:')[0].split('\n') : [];
1741
+ lines.forEach((line) => {
1742
+ const flag = (line.indexOf('(') ? line.split('(')[0].toLowerCase() : '').trim().replace(/\t/g, '');
1743
+ if (flag) {
1744
+ flags.push(flag);
1745
+ }
1746
+ });
1747
+ }
1748
+ result = flags.join(' ').trim().toLowerCase();
1749
+ if (callback) {
1750
+ callback(result);
1751
+ }
1752
+ resolve(result);
1753
+ });
1754
+ }
1755
+ if (_darwin) {
1756
+ exec('sysctl machdep.cpu.features', (error, stdout) => {
1757
+ if (!error) {
1758
+ let lines = stdout.toString().split('\n');
1759
+ if (lines.length > 0 && lines[0].indexOf('machdep.cpu.features:') !== -1) {
1760
+ result = lines[0].split(':')[1].trim().toLowerCase();
1761
+ }
1762
+ }
1763
+ if (callback) {
1764
+ callback(result);
1765
+ }
1766
+ resolve(result);
1767
+ });
1768
+ }
1769
+ if (_sunos) {
1770
+ if (callback) {
1771
+ callback(result);
1772
+ }
1773
+ resolve(result);
1774
+ }
1775
+ });
1776
+ });
1777
+ }
1778
+
1779
+ exports.cpuFlags = cpuFlags;
1780
+
1781
+ // --------------------------
1782
+ // CPU Cache
1783
+
1784
+ function cpuCache(callback) {
1785
+ return new Promise((resolve) => {
1786
+ process.nextTick(() => {
1787
+ let result = {
1788
+ l1d: null,
1789
+ l1i: null,
1790
+ l2: null,
1791
+ l3: null
1792
+ };
1793
+ if (_linux) {
1794
+ try {
1795
+ exec('export LC_ALL=C; lscpu; unset LC_ALL', (error, stdout) => {
1796
+ if (!error) {
1797
+ const lines = stdout.toString().split('\n');
1798
+ lines.forEach((line) => {
1799
+ const parts = line.split(':');
1800
+ if (parts[0].toUpperCase().indexOf('L1D CACHE') !== -1) {
1801
+ result.l1d = parseInt(parts[1].trim()) * (parts[1].indexOf('M') !== -1 ? 1024 * 1024 : parts[1].indexOf('K') !== -1 ? 1024 : 1);
1802
+ }
1803
+ if (parts[0].toUpperCase().indexOf('L1I CACHE') !== -1) {
1804
+ result.l1i = parseInt(parts[1].trim()) * (parts[1].indexOf('M') !== -1 ? 1024 * 1024 : parts[1].indexOf('K') !== -1 ? 1024 : 1);
1805
+ }
1806
+ if (parts[0].toUpperCase().indexOf('L2 CACHE') !== -1) {
1807
+ result.l2 = parseInt(parts[1].trim()) * (parts[1].indexOf('M') !== -1 ? 1024 * 1024 : parts[1].indexOf('K') !== -1 ? 1024 : 1);
1808
+ }
1809
+ if (parts[0].toUpperCase().indexOf('L3 CACHE') !== -1) {
1810
+ result.l3 = parseInt(parts[1].trim()) * (parts[1].indexOf('M') !== -1 ? 1024 * 1024 : parts[1].indexOf('K') !== -1 ? 1024 : 1);
1811
+ }
1812
+ });
1813
+ }
1814
+ if (callback) {
1815
+ callback(result);
1816
+ }
1817
+ resolve(result);
1818
+ });
1819
+ } catch {
1820
+ if (callback) {
1821
+ callback(result);
1822
+ }
1823
+ resolve(result);
1824
+ }
1825
+ }
1826
+ if (_freebsd || _openbsd || _netbsd) {
1827
+ exec('export LC_ALL=C; dmidecode -t 7 2>/dev/null; unset LC_ALL', (error, stdout) => {
1828
+ let cache = [];
1829
+ if (!error) {
1830
+ const data = stdout.toString();
1831
+ cache = data.split('Cache Information');
1832
+ cache.shift();
1833
+ }
1834
+ for (let i = 0; i < cache.length; i++) {
1835
+ const lines = cache[i].split('\n');
1836
+ let cacheType = util.getValue(lines, 'Socket Designation').toLowerCase().replace(' ', '-').split('-');
1837
+ cacheType = cacheType.length ? cacheType[0] : '';
1838
+ const sizeParts = util.getValue(lines, 'Installed Size').split(' ');
1839
+ let size = parseInt(sizeParts[0], 10);
1840
+ const unit = sizeParts.length > 1 ? sizeParts[1] : 'kb';
1841
+ size = size * (unit === 'kb' ? 1024 : unit === 'mb' ? 1024 * 1024 : unit === 'gb' ? 1024 * 1024 * 1024 : 1);
1842
+ if (cacheType) {
1843
+ if (cacheType === 'l1') {
1844
+ result.cache[cacheType + 'd'] = size / 2;
1845
+ result.cache[cacheType + 'i'] = size / 2;
1846
+ } else {
1847
+ result.cache[cacheType] = size;
1848
+ }
1849
+ }
1850
+ }
1851
+ if (callback) {
1852
+ callback(result);
1853
+ }
1854
+ resolve(result);
1855
+ });
1856
+ }
1857
+ if (_darwin) {
1858
+ exec('sysctl hw.l1icachesize hw.l1dcachesize hw.l2cachesize hw.l3cachesize', (error, stdout) => {
1859
+ if (!error) {
1860
+ let lines = stdout.toString().split('\n');
1861
+ lines.forEach((line) => {
1862
+ let parts = line.split(':');
1863
+ if (parts[0].toLowerCase().indexOf('hw.l1icachesize') !== -1) {
1864
+ result.l1d = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
1865
+ }
1866
+ if (parts[0].toLowerCase().indexOf('hw.l1dcachesize') !== -1) {
1867
+ result.l1i = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
1868
+ }
1869
+ if (parts[0].toLowerCase().indexOf('hw.l2cachesize') !== -1) {
1870
+ result.l2 = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
1871
+ }
1872
+ if (parts[0].toLowerCase().indexOf('hw.l3cachesize') !== -1) {
1873
+ result.l3 = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
1874
+ }
1875
+ });
1876
+ }
1877
+ if (callback) {
1878
+ callback(result);
1879
+ }
1880
+ resolve(result);
1881
+ });
1882
+ }
1883
+ if (_sunos) {
1884
+ if (callback) {
1885
+ callback(result);
1886
+ }
1887
+ resolve(result);
1888
+ }
1889
+ if (_windows) {
1890
+ try {
1891
+ const workload = [];
1892
+ workload.push(util.powerShell('Get-CimInstance Win32_processor | select L2CacheSize, L3CacheSize | fl'));
1893
+ workload.push(util.powerShell('Get-CimInstance Win32_CacheMemory | select CacheType,InstalledSize,Level | fl'));
1894
+
1895
+ Promise.all(workload).then((data) => {
1896
+ result = parseWinCache(data[0], data[1]);
1897
+
1898
+ if (callback) {
1899
+ callback(result);
1900
+ }
1901
+ resolve(result);
1902
+ });
1903
+ } catch {
1904
+ if (callback) {
1905
+ callback(result);
1906
+ }
1907
+ resolve(result);
1908
+ }
1909
+ }
1910
+ });
1911
+ });
1912
+ }
1913
+
1914
+ function parseWinCache(linesProc, linesCache) {
1915
+ const result = {
1916
+ l1d: null,
1917
+ l1i: null,
1918
+ l2: null,
1919
+ l3: null
1920
+ };
1921
+
1922
+ // Win32_processor
1923
+ let lines = linesProc.split('\r\n');
1924
+ result.l1d = 0;
1925
+ result.l1i = 0;
1926
+ result.l2 = util.getValue(lines, 'l2cachesize', ':');
1927
+ result.l3 = util.getValue(lines, 'l3cachesize', ':');
1928
+ if (result.l2) {
1929
+ result.l2 = parseInt(result.l2, 10) * 1024;
1930
+ } else {
1931
+ result.l2 = 0;
1932
+ }
1933
+ if (result.l3) {
1934
+ result.l3 = parseInt(result.l3, 10) * 1024;
1935
+ } else {
1936
+ result.l3 = 0;
1937
+ }
1938
+
1939
+ // Win32_CacheMemory
1940
+ const parts = linesCache.split(/\n\s*\n/);
1941
+ let l1i = 0;
1942
+ let l1d = 0;
1943
+ let l2 = 0;
1944
+ parts.forEach((part) => {
1945
+ const lines = part.split('\r\n');
1946
+ const cacheType = util.getValue(lines, 'CacheType');
1947
+ const level = util.getValue(lines, 'Level');
1948
+ const installedSize = util.getValue(lines, 'InstalledSize');
1949
+ // L1 Instructions
1950
+ if (level === '3' && cacheType === '3') {
1951
+ result.l1i = result.l1i + parseInt(installedSize, 10) * 1024;
1952
+ }
1953
+ // L1 Data
1954
+ if (level === '3' && cacheType === '4') {
1955
+ result.l1d = result.l1d + parseInt(installedSize, 10) * 1024;
1956
+ }
1957
+ // L1 all
1958
+ if (level === '3' && cacheType === '5') {
1959
+ l1i = parseInt(installedSize, 10) / 2;
1960
+ l1d = parseInt(installedSize, 10) / 2;
1961
+ }
1962
+ // L2
1963
+ if (level === '4' && cacheType === '5') {
1964
+ l2 = l2 + parseInt(installedSize, 10) * 1024;
1965
+ }
1966
+ });
1967
+ if (!result.l1i && !result.l1d) {
1968
+ result.l1i = l1i;
1969
+ result.l1d = l1d;
1970
+ }
1971
+ if (l2) {
1972
+ result.l2 = l2;
1973
+ }
1974
+ return result;
1975
+ }
1976
+
1977
+ exports.cpuCache = cpuCache;
1978
+
1979
+ // --------------------------
1980
+ // CPU - current load - in %
1981
+
1982
+ function getLoad() {
1983
+ return new Promise((resolve) => {
1984
+ process.nextTick(() => {
1985
+ const loads = os.loadavg().map((x) => {
1986
+ return x / util.cores();
1987
+ });
1988
+ const avgLoad = parseFloat(Math.max.apply(Math, loads).toFixed(2));
1989
+ let result = {};
1990
+
1991
+ const now = Date.now() - _current_cpu.ms;
1992
+ if (now >= 200) {
1993
+ _current_cpu.ms = Date.now();
1994
+ const cpus = os.cpus().map((cpu) => {
1995
+ cpu.times.steal = 0;
1996
+ cpu.times.guest = 0;
1997
+ return cpu;
1998
+ });
1999
+ let totalUser = 0;
2000
+ let totalSystem = 0;
2001
+ let totalNice = 0;
2002
+ let totalIrq = 0;
2003
+ let totalIdle = 0;
2004
+ let totalSteal = 0;
2005
+ let totalGuest = 0;
2006
+ const cores = [];
2007
+ _corecount = cpus && cpus.length ? cpus.length : 0;
2008
+
2009
+ // linux: try to get other cpu stats
2010
+ if (_linux) {
2011
+ try {
2012
+ const lines = execSync('cat /proc/stat 2>/dev/null | grep cpu', util.execOptsLinux).toString().split('\n');
2013
+ if (lines.length > 1) {
2014
+ lines.shift();
2015
+ if (lines.length === cpus.length) {
2016
+ for (let i = 0; i < lines.length; i++) {
2017
+ let parts = lines[i].split(' ');
2018
+ if (parts.length >= 10) {
2019
+ const steal = parseFloat(parts[8]) || 0;
2020
+ const guest = parseFloat(parts[9]) || 0;
2021
+ cpus[i].times.steal = steal;
2022
+ cpus[i].times.guest = guest;
2023
+ }
2024
+ }
2025
+ }
2026
+ }
2027
+ } catch {
2028
+ util.noop();
2029
+ }
2030
+ }
2031
+
2032
+ for (let i = 0; i < _corecount; i++) {
2033
+ const cpu = cpus[i].times;
2034
+ totalUser += cpu.user;
2035
+ totalSystem += cpu.sys;
2036
+ totalNice += cpu.nice;
2037
+ totalIdle += cpu.idle;
2038
+ totalIrq += cpu.irq;
2039
+ totalSteal += cpu.steal || 0;
2040
+ totalGuest += cpu.guest || 0;
2041
+ const tmpTick = _cpus && _cpus[i] && _cpus[i].totalTick ? _cpus[i].totalTick : 0;
2042
+ const tmpLoad = _cpus && _cpus[i] && _cpus[i].totalLoad ? _cpus[i].totalLoad : 0;
2043
+ const tmpUser = _cpus && _cpus[i] && _cpus[i].user ? _cpus[i].user : 0;
2044
+ const tmpSystem = _cpus && _cpus[i] && _cpus[i].sys ? _cpus[i].sys : 0;
2045
+ const tmpNice = _cpus && _cpus[i] && _cpus[i].nice ? _cpus[i].nice : 0;
2046
+ const tmpIdle = _cpus && _cpus[i] && _cpus[i].idle ? _cpus[i].idle : 0;
2047
+ const tmpIrq = _cpus && _cpus[i] && _cpus[i].irq ? _cpus[i].irq : 0;
2048
+ const tmpSteal = _cpus && _cpus[i] && _cpus[i].steal ? _cpus[i].steal : 0;
2049
+ const tmpGuest = _cpus && _cpus[i] && _cpus[i].guest ? _cpus[i].guest : 0;
2050
+ _cpus[i] = cpu;
2051
+ _cpus[i].totalTick = _cpus[i].user + _cpus[i].sys + _cpus[i].nice + _cpus[i].irq + _cpus[i].steal + _cpus[i].guest + _cpus[i].idle;
2052
+ _cpus[i].totalLoad = _cpus[i].user + _cpus[i].sys + _cpus[i].nice + _cpus[i].irq + _cpus[i].steal + _cpus[i].guest;
2053
+ _cpus[i].currentTick = _cpus[i].totalTick - tmpTick;
2054
+ _cpus[i].load = _cpus[i].totalLoad - tmpLoad;
2055
+ _cpus[i].loadUser = _cpus[i].user - tmpUser;
2056
+ _cpus[i].loadSystem = _cpus[i].sys - tmpSystem;
2057
+ _cpus[i].loadNice = _cpus[i].nice - tmpNice;
2058
+ _cpus[i].loadIdle = _cpus[i].idle - tmpIdle;
2059
+ _cpus[i].loadIrq = _cpus[i].irq - tmpIrq;
2060
+ _cpus[i].loadSteal = _cpus[i].steal - tmpSteal;
2061
+ _cpus[i].loadGuest = _cpus[i].guest - tmpGuest;
2062
+ cores[i] = {};
2063
+ cores[i].load = (_cpus[i].load / _cpus[i].currentTick) * 100;
2064
+ cores[i].loadUser = (_cpus[i].loadUser / _cpus[i].currentTick) * 100;
2065
+ cores[i].loadSystem = (_cpus[i].loadSystem / _cpus[i].currentTick) * 100;
2066
+ cores[i].loadNice = (_cpus[i].loadNice / _cpus[i].currentTick) * 100;
2067
+ cores[i].loadIdle = (_cpus[i].loadIdle / _cpus[i].currentTick) * 100;
2068
+ cores[i].loadIrq = (_cpus[i].loadIrq / _cpus[i].currentTick) * 100;
2069
+ cores[i].loadSteal = (_cpus[i].loadSteal / _cpus[i].currentTick) * 100;
2070
+ cores[i].loadGuest = (_cpus[i].loadGuest / _cpus[i].currentTick) * 100;
2071
+ cores[i].rawLoad = _cpus[i].load;
2072
+ cores[i].rawLoadUser = _cpus[i].loadUser;
2073
+ cores[i].rawLoadSystem = _cpus[i].loadSystem;
2074
+ cores[i].rawLoadNice = _cpus[i].loadNice;
2075
+ cores[i].rawLoadIdle = _cpus[i].loadIdle;
2076
+ cores[i].rawLoadIrq = _cpus[i].loadIrq;
2077
+ cores[i].rawLoadSteal = _cpus[i].loadSteal;
2078
+ cores[i].rawLoadGuest = _cpus[i].loadGuest;
2079
+ }
2080
+ const totalTick = totalUser + totalSystem + totalNice + totalIrq + totalSteal + totalGuest + totalIdle;
2081
+ const totalLoad = totalUser + totalSystem + totalNice + totalIrq + totalSteal + totalGuest;
2082
+ const currentTick = totalTick - _current_cpu.tick;
2083
+ result = {
2084
+ avgLoad: avgLoad,
2085
+ currentLoad: ((totalLoad - _current_cpu.load) / currentTick) * 100,
2086
+ currentLoadUser: ((totalUser - _current_cpu.user) / currentTick) * 100,
2087
+ currentLoadSystem: ((totalSystem - _current_cpu.system) / currentTick) * 100,
2088
+ currentLoadNice: ((totalNice - _current_cpu.nice) / currentTick) * 100,
2089
+ currentLoadIdle: ((totalIdle - _current_cpu.idle) / currentTick) * 100,
2090
+ currentLoadIrq: ((totalIrq - _current_cpu.irq) / currentTick) * 100,
2091
+ currentLoadSteal: ((totalSteal - _current_cpu.steal) / currentTick) * 100,
2092
+ currentLoadGuest: ((totalGuest - _current_cpu.guest) / currentTick) * 100,
2093
+ rawCurrentLoad: totalLoad - _current_cpu.load,
2094
+ rawCurrentLoadUser: totalUser - _current_cpu.user,
2095
+ rawCurrentLoadSystem: totalSystem - _current_cpu.system,
2096
+ rawCurrentLoadNice: totalNice - _current_cpu.nice,
2097
+ rawCurrentLoadIdle: totalIdle - _current_cpu.idle,
2098
+ rawCurrentLoadIrq: totalIrq - _current_cpu.irq,
2099
+ rawCurrentLoadSteal: totalSteal - _current_cpu.steal,
2100
+ rawCurrentLoadGuest: totalGuest - _current_cpu.guest,
2101
+ cpus: cores
2102
+ };
2103
+ _current_cpu = {
2104
+ user: totalUser,
2105
+ nice: totalNice,
2106
+ system: totalSystem,
2107
+ idle: totalIdle,
2108
+ irq: totalIrq,
2109
+ steal: totalSteal,
2110
+ guest: totalGuest,
2111
+ tick: totalTick,
2112
+ load: totalLoad,
2113
+ ms: _current_cpu.ms,
2114
+ currentLoad: result.currentLoad,
2115
+ currentLoadUser: result.currentLoadUser,
2116
+ currentLoadSystem: result.currentLoadSystem,
2117
+ currentLoadNice: result.currentLoadNice,
2118
+ currentLoadIdle: result.currentLoadIdle,
2119
+ currentLoadIrq: result.currentLoadIrq,
2120
+ currentLoadSteal: result.currentLoadSteal,
2121
+ currentLoadGuest: result.currentLoadGuest,
2122
+ rawCurrentLoad: result.rawCurrentLoad,
2123
+ rawCurrentLoadUser: result.rawCurrentLoadUser,
2124
+ rawCurrentLoadSystem: result.rawCurrentLoadSystem,
2125
+ rawCurrentLoadNice: result.rawCurrentLoadNice,
2126
+ rawCurrentLoadIdle: result.rawCurrentLoadIdle,
2127
+ rawCurrentLoadIrq: result.rawCurrentLoadIrq,
2128
+ rawCurrentLoadSteal: result.rawCurrentLoadSteal,
2129
+ rawCurrentLoadGuest: result.rawCurrentLoadGuest
2130
+ };
2131
+ } else {
2132
+ const cores = [];
2133
+ for (let i = 0; i < _corecount; i++) {
2134
+ cores[i] = {};
2135
+ cores[i].load = (_cpus[i].load / _cpus[i].currentTick) * 100;
2136
+ cores[i].loadUser = (_cpus[i].loadUser / _cpus[i].currentTick) * 100;
2137
+ cores[i].loadSystem = (_cpus[i].loadSystem / _cpus[i].currentTick) * 100;
2138
+ cores[i].loadNice = (_cpus[i].loadNice / _cpus[i].currentTick) * 100;
2139
+ cores[i].loadIdle = (_cpus[i].loadIdle / _cpus[i].currentTick) * 100;
2140
+ cores[i].loadIrq = (_cpus[i].loadIrq / _cpus[i].currentTick) * 100;
2141
+ cores[i].rawLoad = _cpus[i].load;
2142
+ cores[i].rawLoadUser = _cpus[i].loadUser;
2143
+ cores[i].rawLoadSystem = _cpus[i].loadSystem;
2144
+ cores[i].rawLoadNice = _cpus[i].loadNice;
2145
+ cores[i].rawLoadIdle = _cpus[i].loadIdle;
2146
+ cores[i].rawLoadIrq = _cpus[i].loadIrq;
2147
+ cores[i].rawLoadSteal = _cpus[i].loadSteal;
2148
+ cores[i].rawLoadGuest = _cpus[i].loadGuest;
2149
+ }
2150
+ result = {
2151
+ avgLoad: avgLoad,
2152
+ currentLoad: _current_cpu.currentLoad,
2153
+ currentLoadUser: _current_cpu.currentLoadUser,
2154
+ currentLoadSystem: _current_cpu.currentLoadSystem,
2155
+ currentLoadNice: _current_cpu.currentLoadNice,
2156
+ currentLoadIdle: _current_cpu.currentLoadIdle,
2157
+ currentLoadIrq: _current_cpu.currentLoadIrq,
2158
+ currentLoadSteal: _current_cpu.currentLoadSteal,
2159
+ currentLoadGuest: _current_cpu.currentLoadGuest,
2160
+ rawCurrentLoad: _current_cpu.rawCurrentLoad,
2161
+ rawCurrentLoadUser: _current_cpu.rawCurrentLoadUser,
2162
+ rawCurrentLoadSystem: _current_cpu.rawCurrentLoadSystem,
2163
+ rawCurrentLoadNice: _current_cpu.rawCurrentLoadNice,
2164
+ rawCurrentLoadIdle: _current_cpu.rawCurrentLoadIdle,
2165
+ rawCurrentLoadIrq: _current_cpu.rawCurrentLoadIrq,
2166
+ rawCurrentLoadSteal: _current_cpu.rawCurrentLoadSteal,
2167
+ rawCurrentLoadGuest: _current_cpu.rawCurrentLoadGuest,
2168
+ cpus: cores
2169
+ };
2170
+ }
2171
+ resolve(result);
2172
+ });
2173
+ });
2174
+ }
2175
+
2176
+ function currentLoad(callback) {
2177
+ return new Promise((resolve) => {
2178
+ process.nextTick(() => {
2179
+ getLoad().then((result) => {
2180
+ if (callback) {
2181
+ callback(result);
2182
+ }
2183
+ resolve(result);
2184
+ });
2185
+ });
2186
+ });
2187
+ }
2188
+
2189
+ exports.currentLoad = currentLoad;
2190
+
2191
+ // --------------------------
2192
+ // PS - full load
2193
+ // since bootup
2194
+
2195
+ function getFullLoad() {
2196
+ return new Promise((resolve) => {
2197
+ process.nextTick(() => {
2198
+ const cpus = os.cpus();
2199
+ let totalUser = 0;
2200
+ let totalSystem = 0;
2201
+ let totalNice = 0;
2202
+ let totalIrq = 0;
2203
+ let totalIdle = 0;
2204
+
2205
+ let result = 0;
2206
+
2207
+ if (cpus && cpus.length) {
2208
+ for (let i = 0, len = cpus.length; i < len; i++) {
2209
+ const cpu = cpus[i].times;
2210
+ totalUser += cpu.user;
2211
+ totalSystem += cpu.sys;
2212
+ totalNice += cpu.nice;
2213
+ totalIrq += cpu.irq;
2214
+ totalIdle += cpu.idle;
2215
+ }
2216
+ const totalTicks = totalIdle + totalIrq + totalNice + totalSystem + totalUser;
2217
+ result = ((totalTicks - totalIdle) / totalTicks) * 100.0;
2218
+ }
2219
+ resolve(result);
2220
+ });
2221
+ });
2222
+ }
2223
+
2224
+ function fullLoad(callback) {
2225
+ return new Promise((resolve) => {
2226
+ process.nextTick(() => {
2227
+ getFullLoad().then((result) => {
2228
+ if (callback) {
2229
+ callback(result);
2230
+ }
2231
+ resolve(result);
2232
+ });
2233
+ });
2234
+ });
2235
+ }
2236
+
2237
+ exports.fullLoad = fullLoad;