add total_cores and total_sockets to sigar_cpu_info_t
This commit is contained in:
parent
949147d4ba
commit
187df2f462
|
@ -501,6 +501,14 @@ use vars qw(%classes %cmds);
|
||||||
desc => 'CPU cache size',
|
desc => 'CPU cache size',
|
||||||
plat => 'AL'
|
plat => 'AL'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name => 'total_cores', type => 'Int',
|
||||||
|
desc => 'Total CPU cores (logical)',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name => 'total_sockets', type => 'Int',
|
||||||
|
desc => 'Total CPU sockets (physical)',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
Uptime => [
|
Uptime => [
|
||||||
{
|
{
|
||||||
|
|
|
@ -58,12 +58,16 @@ public class CpuInfo extends SigarCommandBase {
|
||||||
CpuPerc[] cpus =
|
CpuPerc[] cpus =
|
||||||
this.sigar.getCpuPercList();
|
this.sigar.getCpuPercList();
|
||||||
|
|
||||||
println(cpus.length + " total CPUs..");
|
|
||||||
org.hyperic.sigar.CpuInfo info = infos[0];
|
org.hyperic.sigar.CpuInfo info = infos[0];
|
||||||
long cacheSize = info.getCacheSize();
|
long cacheSize = info.getCacheSize();
|
||||||
println("Vendor........" + info.getVendor());
|
println("Vendor........." + info.getVendor());
|
||||||
println("Model........." + info.getModel());
|
println("Model.........." + info.getModel());
|
||||||
println("Mhz..........." + info.getMhz());
|
println("Mhz............" + info.getMhz());
|
||||||
|
println("Total CPUs....." + info.getTotalCores());
|
||||||
|
if (info.getTotalCores() != info.getTotalSockets()) {
|
||||||
|
println("Physical CPUs.." + info.getTotalSockets());
|
||||||
|
}
|
||||||
|
|
||||||
if (cacheSize != Sigar.FIELD_NOTIMPL) {
|
if (cacheSize != Sigar.FIELD_NOTIMPL) {
|
||||||
println("Cache size...." + cacheSize);
|
println("Cache size...." + cacheSize);
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,6 +186,8 @@ typedef struct {
|
||||||
char model[128];
|
char model[128];
|
||||||
int mhz;
|
int mhz;
|
||||||
sigar_uint64_t cache_size;
|
sigar_uint64_t cache_size;
|
||||||
|
int total_sockets;
|
||||||
|
int total_cores;
|
||||||
} sigar_cpu_info_t;
|
} sigar_cpu_info_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
@ -312,6 +312,11 @@ static int sigar_cpu_core_rollup(sigar_t *sigar)
|
||||||
#define sigar_cpu_core_count(sigar) 1
|
#define sigar_cpu_core_count(sigar) 1
|
||||||
#endif
|
#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)
|
static int get_ram(sigar_t *sigar, sigar_mem_t *mem)
|
||||||
{
|
{
|
||||||
char buffer[BUFSIZ], *ptr;
|
char buffer[BUFSIZ], *ptr;
|
||||||
|
@ -1666,6 +1671,7 @@ int sigar_cpu_info_list_get(sigar_t *sigar,
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int core_rollup = sigar_cpu_core_rollup(sigar), i=0;
|
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"))) {
|
if (!(fp = fopen(PROC_FS_ROOT "cpuinfo", "r"))) {
|
||||||
return errno;
|
return errno;
|
||||||
|
@ -1674,15 +1680,20 @@ int sigar_cpu_info_list_get(sigar_t *sigar,
|
||||||
sigar_cpu_info_list_create(cpu_infos);
|
sigar_cpu_info_list_create(cpu_infos);
|
||||||
|
|
||||||
while (get_cpu_info(sigar, &cpu_infos->data[cpu_infos->number], fp)) {
|
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)) {
|
if (core_rollup && (i++ % sigar->lcpu)) {
|
||||||
continue; /* fold logical processors */
|
continue; /* fold logical processors */
|
||||||
}
|
}
|
||||||
|
|
||||||
get_cpuinfo_max_freq(&cpu_infos->data[cpu_infos->number],
|
cpu_info = &cpu_infos->data[cpu_infos->number];
|
||||||
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;
|
++cpu_infos->number;
|
||||||
SIGAR_CPU_INFO_LIST_GROW(cpu_infos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
Loading…
Reference in New Issue