From ac8f9541cde150d9bd9797fdd3b9d5a360864159 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Tue, 6 Nov 2007 06:55:55 +0000 Subject: [PATCH] [SIGAR-71] option for cpu_list to report cores rather than sockets --- bindings/java/src/org/hyperic/sigar/cmd/CpuInfo.java | 10 ++++------ include/sigar_private.h | 1 + src/os/linux/linux_sigar.c | 6 ++++++ src/os/solaris/solaris_sigar.c | 2 +- src/sigar.c | 2 ++ 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/bindings/java/src/org/hyperic/sigar/cmd/CpuInfo.java b/bindings/java/src/org/hyperic/sigar/cmd/CpuInfo.java index 5369426b..eef10f49 100644 --- a/bindings/java/src/org/hyperic/sigar/cmd/CpuInfo.java +++ b/bindings/java/src/org/hyperic/sigar/cmd/CpuInfo.java @@ -55,9 +55,10 @@ public class CpuInfo extends SigarCommandBase { org.hyperic.sigar.CpuInfo[] infos = this.sigar.getCpuInfoList(); - CpuPerc[] cpus = null; + CpuPerc[] cpus = + this.sigar.getCpuPercList(); - println(infos.length + " total CPUs.."); + println(cpus.length + " total CPUs.."); org.hyperic.sigar.CpuInfo info = infos[0]; long cacheSize = info.getCacheSize(); println("Vendor........" + info.getVendor()); @@ -72,11 +73,8 @@ public class CpuInfo extends SigarCommandBase { return; } - for (int i=0; iht_enabled = 0; sigar->lcpu = 0; + if (sigar->cpu_list_cores) { + sigar_log_printf(sigar, SIGAR_LOG_DEBUG, + "[cpu] skipping HT check"); + return 0; + } + sigar_cpuid(0, &eax, &ebx, &ecx, &edx); if ((ebx == INTEL_ID) || (ebx == AMD_ID)) { diff --git a/src/os/solaris/solaris_sigar.c b/src/os/solaris/solaris_sigar.c index 7beb4b6f..ff35cdd6 100644 --- a/src/os/solaris/solaris_sigar.c +++ b/src/os/solaris/solaris_sigar.c @@ -438,7 +438,7 @@ int sigar_cpu_list_get(sigar_t *sigar, sigar_cpu_list_t *cpulist) buf = ksp->ks_data; buf += sizeof(kmutex_t); memcpy(&cpuinfo[0], buf, sizeof(cpuinfo)); - chip_id = get_chip_id(sigar, i); + chip_id = sigar->cpu_list_cores ? -1 : get_chip_id(sigar, i); if (chip_id == -1) { SIGAR_CPU_LIST_GROW(cpulist); diff --git a/src/sigar.c b/src/sigar.c index c2777a15..35c08ef3 100644 --- a/src/sigar.c +++ b/src/sigar.c @@ -39,6 +39,8 @@ SIGAR_DECLARE(int) sigar_open(sigar_t **sigar) int status = sigar_os_open(sigar); if (status == SIGAR_OK) { + /* XXX tmp hack */ + (*sigar)->cpu_list_cores = getenv("SIGAR_CPU_CORES") ? 1 : 0; (*sigar)->pid = 0; (*sigar)->ifconf_buf = NULL; (*sigar)->ifconf_len = 0;