Hi,
I'm trying to gather the system load information (for 1, 5 and 15 mins prior).
As of my understanding, I should use the kstat related data/procedures.
So, a part of my code looks something like this:
--------- code starts
if (!(ksp = kstat_lookup(kc, "unix", 0, "system_misc"))) return FAILURE;
if (kstat_read(kc, ksp, NULL) == -1) return FAILURE;
load_5 = (double) ((kstat_named_t *) kstat_data_lookup(ksp,"avenrun_1min"))->value.l \
/ FSCALE;
load_5 = (double) ((kstat_named_t *) kstat_data_lookup(ksp,"avenrun_5min"))->value.l \
/ FSCALE;
load_15 = (double) ((kstat_named_t *) kstat_data_lookup(ksp,"avenrun_15min"))->value.l \
/ FSCALE;
------------- code end
Now, when I compile my code and run, I recv a segmentation fault in "kstat_data_lookup"
and debugging it I find that the 'data section' ( kstat->ks_data ) is NULL (0x0)
where as the ks_data_size is 432 (below is the "printed" info from gdb)
--------------------- debugged info starts
$1 = {ks_crtime = 0x0000000048c2a004, ks_next = 0x26490, ks_kid = 11,
ks_module = "unix", '\000' <repeats 26 times>, ks_resv = 0 '\000',
ks_instance = 0, ks_name = "system_misc", '\000' <repeats 19 times>,
ks_type = 1 '\001', ks_class = "misc", '\000' <repeats 26 times>,
ks_flags = 1 '\001', ks_data = 0x0, ks_ndata = 9, ks_data_size = 432,
ks_snaptime = 0x00033c8bffdef718,
ks_update = 0xf0096e48 <_elf_jbuf+9284392>, ks_private = 0x0,
ks_snapshot = 0xf0096c10 <_elf_jbuf+9283824>, ks_lock = 0x0}
------------------------ debugged info ends --
I dont understand why the ks_data portion is NULL. Is there something I need to do
earlier? What should I do .... Is there a small specific routine to get the system load
information that I can access. (this metrics retrieval is a very MINOR part of
a big project i am working on ..and I am stuck here 8-(
Any help appreciated.
Pl let me know if I should post this somewhere else ...
thanks a ton,
-Nataraj