add total_cores and total_sockets to sigar_cpu_info_t

This commit is contained in:
Doug MacEachern 2008-04-09 04:38:02 +00:00
parent 949147d4ba
commit 187df2f462
4 changed files with 32 additions and 7 deletions

View File

@ -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 => [
{

View File

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

View File

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

View File

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