missed api _list convention, cpu_infos -> cpu_info_list

This commit is contained in:
Doug MacEachern 2004-07-10 04:44:45 +00:00
parent ca3ecc05f5
commit ddc6f4c55c
16 changed files with 72 additions and 68 deletions

View File

@ -7,7 +7,7 @@ public class CpuInfo {
Sigar sigar = new Sigar();
Hyperic.Sigar.CpuInfo[] infos =
sigar.CpuInfos();
sigar.CpuInfoList();
System.Console.WriteLine(infos.Length + " total CPUs..");

View File

@ -32,8 +32,8 @@ namespace Hyperic.Sigar {
return Hyperic.Sigar.Swap.NativeGet(this);
}
public CpuInfo[] CpuInfos() {
return Hyperic.Sigar.CpuInfos.NativeGet(this);
public CpuInfo[] CpuInfoList() {
return Hyperic.Sigar.CpuInfoList.NativeGet(this);
}
public FileSystem[] FileSystemList() {
@ -126,31 +126,32 @@ namespace Hyperic.Sigar {
}
[StructLayout(LayoutKind.Sequential)]
internal struct CpuInfos {
internal struct CpuInfoList {
private readonly uint Number; //sizeof(unsigned long) == 4
private readonly uint size;
private readonly IntPtr data;
[DllImport(Sigar.LIBSIGAR)]
private static extern int sigar_cpu_infos_get(IntPtr sigar,
IntPtr cpu_infos);
[DllImport(Sigar.LIBSIGAR)]
private static extern int sigar_cpu_infos_destroy(IntPtr sigar,
private static extern int sigar_cpu_info_list_get(IntPtr sigar,
IntPtr cpu_infos);
[DllImport(Sigar.LIBSIGAR)]
private static extern int sigar_cpu_info_list_destroy(IntPtr sigar,
IntPtr cpu_infos);
internal static CpuInfo[] NativeGet(Sigar sigar) {
Type type = typeof(CpuInfos);
Type type = typeof(CpuInfoList);
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(type));
int status = sigar_cpu_infos_get(sigar.sigar.Handle, ptr);
int status = sigar_cpu_info_list_get(sigar.sigar.Handle, ptr);
if (status != Sigar.OK) {
Marshal.FreeHGlobal(ptr);
throw new ApplicationException("cpu_infos_get");
throw new ApplicationException("cpu_info_list_get");
}
CpuInfos infosPtr = (CpuInfos)Marshal.PtrToStructure(ptr, type);
CpuInfoList infosPtr =
(CpuInfoList)Marshal.PtrToStructure(ptr, type);
CpuInfo[] infos = new CpuInfo[infosPtr.Number];
@ -164,7 +165,7 @@ namespace Hyperic.Sigar {
eptr = Sigar.incrementIntPtr(eptr, size);
}
sigar_cpu_infos_destroy(sigar.sigar.Handle, ptr);
sigar_cpu_info_list_destroy(sigar.sigar.Handle, ptr);
Marshal.FreeHGlobal(ptr);

View File

@ -305,12 +305,12 @@ JNIEXPORT jobjectArray SIGAR_JNI(Sigar_getCpuInfoList)
{
int status;
unsigned int i;
sigar_cpu_infos_t cpu_infos;
sigar_cpu_info_list_t cpu_infos;
jobjectArray cpuarray;
jclass cls = SIGAR_FIND_CLASS("CpuInfo");
dSIGAR(NULL);
if ((status = sigar_cpu_infos_get(sigar, &cpu_infos)) != SIGAR_OK) {
if ((status = sigar_cpu_info_list_get(sigar, &cpu_infos)) != SIGAR_OK) {
sigar_throw_error(env, sigar, status);
return NULL;
}
@ -326,7 +326,7 @@ JNIEXPORT jobjectArray SIGAR_JNI(Sigar_getCpuInfoList)
JENV->SetObjectArrayElement(env, cpuarray, i, info_obj);
}
sigar_cpu_infos_destroy(sigar, &cpu_infos);
sigar_cpu_info_list_destroy(sigar, &cpu_infos);
return cpuarray;
}

View File

@ -136,13 +136,13 @@ public class Sigar implements SigarProxy {
return (this.lastCpu = Cpu.fetch(this));
}
private static void pause(int millis) {
static void pause(int millis) {
try {
Thread.sleep(millis);
} catch(InterruptedException e) { }
}
private static void pause() {
static void pause() {
pause(500);
}

View File

@ -201,15 +201,15 @@ file_system_list(sigar)
RETVAL
SV *
cpu_infos(sigar)
cpu_info_list(sigar)
Sigar sigar
PREINIT:
sigar_cpu_infos_t cpu_infos;
sigar_cpu_info_list_t cpu_infos;
int status;
CODE:
status = sigar_cpu_infos_get(sigar, &cpu_infos);
status = sigar_cpu_info_list_get(sigar, &cpu_infos);
if (status != SIGAR_OK) {
SIGAR_CROAK(sigar, "cpu_infos");
@ -220,7 +220,7 @@ cpu_infos(sigar)
sizeof(*cpu_infos.data),
"Sigar::CpuInfo");
sigar_cpu_infos_destroy(sigar, &cpu_infos);
sigar_cpu_info_list_destroy(sigar, &cpu_infos);
OUTPUT:
RETVAL

View File

@ -5,7 +5,7 @@ use Sigar;
my $sigar = new Sigar;
my $infos = $sigar->cpu_infos;
my $infos = $sigar->cpu_info_list;
my $num = scalar @$infos;

View File

@ -123,13 +123,15 @@ typedef struct {
unsigned long number;
unsigned long size;
sigar_cpu_info_t *data;
} sigar_cpu_infos_t;
} sigar_cpu_info_list_t;
SIGAR_DECLARE(int) sigar_cpu_infos_get(sigar_t *sigar,
sigar_cpu_infos_t *cpu_infos);
SIGAR_DECLARE(int)
sigar_cpu_info_list_get(sigar_t *sigar,
sigar_cpu_info_list_t *cpu_infos);
SIGAR_DECLARE(int) sigar_cpu_infos_destroy(sigar_t *sigar,
sigar_cpu_infos_t *cpu_infos);
SIGAR_DECLARE(int)
sigar_cpu_info_list_destroy(sigar_t *sigar,
sigar_cpu_info_list_t *cpu_infos);
typedef struct {
double uptime;

View File

@ -120,13 +120,13 @@ int sigar_os_fs_type_get(sigar_file_system_t *fsp);
void sigar_fs_type_get(sigar_file_system_t *fsp);
int sigar_cpu_infos_create(sigar_cpu_infos_t *cpu_infos);
int sigar_cpu_info_list_create(sigar_cpu_info_list_t *cpu_infos);
int sigar_cpu_infos_grow(sigar_cpu_infos_t *cpu_infos);
int sigar_cpu_info_list_grow(sigar_cpu_info_list_t *cpu_infos);
#define SIGAR_CPU_INFOS_GROW(cpu_infos) \
#define SIGAR_CPU_INFO_LIST_GROW(cpu_infos) \
if (cpu_infos->number >= cpu_infos->size) { \
sigar_cpu_infos_grow(cpu_infos); \
sigar_cpu_info_list_grow(cpu_infos); \
}
int sigar_cpu_list_create(sigar_cpu_list_t *cpulist);

View File

@ -1183,20 +1183,20 @@ static int sigar_get_cpu_mhz(sigar_t *sigar)
return sigar->cpu_mhz;
}
int sigar_cpu_infos_get(sigar_t *sigar,
sigar_cpu_infos_t *cpu_infos)
int sigar_cpu_info_list_get(sigar_t *sigar,
sigar_cpu_info_list_t *cpu_infos)
{
int i;
int ncpu = _system_configuration.ncpus; /* this can change */
/*XXX should only do this once*/
sigar_cpu_infos_create(cpu_infos);
sigar_cpu_info_list_create(cpu_infos);
for (i=0; i<ncpu; i++) {
sigar_cpu_info_t *info;
char *arch, *model=NULL;
SIGAR_CPU_INFOS_GROW(cpu_infos);
SIGAR_CPU_INFO_LIST_GROW(cpu_infos);
info = &cpu_infos->data[cpu_infos->number++];

View File

@ -593,17 +593,17 @@ int sigar_file_system_usage_get(sigar_t *sigar,
return SIGAR_OK;
}
int sigar_cpu_infos_get(sigar_t *sigar,
sigar_cpu_infos_t *cpu_infos)
int sigar_cpu_info_list_get(sigar_t *sigar,
sigar_cpu_info_list_t *cpu_infos)
{
int i;
sigar_cpu_infos_create(cpu_infos);
sigar_cpu_info_list_create(cpu_infos);
for (i=0; i<sigar->ncpu; i++) {
sigar_cpu_info_t *info;
SIGAR_CPU_INFOS_GROW(cpu_infos);
SIGAR_CPU_INFO_LIST_GROW(cpu_infos);
info = &cpu_infos->data[cpu_infos->number++];

View File

@ -538,8 +538,8 @@ int sigar_file_system_usage_get(sigar_t *sigar,
return SIGAR_OK;
}
int sigar_cpu_infos_get(sigar_t *sigar,
sigar_cpu_infos_t *cpu_infos)
int sigar_cpu_info_list_get(sigar_t *sigar,
sigar_cpu_info_list_t *cpu_infos)
{
int i;
struct pst_dynamic stats;
@ -547,7 +547,7 @@ int sigar_cpu_infos_get(sigar_t *sigar,
pstat_getdynamic(&stats, sizeof(stats), 1, 0);
sigar->ncpu = stats.psd_proc_cnt;
sigar_cpu_infos_create(cpu_infos);
sigar_cpu_info_list_create(cpu_infos);
for (i=0; i<sigar->ncpu; i++) {
sigar_cpu_info_t *info;
@ -558,7 +558,7 @@ int sigar_cpu_infos_get(sigar_t *sigar,
continue;
}
SIGAR_CPU_INFOS_GROW(cpu_infos);
SIGAR_CPU_INFO_LIST_GROW(cpu_infos);
info = &cpu_infos->data[cpu_infos->number++];

View File

@ -141,13 +141,13 @@ static int is_ht_enabled(sigar_t *sigar)
{
if (sigar->ht_enabled == -1) {
/* only check once */
sigar_cpu_infos_t cpuinfos;
sigar_cpu_info_list_t cpuinfos;
if (sigar_cpu_infos_get(sigar, &cpuinfos) != SIGAR_OK) {
if (sigar_cpu_info_list_get(sigar, &cpuinfos) != SIGAR_OK) {
sigar->ht_enabled = 0; /* chances we reach here: slim..none */
}
sigar_cpu_infos_destroy(sigar, &cpuinfos);
sigar_cpu_info_list_destroy(sigar, &cpuinfos);
}
return sigar->ht_enabled;
@ -1075,8 +1075,8 @@ static int get_cpu_info(sigar_t *sigar, sigar_cpu_info_t *info,
return found;
}
int sigar_cpu_infos_get(sigar_t *sigar,
sigar_cpu_infos_t *cpu_infos)
int sigar_cpu_info_list_get(sigar_t *sigar,
sigar_cpu_info_list_t *cpu_infos)
{
FILE *fp;
int id;
@ -1090,7 +1090,7 @@ int sigar_cpu_infos_get(sigar_t *sigar,
sigar->ht_enabled = 0; /* figure out below */
sigar_cpu_infos_create(cpu_infos);
sigar_cpu_info_list_create(cpu_infos);
memset(&cpu_id[0], -1, sizeof(cpu_id));
while (get_cpu_info(sigar, &cpu_infos->data[cpu_infos->number], fp, &id)) {
@ -1118,7 +1118,7 @@ int sigar_cpu_infos_get(sigar_t *sigar,
}
++cpu_infos->number;
SIGAR_CPU_INFOS_GROW(cpu_infos);
SIGAR_CPU_INFO_LIST_GROW(cpu_infos);
}
fclose(fp);

View File

@ -952,8 +952,8 @@ int sigar_file_system_usage_get(sigar_t *sigar,
return SIGAR_OK;
}
int sigar_cpu_infos_get(sigar_t *sigar,
sigar_cpu_infos_t *cpu_infos)
int sigar_cpu_info_list_get(sigar_t *sigar,
sigar_cpu_info_list_t *cpu_infos)
{
processor_info_t stats;
unsigned int i;
@ -982,12 +982,12 @@ int sigar_cpu_infos_get(sigar_t *sigar,
return ENOENT;
}
sigar_cpu_infos_create(cpu_infos);
sigar_cpu_info_list_create(cpu_infos);
for (i=0; i<sigar->ncpu; i++) {
sigar_cpu_info_t *info;
SIGAR_CPU_INFOS_GROW(cpu_infos);
SIGAR_CPU_INFO_LIST_GROW(cpu_infos);
info = &cpu_infos->data[cpu_infos->number++];
@ -1360,4 +1360,4 @@ int sigar_net_interface_stat_get(sigar_t *sigar, const char *name,
int sigar_net_connection_list_get(sigar_t *sigar,
sigar_net_connection_list_t *connlist,
int flags
int flags

View File

@ -198,12 +198,12 @@ int sigar_file_system_usage_get(sigar_t *sigar,
return SIGAR_OK;
}
int sigar_cpu_infos_get(sigar_t *sigar,
sigar_cpu_infos_t *cpu_infos)
int sigar_cpu_info_list_get(sigar_t *sigar,
sigar_cpu_info_list_t *cpu_infos)
{
sigar_cpu_info_t *info;
sigar_cpu_infos_create(cpu_infos);
sigar_cpu_info_list_create(cpu_infos);
info = &cpu_infos->data[cpu_infos->number++];

View File

@ -1360,15 +1360,15 @@ sigar_file_system_usage_get(sigar_t *sigar,
return SIGAR_OK;
}
SIGAR_DECLARE(int) sigar_cpu_infos_get(sigar_t *sigar,
sigar_cpu_infos_t *cpu_infos)
SIGAR_DECLARE(int) sigar_cpu_info_list_get(sigar_t *sigar,
sigar_cpu_info_list_t *cpu_infos)
{
int i, status;
sigar_cpu_info_t *info;
sigar_cpu_count(sigar);
sigar_cpu_infos_create(cpu_infos);
sigar_cpu_info_list_create(cpu_infos);
info = &cpu_infos->data[cpu_infos->number++];
@ -1380,7 +1380,7 @@ SIGAR_DECLARE(int) sigar_cpu_infos_get(sigar_t *sigar,
if (sigar->ncpu > 1) {
for (i=1; i<sigar->ncpu; i++) {
SIGAR_CPU_INFOS_GROW(cpu_infos);
SIGAR_CPU_INFO_LIST_GROW(cpu_infos);
memcpy(&cpu_infos->data[cpu_infos->number++],
info, sizeof(*info));

View File

@ -486,7 +486,7 @@ sigar_file_system_list_destroy(sigar_t *sigar,
return SIGAR_OK;
}
int sigar_cpu_infos_create(sigar_cpu_infos_t *cpu_infos)
int sigar_cpu_info_list_create(sigar_cpu_info_list_t *cpu_infos)
{
cpu_infos->number = 0;
cpu_infos->size = SIGAR_CPU_INFO_MAX;
@ -495,7 +495,7 @@ int sigar_cpu_infos_create(sigar_cpu_infos_t *cpu_infos)
return SIGAR_OK;
}
int sigar_cpu_infos_grow(sigar_cpu_infos_t *cpu_infos)
int sigar_cpu_info_list_grow(sigar_cpu_info_list_t *cpu_infos)
{
cpu_infos->data = realloc(cpu_infos->data,
sizeof(*(cpu_infos->data)) *
@ -505,8 +505,9 @@ int sigar_cpu_infos_grow(sigar_cpu_infos_t *cpu_infos)
return SIGAR_OK;
}
SIGAR_DECLARE(int) sigar_cpu_infos_destroy(sigar_t *sigar,
sigar_cpu_infos_t *cpu_infos)
SIGAR_DECLARE(int)
sigar_cpu_info_list_destroy(sigar_t *sigar,
sigar_cpu_info_list_t *cpu_infos)
{
if (cpu_infos->size) {
free(cpu_infos->data);