csigar 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -0
- data/Rakefile +2 -2
- data/bindings/SigarWrapper.pm +47 -0
- data/include/sigar.h +41 -0
- data/include/sigar_private.h +7 -2
- data/include/sigar_util.h +6 -0
- data/src/os/aix/aix_sigar.c +17 -0
- data/src/os/darwin/darwin_sigar.c +19 -7
- data/src/os/hpux/hpux_sigar.c +19 -0
- data/src/os/linux/linux_sigar.c +28 -0
- data/src/os/solaris/solaris_sigar.c +16 -1
- data/src/os/win32/sigar_os.h +2 -0
- data/src/os/win32/win32_sigar.c +50 -6
- data/src/sigar.c +131 -115
- data/src/sigar_cache.c +81 -7
- data/src/sigar_ptql.c +9 -0
- metadata +3 -3
- data/README +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7804b5c687d2dd767a30b7d92f9b886128ea4e83
|
4
|
+
data.tar.gz: 9b25e12b9dcca3aec625a74284862014d56d555e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a48cae74e0750521cfa494452e78c6ec396b6a1fc9b9fdfe6564acb60ef116da0a5f5997d400ecbb23d53ccd8281eb9280708ec016c6ba7fd98811b11ed8620
|
7
|
+
data.tar.gz: 456d3736f2d986eb66afce6bbe08b1aea1bb44de46e2d30b8fbed1c67fdf495b18b4438d8a4144f7b8f5f6a25c18e440575659a2ab3b9264e47c654465898c0a
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Instructions
|
2
|
+
## Creating gem file
|
3
|
+
`rake package`
|
4
|
+
|
5
|
+
Creates a gem file in pkg/csigar-0.x.x.gem.
|
6
|
+
|
7
|
+
## Installing gem file
|
8
|
+
`gem install pkg/csigar-x.x.x.gem`
|
9
|
+
|
10
|
+
Installs gem file to local ruby libs.
|
11
|
+
|
12
|
+
## Publishing gem file
|
13
|
+
`gem push pkg/csigar-x.x.x.gem`
|
14
|
+
|
15
|
+
Pushes gem file to rubygems.org (account required).
|
16
|
+
|
17
|
+
## Test using irb
|
18
|
+
Start interactive ruby shell:
|
19
|
+
`#>irb`
|
20
|
+
Require module (must return "true"):
|
21
|
+
`require 'csigar'`
|
22
|
+
Build instance:
|
23
|
+
`sigar = Csigar.new`
|
24
|
+
Get test value (should return numeric value):
|
25
|
+
`sigar.cpu_perc.wait`
|
26
|
+
|
27
|
+
|
28
|
+
# Docs
|
29
|
+
|
30
|
+
Visit the SIGAR Wiki for documentation, bugs, support, etc.:
|
31
|
+
http://sigar.hyperic.com/
|
32
|
+
|
33
|
+
2014-10-28
|
34
|
+
Patched version of hyperic/sigar by jgottschlich@cloudscale.de
|
35
|
+
- added cpu_perc_metric to ruby bindings
|
36
|
+
- fixed Rakefile to use Gem::PackageTask instead of deprecated package
|
37
|
+
- changed version number to 0.7.3
|
38
|
+
|
39
|
+
|
data/Rakefile
CHANGED
@@ -22,7 +22,7 @@ spec = Gem::Specification.new do |s|
|
|
22
22
|
s.name = GEM
|
23
23
|
# s.version = props['version.major'] + '.' + props['version.minor'] + '.' + props['version.maint']
|
24
24
|
# '0.7.x' until the sigar-1.7.0 release
|
25
|
-
s.version = '0' + '.' + props['version.minor'] + '.' + '
|
25
|
+
s.version = '0' + '.' + props['version.minor'] + '.' + '4'
|
26
26
|
s.summary = props['project.summary']
|
27
27
|
s.description = s.summary
|
28
28
|
s.author = props['project.author']
|
@@ -32,7 +32,7 @@ spec = Gem::Specification.new do |s|
|
|
32
32
|
s.has_rdoc = false
|
33
33
|
s.extensions = 'bindings/ruby/extconf.rb'
|
34
34
|
s.files =
|
35
|
-
%w(LICENSE NOTICE README Rakefile version.properties) +
|
35
|
+
%w(LICENSE NOTICE README.md Rakefile version.properties) +
|
36
36
|
%w(bindings/SigarWrapper.pm bindings/SigarBuild.pm) +
|
37
37
|
`git ls-files -- bindings/ruby/*`.split("\n") +
|
38
38
|
Dir.glob("include/*.h") +
|
data/bindings/SigarWrapper.pm
CHANGED
@@ -43,6 +43,7 @@ my %has_name_arg = map { $_, 1 } qw(FileSystemUsage DiskUsage
|
|
43
43
|
FileAttrs DirStat DirUsage
|
44
44
|
NetInterfaceConfig NetInterfaceStat);
|
45
45
|
|
46
|
+
|
46
47
|
my %proc_no_arg = map { $_, 1 } qw(stat);
|
47
48
|
|
48
49
|
my %get_not_impl = map { $_, 1 } qw(net_address net_route net_connection net_stat cpu_perc
|
@@ -527,6 +528,7 @@ use vars qw(%classes %cmds);
|
|
527
528
|
plat => '*'
|
528
529
|
},
|
529
530
|
],
|
531
|
+
|
530
532
|
ProcMem => [
|
531
533
|
{
|
532
534
|
name => 'size', type => 'Long',
|
@@ -627,6 +629,51 @@ use vars qw(%classes %cmds);
|
|
627
629
|
plat => '*'
|
628
630
|
},
|
629
631
|
],
|
632
|
+
ProcDiskIO => [
|
633
|
+
{
|
634
|
+
name => 'bytes_read', type => 'Long',
|
635
|
+
desc => 'Bytes Read',
|
636
|
+
plat => 'LW'
|
637
|
+
},
|
638
|
+
{
|
639
|
+
name => 'bytes_written', type => 'Long',
|
640
|
+
desc => 'Bytes Written',
|
641
|
+
plat => 'LW'
|
642
|
+
},
|
643
|
+
{
|
644
|
+
name => 'bytes_total', type => 'Long',
|
645
|
+
desc => 'Bytes Total',
|
646
|
+
plat => 'LWAHS'
|
647
|
+
}
|
648
|
+
],
|
649
|
+
|
650
|
+
ProcCumulativeDiskIO => [
|
651
|
+
{
|
652
|
+
name => 'bytes_read', type => 'Long',
|
653
|
+
desc => 'Bytes Read from Start',
|
654
|
+
plat => 'LW'
|
655
|
+
},
|
656
|
+
{
|
657
|
+
name => 'bytes_written', type => 'Long',
|
658
|
+
desc => 'Bytes Written from Start',
|
659
|
+
plat => 'LW'
|
660
|
+
},
|
661
|
+
{
|
662
|
+
name => 'bytes_total', type => 'Long',
|
663
|
+
desc => 'Bytes Total from Start',
|
664
|
+
plat => 'LWAHS'
|
665
|
+
}
|
666
|
+
],
|
667
|
+
|
668
|
+
DumpPidCache => [
|
669
|
+
{
|
670
|
+
name => 'dummy', type => 'Long',
|
671
|
+
desc => 'Dummy',
|
672
|
+
plat => 'LWAHS'
|
673
|
+
}
|
674
|
+
],
|
675
|
+
|
676
|
+
|
630
677
|
ProcState => [
|
631
678
|
{
|
632
679
|
name => 'state', type => 'Char',
|
data/include/sigar.h
CHANGED
@@ -292,6 +292,47 @@ typedef struct {
|
|
292
292
|
SIGAR_DECLARE(int) sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
|
293
293
|
sigar_proc_mem_t *procmem);
|
294
294
|
|
295
|
+
typedef struct {
|
296
|
+
sigar_uint64_t
|
297
|
+
bytes_read,
|
298
|
+
bytes_written,
|
299
|
+
bytes_total;
|
300
|
+
} sigar_proc_disk_io_t;
|
301
|
+
|
302
|
+
SIGAR_DECLARE(int) sigar_proc_disk_io_get(sigar_t *sigar, sigar_pid_t pid,
|
303
|
+
sigar_proc_disk_io_t *proc_disk_io);
|
304
|
+
|
305
|
+
typedef struct {
|
306
|
+
sigar_uint64_t
|
307
|
+
bytes_read,
|
308
|
+
bytes_written,
|
309
|
+
bytes_total;
|
310
|
+
sigar_uint64_t last_time;
|
311
|
+
sigar_uint64_t
|
312
|
+
bytes_read_diff,
|
313
|
+
bytes_written_diff,
|
314
|
+
bytes_total_diff;
|
315
|
+
} sigar_cached_proc_disk_io_t;
|
316
|
+
|
317
|
+
|
318
|
+
typedef struct {
|
319
|
+
sigar_uint64_t
|
320
|
+
bytes_read,
|
321
|
+
bytes_written,
|
322
|
+
bytes_total;
|
323
|
+
} sigar_proc_cumulative_disk_io_t;
|
324
|
+
|
325
|
+
SIGAR_DECLARE(int) sigar_proc_cumulative_disk_io_get(sigar_t *sigar, sigar_pid_t pid,
|
326
|
+
sigar_proc_cumulative_disk_io_t *proc_cumulative_disk_io);
|
327
|
+
|
328
|
+
|
329
|
+
typedef struct {
|
330
|
+
sigar_uint64_t dummy;
|
331
|
+
}sigar_dump_pid_cache_t;
|
332
|
+
|
333
|
+
SIGAR_DECLARE(int) sigar_dump_pid_cache_get(sigar_t *sigar, sigar_dump_pid_cache_t *info);
|
334
|
+
|
335
|
+
|
295
336
|
typedef struct {
|
296
337
|
sigar_uid_t uid;
|
297
338
|
sigar_gid_t gid;
|
data/include/sigar_private.h
CHANGED
@@ -68,7 +68,8 @@
|
|
68
68
|
sigar_cache_t *proc_cpu; \
|
69
69
|
sigar_cache_t *net_listen; \
|
70
70
|
sigar_cache_t *net_services_tcp; \
|
71
|
-
sigar_cache_t *net_services_udp
|
71
|
+
sigar_cache_t *net_services_udp;\
|
72
|
+
sigar_cache_t *proc_io
|
72
73
|
|
73
74
|
#if defined(WIN32)
|
74
75
|
# define SIGAR_INLINE __inline
|
@@ -398,11 +399,15 @@ int sigar_get_iftype(const char *name, int *type, int *inst);
|
|
398
399
|
#define SIGAR_NIC_SIT "IPv6-in-IPv4"
|
399
400
|
#define SIGAR_NIC_IRDA "IrLAP"
|
400
401
|
#define SIGAR_NIC_EC "Econet"
|
401
|
-
|
402
|
+
#define PID_CACHE_CLEANUP_PERIOD 1000*60*10 /* 10 minutes */
|
403
|
+
#define PID_CACHE_ENTRY_EXPIRE_PERIOD 1000*60*20 /* 20 minutes */
|
402
404
|
#ifndef WIN32
|
403
405
|
#include <netdb.h>
|
404
406
|
#endif
|
405
407
|
|
408
|
+
#define PROC_PID_CPU_CACHE 1
|
409
|
+
#define PROC_PID_IO_CACHE 2
|
410
|
+
|
406
411
|
#define SIGAR_HOSTENT_LEN 1024
|
407
412
|
#if defined(_AIX)
|
408
413
|
#define SIGAR_HAS_HOSTENT_DATA
|
data/include/sigar_util.h
CHANGED
@@ -170,15 +170,21 @@ struct sigar_cache_entry_t {
|
|
170
170
|
sigar_cache_entry_t *next;
|
171
171
|
sigar_uint64_t id;
|
172
172
|
void *value;
|
173
|
+
sigar_uint64_t last_access_time;
|
173
174
|
};
|
174
175
|
|
175
176
|
typedef struct {
|
176
177
|
sigar_cache_entry_t **entries;
|
177
178
|
unsigned int count, size;
|
178
179
|
void (*free_value)(void *ptr);
|
180
|
+
sigar_uint64_t entry_expire_period;
|
181
|
+
sigar_uint64_t cleanup_period_millis;
|
182
|
+
sigar_uint64_t last_cleanup_time;
|
179
183
|
} sigar_cache_t;
|
180
184
|
|
181
185
|
sigar_cache_t *sigar_cache_new(int size);
|
186
|
+
sigar_cache_t *sigar_expired_cache_new(int size, sigar_uint64_t cleanup_period_millis, sigar_uint64_t entry_expire_period);
|
187
|
+
void sigar_cache_dump(sigar_cache_t *table);
|
182
188
|
|
183
189
|
sigar_cache_entry_t *sigar_cache_get(sigar_cache_t *table,
|
184
190
|
sigar_uint64_t key);
|
data/src/os/aix/aix_sigar.c
CHANGED
@@ -754,6 +754,23 @@ int sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
|
|
754
754
|
return SIGAR_OK;
|
755
755
|
}
|
756
756
|
|
757
|
+
int sigar_proc_cumulative_disk_io_get(sigar_t *sigar, sigar_pid_t pid,
|
758
|
+
sigar_proc_cumulative_disk_io_t *cumulative_proc_disk_io)
|
759
|
+
{
|
760
|
+
int status = sigar_getprocs(sigar, pid);
|
761
|
+
struct procsinfo64 *pinfo = sigar->pinfo;
|
762
|
+
|
763
|
+
if (status != SIGAR_OK) {
|
764
|
+
return status;
|
765
|
+
}
|
766
|
+
cumulative_proc_disk_io->bytes_read = SIGAR_FIELD_NOTIMPL;
|
767
|
+
cumulative_proc_disk_io->bytes_written = SIGAR_FIELD_NOTIMPL;
|
768
|
+
cumulative_proc_disk_io->bytes_total = pinfo->pi_ioch;
|
769
|
+
|
770
|
+
return SIGAR_OK;
|
771
|
+
}
|
772
|
+
|
773
|
+
|
757
774
|
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
|
758
775
|
sigar_proc_cred_t *proccred)
|
759
776
|
{
|
@@ -16,6 +16,17 @@
|
|
16
16
|
* limitations under the License.
|
17
17
|
*/
|
18
18
|
|
19
|
+
#ifdef DARWIN
|
20
|
+
#include <sys/socket.h>
|
21
|
+
#include <sys/fcntl.h>
|
22
|
+
#include <mach/thread_info.h>
|
23
|
+
#endif
|
24
|
+
|
25
|
+
#include "sigar.h"
|
26
|
+
#include "sigar_private.h"
|
27
|
+
#include "sigar_util.h"
|
28
|
+
#include "sigar_os.h"
|
29
|
+
|
19
30
|
#include <sys/param.h>
|
20
31
|
#include <sys/mount.h>
|
21
32
|
#if !(defined(__FreeBSD__) && (__FreeBSD_version >= 800000))
|
@@ -33,7 +44,6 @@
|
|
33
44
|
#include <mach/mach_port.h>
|
34
45
|
#include <mach/task.h>
|
35
46
|
#include <mach/thread_act.h>
|
36
|
-
#include <mach/thread_info.h>
|
37
47
|
#include <mach/vm_map.h>
|
38
48
|
#if !defined(HAVE_SHARED_REGION_H) && defined(__MAC_10_5) /* see Availability.h */
|
39
49
|
# define HAVE_SHARED_REGION_H /* suckit autoconf */
|
@@ -107,11 +117,6 @@
|
|
107
117
|
#include <netinet/tcp_var.h>
|
108
118
|
#include <netinet/tcp_fsm.h>
|
109
119
|
|
110
|
-
#include "sigar.h"
|
111
|
-
#include "sigar_private.h"
|
112
|
-
#include "sigar_util.h"
|
113
|
-
#include "sigar_os.h"
|
114
|
-
|
115
120
|
#define NMIB(mib) (sizeof(mib)/sizeof(mib[0]))
|
116
121
|
|
117
122
|
#ifdef __FreeBSD__
|
@@ -1241,6 +1246,13 @@ int sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
|
|
1241
1246
|
return SIGAR_OK;
|
1242
1247
|
}
|
1243
1248
|
|
1249
|
+
int sigar_proc_cumulative_disk_io_get(sigar_t *sigar, sigar_pid_t pid,
|
1250
|
+
sigar_proc_cumulative_disk_io_t *proc_cumulative_disk_io)
|
1251
|
+
{
|
1252
|
+
return SIGAR_ENOTIMPL;
|
1253
|
+
}
|
1254
|
+
|
1255
|
+
|
1244
1256
|
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
|
1245
1257
|
sigar_proc_cred_t *proccred)
|
1246
1258
|
{
|
@@ -3708,4 +3720,4 @@ int sigar_os_sys_info_get(sigar_t *sigar,
|
|
3708
3720
|
#endif
|
3709
3721
|
|
3710
3722
|
return SIGAR_OK;
|
3711
|
-
}
|
3723
|
+
}
|
data/src/os/hpux/hpux_sigar.c
CHANGED
@@ -307,6 +307,25 @@ int sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
|
|
307
307
|
return SIGAR_OK;
|
308
308
|
}
|
309
309
|
|
310
|
+
int sigar_proc_cumulative_disk_io_get(sigar_t *sigar, sigar_pid_t pid,
|
311
|
+
sigar_proc_cumulative_disk_io_t *proc_cumulative_disk_io)
|
312
|
+
{
|
313
|
+
|
314
|
+
int status = sigar_pstat_getproc(sigar, pid);
|
315
|
+
struct pst_status *pinfo = sigar->pinfo;
|
316
|
+
|
317
|
+
if (status != SIGAR_OK) {
|
318
|
+
return status;
|
319
|
+
}
|
320
|
+
proc_cumulative_disk_io->bytes_read = SIGAR_FIELD_NOTIMPL;
|
321
|
+
proc_cumulative_disk_io->bytes_written = SIGAR_FIELD_NOTIMPL;
|
322
|
+
proc_cumulative_disk_io->bytes_total = pinfo->pst_ioch;
|
323
|
+
|
324
|
+
|
325
|
+
return SIGAR_OK;
|
326
|
+
}
|
327
|
+
|
328
|
+
|
310
329
|
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
|
311
330
|
sigar_proc_cred_t *proccred)
|
312
331
|
{
|
data/src/os/linux/linux_sigar.c
CHANGED
@@ -768,6 +768,34 @@ int sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
|
|
768
768
|
return SIGAR_OK;
|
769
769
|
}
|
770
770
|
|
771
|
+
SIGAR_INLINE sigar_uint64_t get_named_proc_token(char *buffer,
|
772
|
+
char *token) {
|
773
|
+
char *ptr = strstr(buffer, token);
|
774
|
+
if (!ptr) {
|
775
|
+
return SIGAR_FIELD_NOTIMPL;
|
776
|
+
}
|
777
|
+
ptr = sigar_skip_token(ptr);
|
778
|
+
return sigar_strtoul(ptr);
|
779
|
+
}
|
780
|
+
|
781
|
+
int sigar_proc_cumulative_disk_io_get(sigar_t *sigar, sigar_pid_t pid,
|
782
|
+
sigar_proc_cumulative_disk_io_t *proc_cumulative_disk_io)
|
783
|
+
{
|
784
|
+
char buffer[BUFSIZ];
|
785
|
+
|
786
|
+
int status = SIGAR_PROC_FILE2STR(buffer, pid, "/io");
|
787
|
+
|
788
|
+
if (status != SIGAR_OK) {
|
789
|
+
return status;
|
790
|
+
}
|
791
|
+
|
792
|
+
proc_cumulative_disk_io->bytes_read = get_named_proc_token(buffer, "\nread_bytes");
|
793
|
+
proc_cumulative_disk_io->bytes_written = get_named_proc_token(buffer, "\nwrite_bytes");
|
794
|
+
proc_cumulative_disk_io->bytes_total = proc_cumulative_disk_io->bytes_read + proc_cumulative_disk_io->bytes_written;
|
795
|
+
|
796
|
+
return SIGAR_OK;
|
797
|
+
}
|
798
|
+
|
771
799
|
#define NO_ID_MSG "[proc_cred] /proc/%lu" PROC_PSTATUS " missing "
|
772
800
|
|
773
801
|
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
|
@@ -407,7 +407,7 @@ int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu)
|
|
407
407
|
cpu->idle += xcpu->idle;
|
408
408
|
cpu->nice += xcpu->nice;
|
409
409
|
cpu->wait += xcpu->wait;
|
410
|
-
cpu->total
|
410
|
+
cpu->total += xcpu->total;
|
411
411
|
}
|
412
412
|
|
413
413
|
return SIGAR_OK;
|
@@ -719,6 +719,21 @@ int sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
|
|
719
719
|
return SIGAR_OK;
|
720
720
|
}
|
721
721
|
|
722
|
+
int sigar_proc_cumulative_disk_io_get(sigar_t *sigar, sigar_pid_t pid,
|
723
|
+
sigar_proc_cumulative_disk_io_t *proc_cumulative_disk_io)
|
724
|
+
{
|
725
|
+
prusage_t usage;
|
726
|
+
int status;
|
727
|
+
if ((status = sigar_proc_usage_get(sigar, &usage, pid)) != SIGAR_OK) {
|
728
|
+
return status;
|
729
|
+
}
|
730
|
+
proc_cumulative_disk_io->bytes_read = SIGAR_FIELD_NOTIMPL;
|
731
|
+
proc_cumulative_disk_io->bytes_written = SIGAR_FIELD_NOTIMPL;
|
732
|
+
proc_cumulative_disk_io->bytes_total = usage.pr_ioch;
|
733
|
+
|
734
|
+
return SIGAR_OK;
|
735
|
+
}
|
736
|
+
|
722
737
|
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
|
723
738
|
sigar_proc_cred_t *proccred)
|
724
739
|
{
|
data/src/os/win32/sigar_os.h
CHANGED
data/src/os/win32/win32_sigar.c
CHANGED
@@ -62,6 +62,8 @@ typedef enum {
|
|
62
62
|
#define PERF_TITLE_PPID 1410
|
63
63
|
#define PERF_TITLE_PRIORITY 682
|
64
64
|
#define PERF_TITLE_START_TIME 684
|
65
|
+
#define PERF_TITLE_IO_READ_BYTES_SEC 1420
|
66
|
+
#define PERF_TITLE_IO_WRITE_BYTES_SEC 1422
|
65
67
|
|
66
68
|
typedef enum {
|
67
69
|
PERF_IX_CPUTIME,
|
@@ -74,6 +76,8 @@ typedef enum {
|
|
74
76
|
PERF_IX_PPID,
|
75
77
|
PERF_IX_PRIORITY,
|
76
78
|
PERF_IX_START_TIME,
|
79
|
+
PERF_IX_IO_READ_BYTES_SEC,
|
80
|
+
PERF_IX_IO_WRITE_BYTES_SEC,
|
77
81
|
PERF_IX_MAX
|
78
82
|
} perf_proc_offsets_t;
|
79
83
|
|
@@ -1210,6 +1214,23 @@ SIGAR_DECLARE(int) sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
|
|
1210
1214
|
return SIGAR_OK;
|
1211
1215
|
}
|
1212
1216
|
|
1217
|
+
SIGAR_DECLARE(int) sigar_proc_cumulative_disk_io_get(sigar_t *sigar, sigar_pid_t pid,
|
1218
|
+
sigar_proc_cumulative_disk_io_t *proc_cumulative_disk_io)
|
1219
|
+
{
|
1220
|
+
int status = get_proc_info(sigar, pid);
|
1221
|
+
sigar_win32_pinfo_t *pinfo = &sigar->pinfo;
|
1222
|
+
|
1223
|
+
if (status != SIGAR_OK) {
|
1224
|
+
return status;
|
1225
|
+
}
|
1226
|
+
|
1227
|
+
proc_cumulative_disk_io->bytes_read = pinfo->bytes_read;
|
1228
|
+
proc_cumulative_disk_io->bytes_written = pinfo->bytes_written;
|
1229
|
+
proc_cumulative_disk_io->bytes_total = proc_cumulative_disk_io->bytes_read + proc_cumulative_disk_io->bytes_written;
|
1230
|
+
|
1231
|
+
return SIGAR_OK;
|
1232
|
+
}
|
1233
|
+
|
1213
1234
|
#define TOKEN_DAC (STANDARD_RIGHTS_READ | READ_CONTROL | TOKEN_QUERY)
|
1214
1235
|
|
1215
1236
|
SIGAR_DECLARE(int)
|
@@ -1441,6 +1462,12 @@ static int get_proc_info(sigar_t *sigar, sigar_pid_t pid)
|
|
1441
1462
|
case PERF_TITLE_START_TIME:
|
1442
1463
|
perf_offsets[PERF_IX_START_TIME] = offset;
|
1443
1464
|
break;
|
1465
|
+
case PERF_TITLE_IO_READ_BYTES_SEC:
|
1466
|
+
perf_offsets[PERF_IX_IO_READ_BYTES_SEC] = offset;
|
1467
|
+
break;
|
1468
|
+
case PERF_TITLE_IO_WRITE_BYTES_SEC:
|
1469
|
+
perf_offsets[PERF_IX_IO_WRITE_BYTES_SEC] = offset;
|
1470
|
+
break;
|
1444
1471
|
}
|
1445
1472
|
}
|
1446
1473
|
|
@@ -1466,6 +1493,8 @@ static int get_proc_info(sigar_t *sigar, sigar_pid_t pid)
|
|
1466
1493
|
pinfo->handles = PERF_VAL(PERF_IX_HANDLE_CNT);
|
1467
1494
|
pinfo->threads = PERF_VAL(PERF_IX_THREAD_CNT);
|
1468
1495
|
pinfo->page_faults = PERF_VAL(PERF_IX_PAGE_FAULTS);
|
1496
|
+
pinfo->bytes_read = PERF_VAL(PERF_IX_IO_READ_BYTES_SEC);
|
1497
|
+
pinfo->bytes_written = PERF_VAL(PERF_IX_IO_WRITE_BYTES_SEC);
|
1469
1498
|
|
1470
1499
|
return SIGAR_OK;
|
1471
1500
|
}
|
@@ -3693,6 +3722,7 @@ int sigar_who_list_get_win32(sigar_t *sigar,
|
|
3693
3722
|
#define SIGAR_ARCH "x86"
|
3694
3723
|
#endif
|
3695
3724
|
|
3725
|
+
|
3696
3726
|
int sigar_os_sys_info_get(sigar_t *sigar,
|
3697
3727
|
sigar_sys_info_t *sysinfo)
|
3698
3728
|
{
|
@@ -3700,7 +3730,7 @@ int sigar_os_sys_info_get(sigar_t *sigar,
|
|
3700
3730
|
char *vendor_name, *vendor_version, *code_name=NULL;
|
3701
3731
|
|
3702
3732
|
version.dwOSVersionInfoSize = sizeof(version);
|
3703
|
-
GetVersionEx((OSVERSIONINFO *)&version);
|
3733
|
+
GetVersionEx((OSVERSIONINFO *)&version);
|
3704
3734
|
|
3705
3735
|
if (version.dwMajorVersion == 4) {
|
3706
3736
|
vendor_name = "Windows NT";
|
@@ -3740,11 +3770,25 @@ int sigar_os_sys_info_get(sigar_t *sigar,
|
|
3740
3770
|
code_name = "Vienna";
|
3741
3771
|
}
|
3742
3772
|
}
|
3743
|
-
|
3744
|
-
|
3745
|
-
|
3746
|
-
|
3747
|
-
|
3773
|
+
else {
|
3774
|
+
// not nt work station
|
3775
|
+
if (version.dwMinorVersion == 0 || version.dwMinorVersion ==1) {
|
3776
|
+
vendor_name = "Windows 2008";
|
3777
|
+
vendor_version = "2008";
|
3778
|
+
code_name = "Longhorn Server";
|
3779
|
+
}
|
3780
|
+
else if (version.dwMinorVersion == 2) {
|
3781
|
+
vendor_name = "Windows 2012";
|
3782
|
+
vendor_version = "2012";
|
3783
|
+
code_name = "Windows Server 8";
|
3784
|
+
}
|
3785
|
+
else {
|
3786
|
+
// defaults
|
3787
|
+
vendor_name = "Windows Unknown";
|
3788
|
+
vendor_version = "2012";
|
3789
|
+
}
|
3790
|
+
}
|
3791
|
+
|
3748
3792
|
}
|
3749
3793
|
|
3750
3794
|
SIGAR_SSTRCPY(sysinfo->name, "Win32");
|
data/src/sigar.c
CHANGED
@@ -30,6 +30,11 @@
|
|
30
30
|
#ifndef WIN32
|
31
31
|
#include <arpa/inet.h>
|
32
32
|
#endif
|
33
|
+
#if defined(HAVE_UTMPX_H)
|
34
|
+
# include <utmpx.h>
|
35
|
+
#elif defined(HAVE_UTMP_H)
|
36
|
+
# include <utmp.h>
|
37
|
+
#endif
|
33
38
|
|
34
39
|
#include "sigar.h"
|
35
40
|
#include "sigar_private.h"
|
@@ -59,6 +64,7 @@ SIGAR_DECLARE(int) sigar_open(sigar_t **sigar)
|
|
59
64
|
(*sigar)->net_listen = NULL;
|
60
65
|
(*sigar)->net_services_tcp = NULL;
|
61
66
|
(*sigar)->net_services_udp = NULL;
|
67
|
+
(*sigar)->proc_io = NULL;
|
62
68
|
}
|
63
69
|
|
64
70
|
return status;
|
@@ -91,6 +97,11 @@ SIGAR_DECLARE(int) sigar_close(sigar_t *sigar)
|
|
91
97
|
if (sigar->net_services_udp) {
|
92
98
|
sigar_cache_destroy(sigar->net_services_udp);
|
93
99
|
}
|
100
|
+
if (sigar->proc_io) {
|
101
|
+
sigar_cache_destroy(sigar->proc_io);
|
102
|
+
}
|
103
|
+
|
104
|
+
|
94
105
|
|
95
106
|
return sigar_os_close(sigar);
|
96
107
|
}
|
@@ -118,7 +129,7 @@ SIGAR_DECLARE(int) sigar_proc_cpu_get(sigar_t *sigar, sigar_pid_t pid,
|
|
118
129
|
int status;
|
119
130
|
|
120
131
|
if (!sigar->proc_cpu) {
|
121
|
-
sigar->proc_cpu =
|
132
|
+
sigar->proc_cpu = sigar_expired_cache_new(128, PID_CACHE_CLEANUP_PERIOD, PID_CACHE_ENTRY_EXPIRE_PERIOD);
|
122
133
|
}
|
123
134
|
|
124
135
|
entry = sigar_cache_get(sigar->proc_cpu, pid);
|
@@ -167,6 +178,106 @@ SIGAR_DECLARE(int) sigar_proc_cpu_get(sigar_t *sigar, sigar_pid_t pid,
|
|
167
178
|
|
168
179
|
return SIGAR_OK;
|
169
180
|
}
|
181
|
+
void copy_cached_disk_io_into_disk_io( sigar_cached_proc_disk_io_t *cached, sigar_proc_disk_io_t *proc_disk_io) {
|
182
|
+
proc_disk_io->bytes_read = cached->bytes_read_diff;
|
183
|
+
proc_disk_io->bytes_written = cached->bytes_written_diff;
|
184
|
+
proc_disk_io->bytes_total = cached->bytes_total_diff;
|
185
|
+
}
|
186
|
+
|
187
|
+
sigar_uint64_t get_io_diff(sigar_uint64_t current_value, sigar_uint64_t prev_value, sigar_uint64_t time_diff) {
|
188
|
+
double io_diff;
|
189
|
+
sigar_uint64_t int_io_diff;
|
190
|
+
if ( current_value == SIGAR_FIELD_NOTIMPL ) {
|
191
|
+
return SIGAR_FIELD_NOTIMPL;
|
192
|
+
}
|
193
|
+
io_diff = (( current_value - prev_value)/(double)time_diff)*SIGAR_MSEC;
|
194
|
+
int_io_diff = (sigar_uint64_t)io_diff;
|
195
|
+
if (int_io_diff >=0) {
|
196
|
+
return int_io_diff;
|
197
|
+
}
|
198
|
+
return 0;
|
199
|
+
}
|
200
|
+
|
201
|
+
void calculate_io_diff(sigar_proc_cumulative_disk_io_t * proc_disk_io, sigar_cached_proc_disk_io_t *cached, sigar_uint64_t time_diff, int is_first_time) {
|
202
|
+
/*calculate avg diff /read/write/total per second*/
|
203
|
+
if (!is_first_time) {
|
204
|
+
cached->bytes_written_diff = get_io_diff(proc_disk_io->bytes_written, cached->bytes_written, time_diff);
|
205
|
+
cached->bytes_read_diff = get_io_diff(proc_disk_io->bytes_read, cached->bytes_read, time_diff);
|
206
|
+
cached->bytes_total_diff = get_io_diff(proc_disk_io->bytes_total, cached->bytes_total, time_diff);
|
207
|
+
}
|
208
|
+
else {
|
209
|
+
cached->bytes_total_diff = cached->bytes_read_diff = cached->bytes_written_diff = 0.0;
|
210
|
+
}
|
211
|
+
// now put in cache the current cumulative values
|
212
|
+
cached->bytes_written = proc_disk_io->bytes_written;
|
213
|
+
cached->bytes_read = proc_disk_io->bytes_read;
|
214
|
+
cached->bytes_total = proc_disk_io->bytes_total;
|
215
|
+
}
|
216
|
+
|
217
|
+
SIGAR_DECLARE(int) sigar_proc_disk_io_get(sigar_t *sigar, sigar_pid_t pid,
|
218
|
+
sigar_proc_disk_io_t *proc_disk_io)
|
219
|
+
{
|
220
|
+
sigar_cache_entry_t *entry;
|
221
|
+
sigar_cached_proc_disk_io_t *prev;
|
222
|
+
sigar_proc_cumulative_disk_io_t cumulative_proc_disk_io;
|
223
|
+
sigar_uint64_t time_now = sigar_time_now_millis();
|
224
|
+
sigar_uint64_t time_diff;
|
225
|
+
int status, is_first_time;
|
226
|
+
|
227
|
+
if (!sigar->proc_io) {
|
228
|
+
sigar->proc_io = sigar_expired_cache_new(128, PID_CACHE_CLEANUP_PERIOD, PID_CACHE_ENTRY_EXPIRE_PERIOD);
|
229
|
+
}
|
230
|
+
|
231
|
+
entry = sigar_cache_get(sigar->proc_io, pid);
|
232
|
+
if (entry->value) {
|
233
|
+
prev = (sigar_cached_proc_disk_io_t *)entry->value;
|
234
|
+
}
|
235
|
+
else {
|
236
|
+
prev = entry->value = malloc(sizeof(*prev));
|
237
|
+
SIGAR_ZERO(prev);
|
238
|
+
}
|
239
|
+
is_first_time = (prev->last_time == 0);
|
240
|
+
time_diff = time_now - prev->last_time;
|
241
|
+
|
242
|
+
if (time_diff < 1000) {
|
243
|
+
/* we were just called within < 1 second ago. */
|
244
|
+
copy_cached_disk_io_into_disk_io(prev, proc_disk_io);
|
245
|
+
if (time_diff < 0) {
|
246
|
+
// something is wrong at least from now on the time will be ok
|
247
|
+
prev->last_time = time_now;
|
248
|
+
}
|
249
|
+
return SIGAR_OK;
|
250
|
+
}
|
251
|
+
prev->last_time = time_now;
|
252
|
+
|
253
|
+
|
254
|
+
status =
|
255
|
+
sigar_proc_cumulative_disk_io_get(sigar, pid,
|
256
|
+
&cumulative_proc_disk_io);
|
257
|
+
|
258
|
+
if (status != SIGAR_OK) {
|
259
|
+
return status;
|
260
|
+
}
|
261
|
+
calculate_io_diff(&cumulative_proc_disk_io, prev, time_diff, is_first_time);
|
262
|
+
copy_cached_disk_io_into_disk_io(prev, proc_disk_io);
|
263
|
+
return SIGAR_OK;
|
264
|
+
}
|
265
|
+
|
266
|
+
void get_cache_info(sigar_cache_t * cache, char * name){
|
267
|
+
if (cache == NULL) {
|
268
|
+
return;
|
269
|
+
}
|
270
|
+
|
271
|
+
printf("******** %s *********\n", name);
|
272
|
+
sigar_cache_dump(cache);
|
273
|
+
}
|
274
|
+
|
275
|
+
SIGAR_DECLARE(int) sigar_dump_pid_cache_get(sigar_t *sigar, sigar_dump_pid_cache_t *info) {
|
276
|
+
|
277
|
+
get_cache_info(sigar->proc_cpu, "proc cpu cache");
|
278
|
+
get_cache_info(sigar->proc_io, "proc io cache");
|
279
|
+
return SIGAR_OK;
|
280
|
+
}
|
170
281
|
|
171
282
|
SIGAR_DECLARE(int) sigar_proc_stat_get(sigar_t *sigar,
|
172
283
|
sigar_proc_stat_t *procstat)
|
@@ -1024,40 +1135,7 @@ SIGAR_DECLARE(int) sigar_who_list_destroy(sigar_t *sigar,
|
|
1024
1135
|
return SIGAR_OK;
|
1025
1136
|
}
|
1026
1137
|
|
1027
|
-
#
|
1028
|
-
#include <AvailabilityMacros.h>
|
1029
|
-
#endif
|
1030
|
-
#ifdef MAC_OS_X_VERSION_10_5
|
1031
|
-
# if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
|
1032
|
-
# define SIGAR_NO_UTMP
|
1033
|
-
# endif
|
1034
|
-
/* else 10.4 and earlier or compiled with -mmacosx-version-min=10.3 */
|
1035
|
-
#endif
|
1036
|
-
|
1037
|
-
#if defined(__sun)
|
1038
|
-
# include <utmpx.h>
|
1039
|
-
# define SIGAR_UTMP_FILE _UTMPX_FILE
|
1040
|
-
# define ut_time ut_tv.tv_sec
|
1041
|
-
#elif defined(WIN32)
|
1042
|
-
/* XXX may not be the default */
|
1043
|
-
#define SIGAR_UTMP_FILE "C:\\cygwin\\var\\run\\utmp"
|
1044
|
-
#define UT_LINESIZE 16
|
1045
|
-
#define UT_NAMESIZE 16
|
1046
|
-
#define UT_HOSTSIZE 256
|
1047
|
-
#define UT_IDLEN 2
|
1048
|
-
#define ut_name ut_user
|
1049
|
-
|
1050
|
-
struct utmp {
|
1051
|
-
short ut_type;
|
1052
|
-
int ut_pid;
|
1053
|
-
char ut_line[UT_LINESIZE];
|
1054
|
-
char ut_id[UT_IDLEN];
|
1055
|
-
time_t ut_time;
|
1056
|
-
char ut_user[UT_NAMESIZE];
|
1057
|
-
char ut_host[UT_HOSTSIZE];
|
1058
|
-
long ut_addr;
|
1059
|
-
};
|
1060
|
-
#elif defined(NETWARE)
|
1138
|
+
#if defined(NETWARE)
|
1061
1139
|
static char *getpass(const char *prompt)
|
1062
1140
|
{
|
1063
1141
|
static char password[BUFSIZ];
|
@@ -1067,109 +1145,48 @@ static char *getpass(const char *prompt)
|
|
1067
1145
|
|
1068
1146
|
return (char *)&password;
|
1069
1147
|
}
|
1070
|
-
#elif !defined(SIGAR_NO_UTMP)
|
1071
|
-
# include <utmp.h>
|
1072
|
-
# ifdef UTMP_FILE
|
1073
|
-
# define SIGAR_UTMP_FILE UTMP_FILE
|
1074
|
-
# else
|
1075
|
-
# define SIGAR_UTMP_FILE _PATH_UTMP
|
1076
|
-
# endif
|
1077
|
-
#endif
|
1078
|
-
|
1079
|
-
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(DARWIN)
|
1080
|
-
# define ut_user ut_name
|
1081
|
-
#endif
|
1082
|
-
|
1083
|
-
#ifdef DARWIN
|
1084
|
-
/* XXX from utmpx.h; sizeof changed in 10.5 */
|
1085
|
-
/* additionally, utmpx does not work on 10.4 */
|
1086
|
-
#define SIGAR_HAS_UTMPX
|
1087
|
-
#define _PATH_UTMPX "/var/run/utmpx"
|
1088
|
-
#define _UTX_USERSIZE 256 /* matches MAXLOGNAME */
|
1089
|
-
#define _UTX_LINESIZE 32
|
1090
|
-
#define _UTX_IDSIZE 4
|
1091
|
-
#define _UTX_HOSTSIZE 256
|
1092
|
-
struct utmpx {
|
1093
|
-
char ut_user[_UTX_USERSIZE]; /* login name */
|
1094
|
-
char ut_id[_UTX_IDSIZE]; /* id */
|
1095
|
-
char ut_line[_UTX_LINESIZE]; /* tty name */
|
1096
|
-
pid_t ut_pid; /* process id creating the entry */
|
1097
|
-
short ut_type; /* type of this entry */
|
1098
|
-
struct timeval ut_tv; /* time entry was created */
|
1099
|
-
char ut_host[_UTX_HOSTSIZE]; /* host name */
|
1100
|
-
__uint32_t ut_pad[16]; /* reserved for future use */
|
1101
|
-
};
|
1102
|
-
#define ut_xtime ut_tv.tv_sec
|
1103
|
-
#define UTMPX_USER_PROCESS 7
|
1104
|
-
/* end utmpx.h */
|
1105
|
-
#define SIGAR_UTMPX_FILE _PATH_UTMPX
|
1106
1148
|
#endif
|
1107
1149
|
|
1108
|
-
#if !defined(NETWARE) && !defined(_AIX)
|
1109
|
-
|
1110
1150
|
#define WHOCPY(dest, src) \
|
1111
1151
|
SIGAR_SSTRCPY(dest, src); \
|
1112
1152
|
if (sizeof(src) < sizeof(dest)) \
|
1113
1153
|
dest[sizeof(src)] = '\0'
|
1114
1154
|
|
1115
|
-
|
1116
|
-
|
1117
|
-
sigar_who_list_t *wholist)
|
1155
|
+
static int sigar_who_utmp(sigar_t *sigar,
|
1156
|
+
sigar_who_list_t *wholist)
|
1118
1157
|
{
|
1119
|
-
|
1120
|
-
struct utmpx ut;
|
1158
|
+
#if defined(HAVE_UTMPX_H)
|
1159
|
+
struct utmpx *ut;
|
1121
1160
|
|
1122
|
-
|
1123
|
-
return errno;
|
1124
|
-
}
|
1161
|
+
setutxent();
|
1125
1162
|
|
1126
|
-
while (
|
1163
|
+
while ((ut = getutxent()) != NULL) {
|
1127
1164
|
sigar_who_t *who;
|
1128
1165
|
|
1129
|
-
if (*ut
|
1166
|
+
if (*ut->ut_user == '\0') {
|
1130
1167
|
continue;
|
1131
1168
|
}
|
1132
1169
|
|
1133
|
-
|
1134
|
-
if (ut.ut_type != UTMPX_USER_PROCESS) {
|
1170
|
+
if (ut->ut_type != USER_PROCESS) {
|
1135
1171
|
continue;
|
1136
1172
|
}
|
1137
|
-
#endif
|
1138
1173
|
|
1139
1174
|
SIGAR_WHO_LIST_GROW(wholist);
|
1140
1175
|
who = &wholist->data[wholist->number++];
|
1141
1176
|
|
1142
|
-
WHOCPY(who->user, ut
|
1143
|
-
WHOCPY(who->device, ut
|
1144
|
-
WHOCPY(who->host, ut
|
1177
|
+
WHOCPY(who->user, ut->ut_user);
|
1178
|
+
WHOCPY(who->device, ut->ut_line);
|
1179
|
+
WHOCPY(who->host, ut->ut_host);
|
1145
1180
|
|
1146
|
-
who->time = ut.
|
1181
|
+
who->time = ut->ut_tv.tv_sec;
|
1147
1182
|
}
|
1148
1183
|
|
1149
|
-
|
1150
|
-
|
1151
|
-
return SIGAR_OK;
|
1152
|
-
}
|
1153
|
-
#endif
|
1154
|
-
|
1155
|
-
#if defined(SIGAR_NO_UTMP) && defined(SIGAR_HAS_UTMPX)
|
1156
|
-
#define sigar_who_utmp sigar_who_utmpx
|
1157
|
-
#else
|
1158
|
-
static int sigar_who_utmp(sigar_t *sigar,
|
1159
|
-
sigar_who_list_t *wholist)
|
1160
|
-
{
|
1184
|
+
endutxent();
|
1185
|
+
#elif defined(HAVE_UTMP_H)
|
1161
1186
|
FILE *fp;
|
1162
|
-
#ifdef __sun
|
1163
|
-
/* use futmpx w/ pid32_t for sparc64 */
|
1164
|
-
struct futmpx ut;
|
1165
|
-
#else
|
1166
1187
|
struct utmp ut;
|
1167
|
-
|
1168
|
-
if (!(fp = fopen(
|
1169
|
-
#ifdef SIGAR_HAS_UTMPX
|
1170
|
-
/* Darwin 10.5 */
|
1171
|
-
return sigar_who_utmpx(sigar, wholist);
|
1172
|
-
#endif
|
1188
|
+
|
1189
|
+
if (!(fp = fopen(_PATH_UTMP, "r"))) {
|
1173
1190
|
return errno;
|
1174
1191
|
}
|
1175
1192
|
|
@@ -1189,7 +1206,7 @@ static int sigar_who_utmp(sigar_t *sigar,
|
|
1189
1206
|
SIGAR_WHO_LIST_GROW(wholist);
|
1190
1207
|
who = &wholist->data[wholist->number++];
|
1191
1208
|
|
1192
|
-
WHOCPY(who->user, ut.
|
1209
|
+
WHOCPY(who->user, ut.ut_name);
|
1193
1210
|
WHOCPY(who->device, ut.ut_line);
|
1194
1211
|
WHOCPY(who->host, ut.ut_host);
|
1195
1212
|
|
@@ -1197,11 +1214,10 @@ static int sigar_who_utmp(sigar_t *sigar,
|
|
1197
1214
|
}
|
1198
1215
|
|
1199
1216
|
fclose(fp);
|
1217
|
+
#endif
|
1200
1218
|
|
1201
1219
|
return SIGAR_OK;
|
1202
1220
|
}
|
1203
|
-
#endif /* SIGAR_NO_UTMP */
|
1204
|
-
#endif /* NETWARE */
|
1205
1221
|
|
1206
1222
|
#if defined(WIN32)
|
1207
1223
|
|
data/src/sigar_cache.c
CHANGED
@@ -35,7 +35,7 @@ static void free_value(void *ptr)
|
|
35
35
|
free(ptr);
|
36
36
|
}
|
37
37
|
|
38
|
-
sigar_cache_t *
|
38
|
+
sigar_cache_t *sigar_expired_cache_new(int size, sigar_uint64_t cleanup_period_millis, sigar_uint64_t entry_expire_period)
|
39
39
|
{
|
40
40
|
sigar_cache_t *table = malloc(sizeof(*table));
|
41
41
|
table->count = 0;
|
@@ -43,16 +43,27 @@ sigar_cache_t *sigar_cache_new(int size)
|
|
43
43
|
table->entries = malloc(ENTRIES_SIZE(size));
|
44
44
|
memset(table->entries, '\0', ENTRIES_SIZE(size));
|
45
45
|
table->free_value = free_value;
|
46
|
+
table->cleanup_period_millis = cleanup_period_millis;
|
47
|
+
table->last_cleanup_time = sigar_time_now_millis();
|
48
|
+
table->entry_expire_period = entry_expire_period;
|
46
49
|
return table;
|
47
50
|
}
|
48
51
|
|
49
|
-
|
52
|
+
sigar_cache_t *sigar_cache_new(int size)
|
53
|
+
{
|
54
|
+
return sigar_expired_cache_new(size, SIGAR_FIELD_NOTIMPL, SIGAR_FIELD_NOTIMPL);
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
/*#ifdef DEBUG_CACHE*/
|
50
59
|
/* see how well entries are distributed */
|
51
|
-
|
60
|
+
void sigar_cache_dump(sigar_cache_t *table)
|
52
61
|
{
|
53
62
|
int i;
|
54
63
|
sigar_cache_entry_t **entries = table->entries;
|
55
|
-
|
64
|
+
printf("table size %lu\n", (long)table->size);
|
65
|
+
printf("table count %lu\n", (long)table->count);
|
66
|
+
|
56
67
|
for (i=0; i<table->size; i++) {
|
57
68
|
sigar_cache_entry_t *entry = *entries++;
|
58
69
|
|
@@ -68,12 +79,12 @@ static void sigar_cache_dump(sigar_cache_t *table)
|
|
68
79
|
printf("\n");
|
69
80
|
fflush(stdout);
|
70
81
|
}
|
71
|
-
|
82
|
+
/*#endif*/
|
72
83
|
|
73
84
|
static void sigar_cache_rehash(sigar_cache_t *table)
|
74
85
|
{
|
75
86
|
int i;
|
76
|
-
unsigned int new_size = table->
|
87
|
+
unsigned int new_size = table->count * 2 + 1;
|
77
88
|
sigar_cache_entry_t **entries = table->entries;
|
78
89
|
sigar_cache_entry_t **new_entries =
|
79
90
|
malloc(ENTRIES_SIZE(new_size));
|
@@ -101,16 +112,76 @@ static void sigar_cache_rehash(sigar_cache_t *table)
|
|
101
112
|
#define SIGAR_CACHE_IX(t, k) \
|
102
113
|
t->entries + (k % t->size)
|
103
114
|
|
115
|
+
void sigar_perform_cleanup_if_necessary(sigar_cache_t *table) {
|
116
|
+
sigar_uint64_t current_time;
|
117
|
+
int i;
|
118
|
+
sigar_cache_entry_t **entries;
|
119
|
+
if (table->cleanup_period_millis == SIGAR_FIELD_NOTIMPL) {
|
120
|
+
/* no cleanup for this cache) */
|
121
|
+
return;
|
122
|
+
}
|
123
|
+
current_time = sigar_time_now_millis();
|
124
|
+
if ((current_time - table->last_cleanup_time) < table->cleanup_period_millis) {
|
125
|
+
/* not enough time has passed since last cleanup */
|
126
|
+
return;
|
127
|
+
}
|
128
|
+
|
129
|
+
/* performing cleanup */
|
130
|
+
entries = table->entries;
|
131
|
+
|
132
|
+
table->last_cleanup_time = current_time;
|
133
|
+
|
134
|
+
for (i=0; i<table->size; i++) {
|
135
|
+
sigar_cache_entry_t *entry, *ptr, *entry_prev=NULL, **entry_in_table;
|
136
|
+
entry_in_table = entries;
|
137
|
+
entry = *entries++;
|
138
|
+
|
139
|
+
while (entry) {
|
140
|
+
sigar_uint64_t period_with_no_access = current_time - entry->last_access_time;
|
141
|
+
ptr = entry->next;
|
142
|
+
if (table->entry_expire_period < period_with_no_access) {
|
143
|
+
/* no one acess this entry for too long - we can delete it */
|
144
|
+
if (entry->value) {
|
145
|
+
table->free_value(entry->value);
|
146
|
+
}
|
147
|
+
free(entry);
|
148
|
+
table->count--;
|
149
|
+
if (entry_prev != NULL) {
|
150
|
+
entry_prev->next = ptr;
|
151
|
+
}
|
152
|
+
else {
|
153
|
+
/* removing first entry - head of list should point to next entry */
|
154
|
+
*entry_in_table = ptr;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
else {
|
158
|
+
/* entry not expired - advance entry_prev to current entry*/
|
159
|
+
entry_prev = entry;
|
160
|
+
}
|
161
|
+
entry = ptr;
|
162
|
+
}
|
163
|
+
}
|
164
|
+
if (table->count < (table->size/4)) {
|
165
|
+
/* hash table (the array size) too big for the amount of values it contains perform rehash */
|
166
|
+
sigar_cache_rehash(table);
|
167
|
+
}
|
168
|
+
}
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
104
173
|
sigar_cache_entry_t *sigar_cache_find(sigar_cache_t *table,
|
105
174
|
sigar_uint64_t key)
|
106
175
|
{
|
107
176
|
sigar_cache_entry_t *entry, **ptr;
|
177
|
+
sigar_perform_cleanup_if_necessary(table);
|
108
178
|
|
109
179
|
for (ptr = SIGAR_CACHE_IX(table, key), entry = *ptr;
|
110
180
|
entry;
|
111
181
|
ptr = &entry->next, entry = *ptr)
|
112
182
|
{
|
113
183
|
if (entry->id == key) {
|
184
|
+
entry->last_access_time = sigar_time_now_millis();
|
114
185
|
return entry;
|
115
186
|
}
|
116
187
|
}
|
@@ -123,17 +194,19 @@ sigar_cache_entry_t *sigar_cache_get(sigar_cache_t *table,
|
|
123
194
|
sigar_uint64_t key)
|
124
195
|
{
|
125
196
|
sigar_cache_entry_t *entry, **ptr;
|
197
|
+
sigar_perform_cleanup_if_necessary(table);
|
126
198
|
|
127
199
|
for (ptr = SIGAR_CACHE_IX(table, key), entry = *ptr;
|
128
200
|
entry;
|
129
201
|
ptr = &entry->next, entry = *ptr)
|
130
202
|
{
|
131
203
|
if (entry->id == key) {
|
204
|
+
entry->last_access_time = sigar_time_now_millis();
|
132
205
|
return entry;
|
133
206
|
}
|
134
207
|
}
|
135
208
|
|
136
|
-
if (table->count
|
209
|
+
if (++table->count > table->size) {
|
137
210
|
sigar_cache_rehash(table);
|
138
211
|
|
139
212
|
for (ptr = SIGAR_CACHE_IX(table, key), entry = *ptr;
|
@@ -147,6 +220,7 @@ sigar_cache_entry_t *sigar_cache_get(sigar_cache_t *table,
|
|
147
220
|
entry->id = key;
|
148
221
|
entry->value = NULL;
|
149
222
|
entry->next = NULL;
|
223
|
+
entry->last_access_time = sigar_time_now_millis();
|
150
224
|
|
151
225
|
return entry;
|
152
226
|
}
|
data/src/sigar_ptql.c
CHANGED
@@ -1338,6 +1338,14 @@ static ptql_lookup_t PTQL_Cpu[] = {
|
|
1338
1338
|
{ NULL }
|
1339
1339
|
};
|
1340
1340
|
|
1341
|
+
static ptql_lookup_t PTQL_Disk_IO[] = {
|
1342
|
+
{ "BytesRead", PTQL_LOOKUP_ENTRY(proc_disk_io, bytes_read, UI64) },
|
1343
|
+
{ "BytesWritten", PTQL_LOOKUP_ENTRY(proc_disk_io, bytes_written, UI64) },
|
1344
|
+
{ "BytesTotal", PTQL_LOOKUP_ENTRY(proc_disk_io, bytes_total, UI64) },
|
1345
|
+
{ NULL }
|
1346
|
+
};
|
1347
|
+
|
1348
|
+
|
1341
1349
|
static ptql_lookup_t PTQL_CredName[] = {
|
1342
1350
|
{ "User", PTQL_LOOKUP_ENTRY(proc_cred_name, user, STR) },
|
1343
1351
|
{ "Group", PTQL_LOOKUP_ENTRY(proc_cred_name, group, STR) },
|
@@ -1424,6 +1432,7 @@ static ptql_entry_t ptql_map[] = {
|
|
1424
1432
|
{ "Port", PTQL_Port },
|
1425
1433
|
{ "Pid", PTQL_Pid },
|
1426
1434
|
{ "Service", PTQL_Service },
|
1435
|
+
{ "Disk_IO", PTQL_Disk_IO },
|
1427
1436
|
{ NULL }
|
1428
1437
|
};
|
1429
1438
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csigar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Doug MacEachern, Joerg Gottschlich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Patched version of System Information Gatherer And Reporter (original
|
14
14
|
by Doug McEachern, patched by Joerg Gottschlich)
|
@@ -20,7 +20,7 @@ extra_rdoc_files: []
|
|
20
20
|
files:
|
21
21
|
- LICENSE
|
22
22
|
- NOTICE
|
23
|
-
- README
|
23
|
+
- README.md
|
24
24
|
- Rakefile
|
25
25
|
- version.properties
|
26
26
|
- bindings/SigarWrapper.pm
|
data/README
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
Visit the SIGAR Wiki for documentation, bugs, support, etc.:
|
2
|
-
http://sigar.hyperic.com/
|
3
|
-
|
4
|
-
2014-10-28
|
5
|
-
Patched version of hyperic/sigar by jgottschlich@cloudscale.de
|
6
|
-
- added cpu_perc_metric to ruby bindings
|
7
|
-
- fixed Rakefile to use Gem::PackageTask instead of deprecated package
|
8
|
-
- changed version number to 0.7.3
|