Merge branch 'master' into SIGAR-172
This commit is contained in:
commit
7496b795e4
13 files changed
+218
-27
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
+86
-3
@@ -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,7 +1716,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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user