From cfae297d9b09e5a210d6a43a1eb63261edc9414a Mon Sep 17 00:00:00 2001 From: Matthew Kent Date: Sat, 8 Aug 2009 14:44:58 -0700 Subject: [PATCH 01/13] Add IFF_DYNAMIC support for Linux. Support in the ruby binding. --- bindings/ruby/rbsigar.c | 1 + include/sigar.h | 1 + src/sigar.c | 4 ++++ src/sigar_format.c | 3 +++ 4 files changed, 9 insertions(+) diff --git a/bindings/ruby/rbsigar.c b/bindings/ruby/rbsigar.c index 7bfc7a7d..526125a9 100644 --- a/bindings/ruby/rbsigar.c +++ b/bindings/ruby/rbsigar.c @@ -684,6 +684,7 @@ static void Init_rbsigar_constants(VALUE rclass) RB_SIGAR_CONST_INT(IFF_MULTICAST); RB_SIGAR_CONST_INT(IFF_SLAVE); RB_SIGAR_CONST_INT(IFF_MASTER); + RB_SIGAR_CONST_INT(IFF_DYNAMIC); RB_SIGAR_CONST_INT(NETCONN_CLIENT); RB_SIGAR_CONST_INT(NETCONN_SERVER); diff --git a/include/sigar.h b/include/sigar.h index a09ecebd..d5f5d6a2 100644 --- a/include/sigar.h +++ b/include/sigar.h @@ -585,6 +585,7 @@ SIGAR_DECLARE(int) sigar_net_route_list_destroy(sigar_t *sigar, #define SIGAR_IFF_MULTICAST 0x800 #define SIGAR_IFF_SLAVE 0x1000 #define SIGAR_IFF_MASTER 0x2000 +#define SIGAR_IFF_DYNAMIC 0x4000 #define SIGAR_NULL_HWADDR "00:00:00:00:00:00" diff --git a/src/sigar.c b/src/sigar.c index 9ab00450..a21808ae 100644 --- a/src/sigar.c +++ b/src/sigar.c @@ -1551,6 +1551,7 @@ int sigar_net_interface_config_get(sigar_t *sigar, const char *name, int is_mcast = flags & IFF_MULTICAST; int is_slave = flags & IFF_SLAVE; int is_master = flags & IFF_MASTER; + int is_dynamic = flags & IFF_DYNAMIC; /* * XXX: should just define SIGAR_IFF_* * and test IFF_* bits on given platform. @@ -1568,6 +1569,9 @@ int sigar_net_interface_config_get(sigar_t *sigar, const char *name, if (is_master) { flags |= SIGAR_IFF_MASTER; } + if (is_dynamic) { + flags |= SIGAR_IFF_DYNAMIC; + } #endif ifconfig->flags = flags; } diff --git a/src/sigar_format.c b/src/sigar_format.c index ea7d5290..a719f6a0 100644 --- a/src/sigar_format.c +++ b/src/sigar_format.c @@ -559,6 +559,9 @@ SIGAR_DECLARE(char *) sigar_net_interface_flags_to_string(sigar_uint64_t flags, if (flags & SIGAR_IFF_MASTER) { strcat(buf, "MASTER "); } + if (flags & SIGAR_IFF_DYNAMIC) { + strcat(buf, "DYNAMIC "); + } return buf; } From 83996dda13797c0fe9e83384ec9c36add8b5d85d Mon Sep 17 00:00:00 2001 From: Matthew Kent Date: Sun, 9 Aug 2009 15:20:25 -0700 Subject: [PATCH 02/13] Add per interface support for tx_queue_len, Linux only. Update the ifconfig example output. --- bindings/SigarWrapper.pm | 5 +++++ bindings/ruby/examples/ifconfig.rb | 3 ++- include/sigar.h | 1 + src/sigar.c | 13 ++++++++++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/bindings/SigarWrapper.pm b/bindings/SigarWrapper.pm index 5801f70e..56793a16 100644 --- a/bindings/SigarWrapper.pm +++ b/bindings/SigarWrapper.pm @@ -1081,6 +1081,11 @@ use vars qw(%classes %cmds); desc => '', plat => 'DFL' }, + { + name => 'tx_queue_len', type => 'Int', + desc => '', + plat => 'L' + }, ], NetInterfaceStat => [ { diff --git a/bindings/ruby/examples/ifconfig.rb b/bindings/ruby/examples/ifconfig.rb index 4443e7ef..d0cf21cd 100644 --- a/bindings/ruby/examples/ifconfig.rb +++ b/bindings/ruby/examples/ifconfig.rb @@ -65,7 +65,8 @@ iflist.each do |ifname| " overruns:" + ifstat.tx_overruns.to_s + " carrier:" + ifstat.tx_carrier.to_s - puts "\t" + "collisions:" + ifstat.tx_collisions.to_s + puts "\t" + "collisions:" + ifstat.tx_collisions.to_s + + " txqueuelen:" + ifconfig.tx_queue_len.to_s rx_bytes = ifstat.rx_bytes tx_bytes = ifstat.tx_bytes diff --git a/include/sigar.h b/include/sigar.h index a09ecebd..0ca85fa5 100644 --- a/include/sigar.h +++ b/include/sigar.h @@ -613,6 +613,7 @@ typedef struct { flags, mtu, metric; + int tx_queue_len; } sigar_net_interface_config_t; SIGAR_DECLARE(int) diff --git a/src/sigar.c b/src/sigar.c index 9ab00450..e0d7623f 100644 --- a/src/sigar.c +++ b/src/sigar.c @@ -1640,7 +1640,18 @@ int sigar_net_interface_config_get(sigar_t *sigar, const char *name, ifconfig->metric = ifr.ifr_metric ? ifr.ifr_metric : 1; } - close(sock); +#if defined(SIOCGIFTXQLEN) + if (!ioctl(sock, SIOCGIFTXQLEN, &ifr)) { + ifconfig->tx_queue_len = ifr.ifr_qlen; + } + else { + ifconfig->tx_queue_len = -1; /* net-tools behaviour */ + } +#else + ifconfig->tx_queue_len = -1; +#endif + + close(sock); /* XXX can we get a better description like win32? */ SIGAR_SSTRCPY(ifconfig->description, From ea3fcd5b455a3cda7412610205e8084c0b4a8e2b Mon Sep 17 00:00:00 2001 From: Matthew Kent Date: Mon, 10 Aug 2009 00:29:23 -0700 Subject: [PATCH 03/13] Add more interface types from net-tools. --- include/sigar_private.h | 22 +++++++++++++ src/sigar.c | 69 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 89 insertions(+), 2 deletions(-) diff --git a/include/sigar_private.h b/include/sigar_private.h index fde2465f..b9b657a8 100644 --- a/include/sigar_private.h +++ b/include/sigar_private.h @@ -363,8 +363,30 @@ int sigar_get_iftype(const char *name, int *type, int *inst); #endif #define SIGAR_NIC_LOOPBACK "Local Loopback" +#define SIGAR_NIC_UNSPEC "UNSPEC" +#define SIGAR_NIC_SLIP "Serial Line IP" +#define SIGAR_NIC_CSLIP "VJ Serial Line IP" +#define SIGAR_NIC_SLIP6 "6-bit Serial Line IP" +#define SIGAR_NIC_CSLIP6 "VJ 6-bit Serial Line IP" +#define SIGAR_NIC_ADAPTIVE "Adaptive Serial Line IP" #define SIGAR_NIC_ETHERNET "Ethernet" +#define SIGAR_NIC_ASH "Ash" +#define SIGAR_NIC_FDDI "Fiber Distributed Data Interface" +#define SIGAR_NIC_HIPPI "HIPPI" +#define SIGAR_NIC_AX25 "AMPR AX.25" +#define SIGAR_NIC_ROSE "AMPR ROSE" #define SIGAR_NIC_NETROM "AMPR NET/ROM" +#define SIGAR_NIC_X25 "generic X.25" +#define SIGAR_NIC_TUNNEL "IPIP Tunnel" +#define SIGAR_NIC_PPP "Point-to-Point Protocol" +#define SIGAR_NIC_HDLC "(Cisco)-HDLC" +#define SIGAR_NIC_LAPB "LAPB" +#define SIGAR_NIC_ARCNET "ARCnet" +#define SIGAR_NIC_DLCI "Frame Relay DLCI" +#define SIGAR_NIC_FRAD "Frame Relay Access Device" +#define SIGAR_NIC_SIT "IPv6-in-IPv4" +#define SIGAR_NIC_IRDA "IrLAP" +#define SIGAR_NIC_EC "Econet" #ifndef WIN32 #include diff --git a/src/sigar.c b/src/sigar.c index 9ab00450..14512778 100644 --- a/src/sigar.c +++ b/src/sigar.c @@ -1499,12 +1499,77 @@ static void get_interface_type(sigar_net_interface_config_t *ifconfig, char *type; switch (family) { + case ARPHRD_SLIP: + type = SIGAR_NIC_SLIP; + break; + case ARPHRD_CSLIP: + type = SIGAR_NIC_CSLIP; + break; + case ARPHRD_SLIP6: + type = SIGAR_NIC_SLIP6; + break; + case ARPHRD_CSLIP6: + type = SIGAR_NIC_CSLIP6; + break; + case ARPHRD_ADAPT: + type = SIGAR_NIC_ADAPTIVE; + break; + case ARPHRD_ETHER: + type = SIGAR_NIC_ETHERNET; + break; + case ARPHRD_ASH: + type = SIGAR_NIC_ASH; + break; + case ARPHRD_FDDI: + type = SIGAR_NIC_FDDI; + break; + case ARPHRD_HIPPI: + type = SIGAR_NIC_HIPPI; + break; + case ARPHRD_AX25: + type = SIGAR_NIC_AX25; + break; + case ARPHRD_ROSE: + type = SIGAR_NIC_ROSE; + break; case ARPHRD_NETROM: type = SIGAR_NIC_NETROM; break; - /* XXX more */ + case ARPHRD_X25: + type = SIGAR_NIC_X25; + break; + case ARPHRD_TUNNEL: + type = SIGAR_NIC_TUNNEL; + break; + case ARPHRD_PPP: + type = SIGAR_NIC_PPP; + break; + case ARPHRD_CISCO: + type = SIGAR_NIC_HDLC; + break; + case ARPHRD_LAPB: + type = SIGAR_NIC_LAPB; + break; + case ARPHRD_ARCNET: + type = SIGAR_NIC_ARCNET; + break; + case ARPHRD_DLCI: + type = SIGAR_NIC_DLCI; + break; + case ARPHRD_FRAD: + type = SIGAR_NIC_FRAD; + break; + case ARPHRD_SIT: + type = SIGAR_NIC_SIT; + break; + case ARPHRD_IRDA: + type = SIGAR_NIC_IRDA; + break; + case ARPHRD_ECONET: + type = SIGAR_NIC_EC; + break; default: - type = SIGAR_NIC_ETHERNET; + type = SIGAR_NIC_UNSPEC; break; } From 079dd9b09fd389b91ee80e537e0a31ba549e2dde Mon Sep 17 00:00:00 2001 From: Jan Kneschke Date: Sun, 9 Aug 2009 14:22:39 +0200 Subject: [PATCH 04/13] (SIGAR-137) sdl_data isn't 0-terminated fixed 2 more places where sdl_data is used as it would be 0-term'ed and doesn't honour sdl_nlen --- src/os/darwin/darwin_sigar.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/os/darwin/darwin_sigar.c b/src/os/darwin/darwin_sigar.c index 8a665a10..62a14ea4 100644 --- a/src/os/darwin/darwin_sigar.c +++ b/src/os/darwin/darwin_sigar.c @@ -2487,7 +2487,11 @@ static int sigar_ifmsg_init(sigar_t *sigar) return SIGAR_OK; } -static int has_ifaddr(char *name) +/** + * @param name name of the interface + * @param name_len length of name (w/o \0) + */ +static int has_ifaddr(char *name, size_t name_len) { int sock, status; struct ifreq ifr; @@ -2495,7 +2499,8 @@ static int has_ifaddr(char *name) if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { return errno; } - SIGAR_SSTRCPY(ifr.ifr_name, name); + strncpy(ifr.ift_name, name, MIN(sizeof(ifr.ift_name) - 1, name_len)); + ifr.ift_name[MIN(sizeof(ifr.ift_name) - 1, name_len)] = '\0'; if (ioctl(sock, SIOCGIFADDR, &ifr) == 0) { status = SIGAR_OK; } @@ -2545,7 +2550,7 @@ static int sigar_ifmsg_iter(sigar_t *sigar, ifmsg_iter_t *iter) switch (iter->type) { case IFMSG_ITER_LIST: if (sdl->sdl_type == IFT_OTHER) { - if (has_ifaddr(sdl->sdl_data) != SIGAR_OK) { + if (has_ifaddr(sdl->sdl_data, sdl->sdl_nlen) != SIGAR_OK) { break; } } @@ -2566,7 +2571,7 @@ static int sigar_ifmsg_iter(sigar_t *sigar, ifmsg_iter_t *iter) break; case IFMSG_ITER_GET: - if (strEQ(iter->name, sdl->sdl_data)) { + if (strlen(iter->name) == sdl->sdl_nlen && 0 == memcmp(iter->name, sdl->sdl_data, sdl->sdl_nlen)) { iter->data.ifm = ifm; return SIGAR_OK; } From e3068f466a11315195f1e35baafbf355b8167e59 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 12 Aug 2009 09:42:28 -0700 Subject: [PATCH 05/13] s/ift_name/ifr_name/g --- src/os/darwin/darwin_sigar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/os/darwin/darwin_sigar.c b/src/os/darwin/darwin_sigar.c index 62a14ea4..a72b5e99 100644 --- a/src/os/darwin/darwin_sigar.c +++ b/src/os/darwin/darwin_sigar.c @@ -2499,8 +2499,8 @@ static int has_ifaddr(char *name, size_t name_len) if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { return errno; } - strncpy(ifr.ift_name, name, MIN(sizeof(ifr.ift_name) - 1, name_len)); - ifr.ift_name[MIN(sizeof(ifr.ift_name) - 1, name_len)] = '\0'; + strncpy(ifr.ifr_name, name, MIN(sizeof(ifr.ifr_name) - 1, name_len)); + ifr.ifr_name[MIN(sizeof(ifr.ifr_name) - 1, name_len)] = '\0'; if (ioctl(sock, SIOCGIFADDR, &ifr) == 0) { status = SIGAR_OK; } From a77d7ef04f5881719fc84eb6db0644e8352502a1 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 12 Aug 2009 10:07:08 -0700 Subject: [PATCH 06/13] IFF_DYNAMIC not defined in linux 2.2 kernel --- src/sigar.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sigar.c b/src/sigar.c index a21808ae..ca9ea414 100644 --- a/src/sigar.c +++ b/src/sigar.c @@ -1548,6 +1548,9 @@ int sigar_net_interface_config_get(sigar_t *sigar, const char *name, if (!ioctl(sock, SIOCGIFFLAGS, &ifr)) { sigar_uint64_t flags = ifr.ifr_flags; #ifdef __linux__ +# ifndef IFF_DYNAMIC +# define IFF_DYNAMIC 0x8000 /* not in 2.2 kernel */ +# endif /* IFF_DYNAMIC */ int is_mcast = flags & IFF_MULTICAST; int is_slave = flags & IFF_SLAVE; int is_master = flags & IFF_MASTER; From 22c1b065dd0064fbe7a1e47671589c813444ec27 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 12 Aug 2009 10:11:36 -0700 Subject: [PATCH 07/13] add IFF_MASTER to NetFlags --- bindings/java/src/org/hyperic/sigar/NetFlags.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bindings/java/src/org/hyperic/sigar/NetFlags.java b/bindings/java/src/org/hyperic/sigar/NetFlags.java index ed680032..c9ecab0d 100644 --- a/bindings/java/src/org/hyperic/sigar/NetFlags.java +++ b/bindings/java/src/org/hyperic/sigar/NetFlags.java @@ -97,6 +97,11 @@ public class NetFlags { public final static int IFF_SLAVE = 0x1000; + /** + * Master of a load balancer + */ + public static final int IFF_MASTER = 0x2000; + public static final int RTF_UP = 0x1; public static final int RTF_GATEWAY = 0x2; From 5c8d1edbae1d8de2381d2a1d1f9516b6d80108b2 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 12 Aug 2009 10:13:13 -0700 Subject: [PATCH 08/13] add IFF_DYNAMIC to NetFlags --- bindings/java/src/org/hyperic/sigar/NetFlags.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bindings/java/src/org/hyperic/sigar/NetFlags.java b/bindings/java/src/org/hyperic/sigar/NetFlags.java index c9ecab0d..b9f62581 100644 --- a/bindings/java/src/org/hyperic/sigar/NetFlags.java +++ b/bindings/java/src/org/hyperic/sigar/NetFlags.java @@ -102,6 +102,11 @@ public class NetFlags { */ public static final int IFF_MASTER = 0x2000; + /** + * Dialup device with changing addresses + */ + public static final int IFF_DYNAMIC = 0x4000; + public static final int RTF_UP = 0x1; public static final int RTF_GATEWAY = 0x2; From 09f3418c1a7a77bb8ffb215c0f905587f579cc95 Mon Sep 17 00:00:00 2001 From: Matthew Kent Date: Wed, 12 Aug 2009 22:51:48 -0700 Subject: [PATCH 09/13] Add linux collection of cpu min/max. Make cpu mhz default the current mhz. --- bindings/SigarWrapper.pm | 12 +++++++++++- bindings/ruby/examples/cpu_info.rb | 4 +++- include/sigar.h | 2 ++ src/os/linux/linux_sigar.c | 19 ++++++++++++++++++- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/bindings/SigarWrapper.pm b/bindings/SigarWrapper.pm index 5801f70e..6f79a5c3 100644 --- a/bindings/SigarWrapper.pm +++ b/bindings/SigarWrapper.pm @@ -471,9 +471,19 @@ use vars qw(%classes %cmds); }, { name => 'mhz', type => 'Int', - desc => 'CPU speed', + desc => 'Current CPU speed', plat => 'AFHLSW' }, + { + name => 'mhz_max', type => 'Int', + desc => 'Maximum CPU speed', + plat => 'L' + }, + { + name => 'mhz_min', type => 'Int', + desc => 'Maximum CPU speed', + plat => 'L' + }, { name => 'cache_size', type => 'Long', desc => 'CPU cache size', diff --git a/bindings/ruby/examples/cpu_info.rb b/bindings/ruby/examples/cpu_info.rb index f68a5a80..a38dec8d 100644 --- a/bindings/ruby/examples/cpu_info.rb +++ b/bindings/ruby/examples/cpu_info.rb @@ -11,6 +11,8 @@ puts num.to_s + " total CPUs.." infos.each do |info| puts "Vendor........" + info.vendor puts "Model........." + info.model - puts "Mhz..........." + info.mhz.to_s + puts "Current Mhz..." + info.mhz.to_s + puts "Maximum Mhz..." + info.mhz_max.to_s + puts "Minimum Mhz..." + info.mhz_min.to_s puts "Cache size...." + info.cache_size.to_s end diff --git a/include/sigar.h b/include/sigar.h index d5f5d6a2..003ede19 100644 --- a/include/sigar.h +++ b/include/sigar.h @@ -188,6 +188,8 @@ typedef struct { char vendor[128]; char model[128]; int mhz; + int mhz_max; + int mhz_min; sigar_uint64_t cache_size; int total_sockets; int total_cores; diff --git a/src/os/linux/linux_sigar.c b/src/os/linux/linux_sigar.c index 1d3a9e1e..008c9bc3 100644 --- a/src/os/linux/linux_sigar.c +++ b/src/os/linux/linux_sigar.c @@ -1598,7 +1598,23 @@ static void get_cpuinfo_max_freq(sigar_cpu_info_t *cpu_info, int num) sigar_file2str(max_freq, max_freq, sizeof(max_freq)-1); if (status == SIGAR_OK) { - cpu_info->mhz = atoi(max_freq) / 1000; + cpu_info->mhz_max = atoi(max_freq) / 1000; + } +} + +static void get_cpuinfo_min_freq(sigar_cpu_info_t *cpu_info, int num) +{ + int status; + char min_freq[PATH_MAX]; + snprintf(min_freq, sizeof(min_freq), + "/sys/devices/system/cpu/cpu%d" + "/cpufreq/cpuinfo_min_freq", num); + + status = + sigar_file2str(min_freq, min_freq, sizeof(min_freq)-1); + + if (status == SIGAR_OK) { + cpu_info->mhz_min = atoi(min_freq) / 1000; } } @@ -1624,6 +1640,7 @@ int sigar_cpu_info_list_get(sigar_t *sigar, info = &cpu_infos->data[cpu_infos->number]; get_cpuinfo_max_freq(info, cpu_infos->number); + get_cpuinfo_min_freq(info, cpu_infos->number); info->total_cores = sigar->ncpu; info->cores_per_socket = sigar->lcpu; From dcddb5f642983138c51bd2703d0852142e08ab08 Mon Sep 17 00:00:00 2001 From: Matthew Kent Date: Wed, 12 Aug 2009 23:41:06 -0700 Subject: [PATCH 10/13] Untested stab at cpu mhz min/max support for Darwin. --- bindings/SigarWrapper.pm | 28 ++++++++++++------------- src/os/darwin/darwin_sigar.c | 40 ++++++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/bindings/SigarWrapper.pm b/bindings/SigarWrapper.pm index 6f79a5c3..f1895157 100644 --- a/bindings/SigarWrapper.pm +++ b/bindings/SigarWrapper.pm @@ -462,44 +462,44 @@ use vars qw(%classes %cmds); { name => 'vendor', type => 'String', desc => 'CPU vendor id', - plat => 'AFLHSW' + plat => '*' }, { name => 'model', type => 'String', desc => 'CPU model', - plat => 'AFLHSW' + plat => '*' }, { name => 'mhz', type => 'Int', desc => 'Current CPU speed', - plat => 'AFHLSW' + plat => '*' }, { name => 'mhz_max', type => 'Int', desc => 'Maximum CPU speed', - plat => 'L' + plat => 'DL' }, { name => 'mhz_min', type => 'Int', desc => 'Maximum CPU speed', - plat => 'L' + plat => 'DL' }, { name => 'cache_size', type => 'Long', desc => 'CPU cache size', - plat => 'AL' + plat => 'ADL' }, { - name => 'total_cores', type => 'Int', - desc => 'Total CPU cores (logical)', + name => 'total_cores', type => 'Int', + desc => 'Total CPU cores (logical)', }, { - name => 'total_sockets', type => 'Int', - desc => 'Total CPU sockets (physical)', + name => 'total_sockets', type => 'Int', + desc => 'Total CPU sockets (physical)', }, { - name => 'cores_per_socket', type => 'Int', - desc => 'Number of CPU cores per CPU socket', + name => 'cores_per_socket', type => 'Int', + desc => 'Number of CPU cores per CPU socket', }, ], Uptime => [ @@ -2070,8 +2070,8 @@ EOF my $member = $field->{member} || $name; my $desc = $field->{desc} || $name; (my $jname = $name) =~ s/_(\w)/\u$1/g; - my $getter = "get\u$jname"; - $jname = jname($jname); + my $getter = "get\u$jname"; + $jname = jname($jname); my $sig = qq("$field_types{$type}"); my $set = "JENV->Set${type}Field"; my $get = "JENV->Get${type}Field"; diff --git a/src/os/darwin/darwin_sigar.c b/src/os/darwin/darwin_sigar.c index 38c80958..43baaa3b 100644 --- a/src/os/darwin/darwin_sigar.c +++ b/src/os/darwin/darwin_sigar.c @@ -2237,6 +2237,8 @@ int sigar_file_system_usage_get(sigar_t *sigar, #ifdef DARWIN #define CTL_HW_FREQ "hw.cpufrequency" +#define CTL_HW_FREQ_MAX "hw.cpufrequency_max" +#define CTL_HW_FREQ_MIN "hw.cpufrequency_min" #else /* XXX FreeBSD 5.x+ only? */ #define CTL_HW_FREQ "machdep.tsc_freq" @@ -2246,7 +2248,7 @@ int sigar_cpu_info_list_get(sigar_t *sigar, sigar_cpu_info_list_t *cpu_infos) { int i; - unsigned int mhz; + unsigned int mhz, mhz_min, mhz_max; int cache_size=SIGAR_FIELD_NOTIMPL; size_t size; char model[128], vendor[128], *ptr; @@ -2257,24 +2259,48 @@ int sigar_cpu_info_list_get(sigar_t *sigar, #if defined(DARWIN) { - int mib[] = { CTL_HW, HW_CPU_FREQ }; + int mib[2]; + mib[0] = CTL_HW; + + mib[1] = HW_CPU_FREQ; size = sizeof(mhz); if (sysctl(mib, NMIB(mib), &mhz, &size, NULL, 0) < 0) { mhz = SIGAR_FIELD_NOTIMPL; } + mib[1] = HW_CPU_FREQ_MAX; + size = sizeof(mhz_max); + if (sysctl(mib, NMIB(mib), &mhz_max, &size, NULL, 0) < 0) { + mhz_max = SIGAR_FIELD_NOTIMPL; + } + mib[1] = HW_CPU_FREQ_MIN; + size = sizeof(mhz_min); + if (sysctl(mib, NMIB(mib), &mhz_max, &size, NULL, 0) < 0) { + mhz_min = SIGAR_FIELD_NOTIMPL; + } } #elif defined(__FreeBSD__) if (sysctlbyname(CTL_HW_FREQ, &mhz, &size, NULL, 0) < 0) { mhz = SIGAR_FIELD_NOTIMPL; } + /* TODO */ + mhz_max = SIGAR_FIELD_NOTIMPL; + mhz_min = SIGAR_FIELD_NOTIMPL; #else /*XXX OpenBSD*/ mhz = SIGAR_FIELD_NOTIMPL; + mhz_max = SIGAR_FIELD_NOTIMPL; + mhz_min = SIGAR_FIELD_NOTIMPL; #endif if (mhz != SIGAR_FIELD_NOTIMPL) { mhz /= 1000000; } + if (mhz_max != SIGAR_FIELD_NOTIMPL) { + mhz_max /= 1000000; + } + if (mhz_min != SIGAR_FIELD_NOTIMPL) { + mhz_min /= 1000000; + } size = sizeof(model); #ifdef __OpenBSD__ @@ -2297,6 +2323,14 @@ int sigar_cpu_info_list_get(sigar_t *sigar, /* freebsd4 */ mhz = sigar_cpu_mhz_from_model(model); } + /* XXX not sure */ + if (mhz_max == SIGAR_FIELD_NOTIMPL) { + mhz_max = 0; + } + if (mhz_min == SIGAR_FIELD_NOTIMPL) { + mhz_min = 0; + } + #ifdef DARWIN size = sizeof(vendor); @@ -2351,6 +2385,8 @@ int sigar_cpu_info_list_get(sigar_t *sigar, sigar_cpu_model_adjust(sigar, info); info->mhz = mhz; + info->mhz_max = mhz_max; + info->mhz_min = mhz_min; info->cache_size = cache_size; info->total_cores = sigar->ncpu; info->cores_per_socket = sigar->lcpu; From ee15426546f5d18e5914e88b8718e92579ae4779 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Thu, 13 Aug 2009 15:45:03 -0700 Subject: [PATCH 11/13] need to use sysctlbyname with hw.cpufrequency_{min,max} --- src/os/darwin/darwin_sigar.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/os/darwin/darwin_sigar.c b/src/os/darwin/darwin_sigar.c index 43baaa3b..2e5ae26e 100644 --- a/src/os/darwin/darwin_sigar.c +++ b/src/os/darwin/darwin_sigar.c @@ -2236,7 +2236,6 @@ int sigar_file_system_usage_get(sigar_t *sigar, } #ifdef DARWIN -#define CTL_HW_FREQ "hw.cpufrequency" #define CTL_HW_FREQ_MAX "hw.cpufrequency_max" #define CTL_HW_FREQ_MIN "hw.cpufrequency_min" #else @@ -2259,24 +2258,17 @@ int sigar_cpu_info_list_get(sigar_t *sigar, #if defined(DARWIN) { - int mib[2]; - mib[0] = CTL_HW; - - mib[1] = HW_CPU_FREQ; + int mib[] = { CTL_HW, HW_CPU_FREQ }; size = sizeof(mhz); if (sysctl(mib, NMIB(mib), &mhz, &size, NULL, 0) < 0) { mhz = SIGAR_FIELD_NOTIMPL; } - mib[1] = HW_CPU_FREQ_MAX; - size = sizeof(mhz_max); - if (sysctl(mib, NMIB(mib), &mhz_max, &size, NULL, 0) < 0) { - mhz_max = SIGAR_FIELD_NOTIMPL; - } - mib[1] = HW_CPU_FREQ_MIN; - size = sizeof(mhz_min); - if (sysctl(mib, NMIB(mib), &mhz_max, &size, NULL, 0) < 0) { - mhz_min = SIGAR_FIELD_NOTIMPL; - } + } + if (sysctlbyname(CTL_HW_FREQ_MAX, &mhz_max, &size, NULL, 0) < 0) { + mhz_max = SIGAR_FIELD_NOTIMPL; + } + if (sysctlbyname(CTL_HW_FREQ_MIN, &mhz_min, &size, NULL, 0) < 0) { + mhz_min = SIGAR_FIELD_NOTIMPL; } #elif defined(__FreeBSD__) if (sysctlbyname(CTL_HW_FREQ, &mhz, &size, NULL, 0) < 0) { From 245e563857f070173237dd9b6e62ae0462a02371 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Thu, 13 Aug 2009 16:34:11 -0700 Subject: [PATCH 12/13] .cpp -> .o --- bindings/perl/Makefile.PL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/perl/Makefile.PL b/bindings/perl/Makefile.PL index b4bd624f..c768e976 100644 --- a/bindings/perl/Makefile.PL +++ b/bindings/perl/Makefile.PL @@ -25,7 +25,7 @@ else { my $flags = SigarBuild::flags(); my(@inline_src) = SigarBuild::inline_src($flags); push @clean_files, @inline_src; - my(@object) = ('Sigar.o', map { s/c$/o/; $_ } @inline_src); + my(@object) = ('Sigar.o', map { s/cp{0,2}$/o/; $_ } @inline_src); my(@libs) = map { "-l$_" } @{$flags->{libs}}; @mm_args = ( From 085218e3fbb2a728bbb17c2264b966be851bccb8 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Thu, 13 Aug 2009 16:35:08 -0700 Subject: [PATCH 13/13] add win32 comsupp and wbemuuid libs --- bindings/SigarBuild.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/SigarBuild.pm b/bindings/SigarBuild.pm index 597367e9..d83ef3e6 100644 --- a/bindings/SigarBuild.pm +++ b/bindings/SigarBuild.pm @@ -71,7 +71,7 @@ sub flags { $os = $1; $is_win32 = 1; @cppflags = ('-DWIN32'); - @libs = qw(kernel32 user32 advapi32 ws2_32 netapi32 shell32 pdh version); + @libs = qw(kernel32 user32 advapi32 ws2_32 netapi32 shell32 pdh version comsupp wbemuuid); } elsif ($os =~ /(linux)/) { $os = $1;