Merge branch 'master' into SIGAR-172

This commit is contained in:
Matthew Kent 2009-08-13 23:41:53 -07:00
commit 7496b795e4
13 changed files with 218 additions and 27 deletions

View File

@ -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;

View File

@ -462,22 +462,32 @@ 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 => 'CPU speed',
plat => 'AFHLSW'
desc => 'Current CPU speed',
plat => '*'
},
{
name => 'mhz_max', type => 'Int',
desc => 'Maximum CPU speed',
plat => 'DL'
},
{
name => 'mhz_min', type => 'Int',
desc => 'Maximum CPU speed',
plat => 'DL'
},
{
name => 'cache_size', type => 'Long',
desc => 'CPU cache size',
plat => 'AL'
plat => 'ADL'
},
{
name => 'total_cores', type => 'Int',
@ -1086,6 +1096,11 @@ use vars qw(%classes %cmds);
desc => '',
plat => 'DFL'
},
{
name => 'tx_queue_len', type => 'Int',
desc => '',
plat => 'L'
},
],
NetInterfaceStat => [
{

View File

@ -97,6 +97,16 @@ public class NetFlags {
public final static int IFF_SLAVE = 0x1000;
/**
* Master of a load balancer
*/
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;

View File

@ -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 = (

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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;
@ -586,6 +588,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"
@ -614,6 +617,7 @@ typedef struct {
flags,
mtu,
metric;
int tx_queue_len;
} sigar_net_interface_config_t;
SIGAR_DECLARE(int)

View File

@ -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 <netdb.h>

View File

@ -2236,7 +2236,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 +2247,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;
@ -2263,18 +2264,35 @@ int sigar_cpu_info_list_get(sigar_t *sigar,
mhz = 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) {
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 +2315,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 +2377,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;
@ -2487,7 +2515,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 +2527,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.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;
}
@ -2545,7 +2578,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 +2599,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;
}

View File

@ -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;

View File

@ -1503,12 +1503,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;
}
@ -1552,9 +1617,13 @@ 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;
int is_dynamic = flags & IFF_DYNAMIC;
/*
* XXX: should just define SIGAR_IFF_*
* and test IFF_* bits on given platform.
@ -1572,6 +1641,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;
}
@ -1644,6 +1716,17 @@ int sigar_net_interface_config_get(sigar_t *sigar, const char *name,
ifconfig->metric = ifr.ifr_metric ? ifr.ifr_metric : 1;
}
#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? */

View File

@ -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;
}