linux_stat 2.1.1 → 2.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7af04643c6d2b3886048d2f8e454b6aaea3646a7aca28e46af44bb67e8ecb3f
4
- data.tar.gz: fba61371d7ab4169e6c187a81bba56c8016d848afea9b2c6d5a8b2ffd30fb9bb
3
+ metadata.gz: da63a14786b35b2eb286dfe55a0466d58f287b34e22d8b87213fe0e0549e7142
4
+ data.tar.gz: d184a4fb326d78d8cc375cd651b2a490963121bd3c260d3979c774744e7f35b1
5
5
  SHA512:
6
- metadata.gz: 33272ae30466df860dd3330cdbac62031a9f1022f6854577c83330705cb2ec5c3b2864cac88d1e5823c2d756e1866496fef01e3ef77f26e8e82dd71d14a7ad1a
7
- data.tar.gz: 1004e9136ce2b252a7c4ce2f408dcaa4558dd1d4219edc61a049ead3456ab571a7b17058663462136858372659855b894c578c15f0099d84ae2a99ed8d30824e
6
+ metadata.gz: fbeaa968b47d24698e6d21a141a07ab014673b1d6a34798ed2e1a1b3ab2d9152860b8ee53b057409345592c13ac725648448fb4fe540d3225ac67a832ef6ee09
7
+ data.tar.gz: 84a7153078308c22bcad3681c15b5fbb7e9fee9ae873379e190cae23287fd4adea5bc319c31395ae87e6e8d155fae5c66826c6db6736c9838071c5156e2b56d9
@@ -283,7 +283,7 @@ module LinuxStat
283
283
  uptime = LS::ProcFS.uptime_f
284
284
  return {} unless uptime && !stat.empty?
285
285
 
286
- utime, stime, starttime = *stat.values_at(11, 12, 19).map(&:to_f)
286
+ utime, stime, starttime = *stat.values_at(10, 11, 18).map(&:to_f)
287
287
  uptime *= ticks
288
288
 
289
289
  total_time = utime + stime
@@ -295,14 +295,14 @@ module LinuxStat
295
295
  uptime = LS::ProcFS.uptime_f
296
296
  return {} unless uptime && !stat.empty?
297
297
 
298
- utime2, stime2, starttime2 = *stat.values_at(11, 12, 19).map(&:to_f)
298
+ utime2, stime2, starttime2 = *stat.values_at(10, 11, 18).map(&:to_f)
299
299
  uptime *= ticks
300
300
 
301
301
  total_time2 = utime2 + stime2
302
302
  idle2 = uptime - starttime2 - total_time2
303
303
 
304
304
  totald = idle2.+(total_time2).-(idle1 + total_time)
305
- cpu_u = totald.-(idle2 - idle1).fdiv(totald).abs.*(100)./(cpu_count)
305
+ cpu_u = totald.-(idle2 - idle1).fdiv(totald).abs.*(100)./(LinuxStat::CPU.count)
306
306
 
