diff --git a/bindings/SigarWrapper.pm b/bindings/SigarWrapper.pm index f4a6c638..7790c704 100644 --- a/bindings/SigarWrapper.pm +++ b/bindings/SigarWrapper.pm @@ -501,6 +501,14 @@ use vars qw(%classes %cmds); desc => 'CPU cache size', plat => 'AL' }, + { + name => 'total_cores', type => 'Int', + desc => 'Total CPU cores (logical)', + }, + { + name => 'total_sockets', type => 'Int', + desc => 'Total CPU sockets (physical)', + }, ], Uptime => [ { diff --git a/bindings/java/src/org/hyperic/sigar/cmd/CpuInfo.java b/bindings/java/src/org/hyperic/sigar/cmd/CpuInfo.java index eef10f49..ddf8f397 100644 --- a/bindings/java/src/org/hyperic/sigar/cmd/CpuInfo.java +++ b/bindings/java/src/org/hyperic/sigar/cmd/CpuInfo.java @@ -58,12 +58,16 @@ public class CpuInfo extends SigarCommandBase { CpuPerc[] cpus = this.sigar.getCpuPercList(); - println(cpus.length + " total CPUs.."); org.hyperic.sigar.CpuInfo info = infos[0]; long cacheSize = info.getCacheSize(); - println("Vendor........" + info.getVendor()); - println("Model........." + info.getModel()); - println("Mhz..........." + info.getMhz()); + println("Vendor........." + info.getVendor()); + println("Model.........." + info.getModel()); + println("Mhz............" + info.getMhz()); + println("Total CPUs....." + info.getTotalCores()); + if (info.getTotalCores() != info.getTotalSockets()) { + println("Physical CPUs.." + info.getTotalSockets()); + } + if (cacheSize != Sigar.FIELD_NOTIMPL) { println("Cache size...." + cacheSize); } diff --git a/include/sigar.h b/include/sigar.h index 908827ee..0011daf4 100644 --- a/include/sigar.h +++ b/include/sigar.h @@ -186,6 +186,8 @@ typedef struct { char model[128]; int mhz; sigar_uint64_t cache_size; + int total_sockets; + int total_cores; } sigar_cpu_info_t; typedef struct { diff --git a/src/os/linux/linux_sigar.c b/src/os/linux/linux_sigar.c index aefe0386..78f8c180 100644 --- a/src/os/linux/linux_sigar.c +++ b/src/os/linux/linux_sigar.c @@ -312,6 +312,11 @@ static int sigar_cpu_core_rollup(sigar_t *sigar) #define sigar_cpu_core_count(sigar) 1 #endif +static int sigar_cpu_total_count(sigar_t *sigar) +{ + return (int)sysconf(_SC_NPROCESSORS_CONF); +} + static int get_ram(sigar_t *sigar, sigar_mem_t *mem) { char buffer[BUFSIZ], *ptr; @@ -1666,6 +1671,7 @@ int sigar_cpu_info_list_get(sigar_t *sigar, { FILE *fp; int core_rollup = sigar_cpu_core_rollup(sigar), i=0; + int ncpu = sigar_cpu_total_count(sigar); if (!(fp = fopen(PROC_FS_ROOT "cpuinfo", "r"))) { return errno; @@ -1674,15 +1680,20 @@ int sigar_cpu_info_list_get(sigar_t *sigar, sigar_cpu_info_list_create(cpu_infos); while (get_cpu_info(sigar, &cpu_infos->data[cpu_infos->number], fp)) { + sigar_cpu_info_t *cpu_info; + + SIGAR_CPU_INFO_LIST_GROW(cpu_infos); + if (core_rollup && (i++ % sigar->lcpu)) { continue; /* fold logical processors */ } - get_cpuinfo_max_freq(&cpu_infos->data[cpu_infos->number], - cpu_infos->number); + cpu_info = &cpu_infos->data[cpu_infos->number]; + get_cpuinfo_max_freq(cpu_info, cpu_infos->number); + cpu_info->total_sockets = ncpu / sigar->lcpu; + cpu_info->total_cores = ncpu; ++cpu_infos->number; - SIGAR_CPU_INFO_LIST_GROW(cpu_infos); } fclose(fp);