307
307
  {
308
308
  cpu_usage: cpu_u > 100 ? 100.0 : cpu_u.round(2),
@@ -338,32 +338,10 @@ module LinuxStat
338
338
  #
339
339
  # This method is more efficient than running LinuxStat::ProcessInfo.cpu_stat()
340
340
  def cpu_usage(pid: $$, sleep: ticks_to_ms_t5)
341
- ticks = get_ticks
342
- stat = LinuxStat::ProcFS.ps_stat(pid)
343
- uptime = LS::ProcFS.uptime_f
344
- return nil unless uptime && !stat.empty?
345
-
346
- utime, stime, starttime = *stat.values_at(10, 11, 18).map(&:to_f)
347
- uptime *= ticks
348
-
349
- total_time = utime + stime
350
- idle1 = uptime - starttime - total_time
351
-
352
- sleep(sleep)
353
-
354
- stat = LinuxStat::ProcFS.ps_stat(pid)
355
- uptime = LS::ProcFS.uptime_f
356
- return nil unless uptime && !stat.empty?
357
-
358
- utime2, stime2, starttime2 = *stat.values_at(10, 11, 18).map(&:to_f)
359
- uptime *= ticks
360
-
361
- total_time2 = utime2 + stime2
362
- idle2 = uptime - starttime2 - total_time2
341
+ u = cpu_usage_thread(pid, sleep)
342
+ return nil unless u
363
343
 
364
- totald = idle2.+(total_time2).-(idle1 + total_time)
365
-
366
- u = totald.-(idle2 - idle1).fdiv(totald).abs.*(100)./(cpu_count)
344
+ u /= LinuxStat::CPU.count
367
345
  u > 100 ? 100.0 : u.round(2)
368
346
  end
369
347
 
@@ -390,34 +368,10 @@ module LinuxStat
390
368
  #
391
369
  # But if the info isn't available, it will return nil.
392
370
  def thread_usage(pid: $$, sleep: ticks_to_ms_t5)
393
- ticks = get_ticks
394
- stat = LinuxStat::ProcFS.ps_stat(pid)
395
- uptime = LS::ProcFS.uptime_f
396
- return nil unless uptime && !stat.empty?
397
-
398
- utime, stime, starttime = *stat.values_at(10, 11, 18).map(&:to_f)
399
- uptime *= ticks
400
-
401
- total_time = utime + stime
402
- idle1 = uptime - starttime - total_time
403
-
404
- sleep(sleep)
371
+ u = cpu_usage_thread(pid, sleep)
372
+ return nil unless u
405
373
 
406
- stat = LinuxStat::ProcFS.ps_stat(pid)
407
- uptime = LS::ProcFS.uptime_f
408
- return nil unless uptime && !stat.empty?
409
-
410
- utime2, stime2, starttime2 = *stat.values_at(10, 11, 18).map(&:to_f)
411
- uptime *= ticks
412
-
413
- total_time2 = utime2 + stime2
414
- idle2 = uptime - starttime2 - total_time2
415
-
416
- totald = idle2.+(total_time2).-(idle1 + total_time)
417
-
418
- u = totald.-(idle2 - idle1).fdiv(totald).abs.*(100)
419
-
420
- cpu_count_t100 = cpu_count * 100
374
+ cpu_count_t100 = LinuxStat::CPU.count * 100
421
375
  u > cpu_count_t100 ? cpu_count_t100 : u.round(2)
422
376
  end
423
377
 
@@ -709,8 +663,33 @@ module LinuxStat
709
663
  @@pagesize ||= LinuxStat::Sysconf.pagesize.to_i
710
664
  end
711
665
 
712
- def cpu_count
713
- @@nprocessors_conf ||= LinuxStat::CPU.count
666
+ def cpu_usage_thread(pid, delay)
667
+ ticks = get_ticks
668
+ stat = LinuxStat::ProcFS.ps_stat(pid)
669
+ uptime = LS::ProcFS.uptime_f
670
+ return nil unless uptime && !stat.empty?
671
+
672
+ utime, stime, starttime = *stat.values_at(10, 11, 18).map(&:to_f)
673
+ uptime *= ticks
674
+
675
+ total_time = utime + stime
676
+ idle1 = uptime - starttime - total_time
677
+
678
+ sleep(delay)
679
+
680
+ stat = LinuxStat::ProcFS.ps_stat(pid)
681
+ uptime = LS::ProcFS.uptime_f
682
+ return nil unless uptime && !stat.empty?
683
+
684
+ utime2, stime2, starttime2 = *stat.values_at(10, 11, 18).map(&:to_f)
685
+ uptime *= ticks
686
+
687
+ total_time2 = utime2 + stime2
688
+ idle2 = uptime - starttime2 - total_time2
689
+
690
+ totald = idle2.+(total_time2).-(idle1 + total_time)
691
+
692
+ totald.-(idle2 - idle1).fdiv(totald).abs.*(100)
714
693
  end
715
694
  end
716
695
  end
@@ -1,3 +1,3 @@
1
1
  module LinuxStat
2
- VERSION ||= "2.1.1"
2
+ VERSION ||= "2.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linux_stat
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sourav Goswami
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-05 00:00:00.000000000 Z
11
+ date: 2021-02-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Linux only, efficient linux system utilization reporting and system monitoring
14
14
  gem
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  requirements: []
88
- rubygems_version: 3.1.4
88
+ rubygems_version: 3.2.7
89
89
  signing_key:
90
90
  specification_version: 4
91
91
  summary: Efficient linux system reporting gem