Unix Programming - System resource information on HP-UX

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > November 2006 > System resource information on HP-UX





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author System resource information on HP-UX
k.szczesny@gmail.com

2006-11-15, 1:21 pm

Hi,

i'm new to HP-UX, but i have to write a library, from which i will get
info such as:
cpu kernel time
cpu user time
cpu idle time
(average to all processors)
free ram
used ram
total ram

to pass it to Java application trough JNI.
I already wrote such library for windows, but now i need one for HP-UX
(ver. B.11.11 9000/800).
I''ve tried with systeminfo, but i can't get it to work. I've been
trying several code samples found across the google, but i guess all of
them were made for other systems then hp-ux.

Here's a quick sample:

#include <stdlib.h>
#include <stdio.h>
#include <sys/sysinfo.h>

int main(int argc, const char *argv[])
{
struct minfo s_info;
int ret = sysinfo(s_info);

if(ret == -1){
perror("");
exit(-1);
}
return 1;
}

Probably it's lame, but i really have to solve this. Information passed
by this library is crucial for me :/
Please, help ;)

Best regards,
Krystian

moi

2006-11-15, 1:21 pm

On Wed, 15 Nov 2006 06:21:12 -0800, k.szczesny wrote:


> struct minfo s_info;
> int ret = sysinfo(s_info);
>


You'll at least need an & here.

Sysinfo is a linux-extension. Maybe you should try getrusage()
getrlimit(), and friends.

HTH,
AvK
Rick Jones

2006-11-15, 7:28 pm

moi <root@localhost.localdomain> wrote:
> On Wed, 15 Nov 2006 06:21:12 -0800, k.szczesny wrote:
[vbcol=seagreen]
> You'll at least need an & here.


> Sysinfo is a linux-extension. Maybe you should try getrusage()
> getrlimit(), and friends.


Better still (?), peruse the manpage for pstat and start from there

rick jones
--
web2.0 n, the dot.com reunion tour...
these opinions are mine, all mine; HP might not want them anyway...
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...
k.szczesny@gmail.com

2006-11-16, 1:30 am

moi wrote:
> On Wed, 15 Nov 2006 06:21:12 -0800, k.szczesny wrote:
>
>
>
> You'll at least need an & here.
>
> Sysinfo is a linux-extension. Maybe you should try getrusage()
> getrlimit(), and friends.
>
> HTH,
> AvK


Hi,

thank You for reply.
Unfortunately getrusage and getrlimit gives information about usage of
a certain process. I need info about whole system.

k.szczesny@gmail.com

2006-11-16, 7:29 am


Rick Jones wrote:
> moi <root@localhost.localdomain> wrote:
>
>
>
> Better still (?), peruse the manpage for pstat and start from there
>
> rick jones


Thanks for reply,

it helped a lot, now i've got information about cpu usage, all i have
left to do is get info about RAM. in pstat there are information about
virtual memory only as i can see.
If You could point me into right direction i would be gratefull.

Best regards,
Krystian

P.s.

It's not that i like to anwer my own questions, but i hate to search in
groups for a solution, find a question and an answer that somebody did
his job, but gave no solution to public ;]

Here is how i did it:

#include <sys/param.h>
#include <sys/pstat.h>
#include <sys/unistd.h>
#include <stdio.h>
#include <string.h>
#define MAX_PROCS 128
#define VALID_CPUSTATES 9

/*
//
// Processor states on HP-UX
// 0 - CPU_USER
// 1 - CPU_NICE
// 2 - CPU_SYSTEM
// 3 - CPU_IDLE
// 4 - CPU_WAIT
// 5 - CPU_BLOCK
// 6 - CPU_SWAIT
// 7 - CPU_INTERRUP
// 8 - CPU_KERNEL
/*
struct pst_processor pstat_buffer[MAX_PROCS];
struct pstat_dyn;

int rc;
int i, j, total_prev;
int tot_prev[VALID_CPUSTATES], tot_cur[VALID_CPUSTATES],
tot_delta[VALID_CPUSTATES];

main()
{

rc=pstat_getprocessor(pstat_buffer,sizeo
f(struct pst_processor),
pstat_dyn.psd_proc_cnt, 0);

if ( rc == -1 )
return rc;


for (i=0;i<VALID_CPUSTATES;i++)
{
tot_prev[i]=pstat_dyn.psd_cpu_time[i];
}

sleep(200);

rc=pstat_getdynamic(&pstat_dyn,sizeof(struct pst_dynamic), 1,0);

if ( rc == -1 )
return rc;

for (i=0;i<VALID_CPUSTATES;i++)
{
tot_cur[i]=pstat_dyn.psd_cpu_time[i];
tot_delta[i] = tot_cur[i] - tot_prev[i];
}

}

// and now with tot_delta one can measure the percentage of use by
certain type of work cpu does

Rick Jones

2006-11-16, 1:17 pm

k.szczesny@gmail.com wrote:
> Rick Jones wrote:
[vbcol=seagreen]
> Thanks for reply,


> it helped a lot, now i've got information about cpu usage, all i have
> left to do is get info about RAM. in pstat there are information about
> virtual memory only as i can see.
> If You could point me into right direction i would be gratefull.


Perhaps some of the "pstat_static" stuff will talk about RAM. Perusal
of the pstat include file(s) might find it. Otherwise, at the risk of
it doing "something else" you could try the latest PD top sources
and/or a tusc (aka system call) trace of top running on an HP-UX
system (or of vmstat or other tools I suppose...)

rick jones
--
a wide gulf separates "what if" from "if only"
these opinions are mine, all mine; HP might not want them anyway...
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...
Don Morris

2006-11-16, 7:20 pm

Rick Jones wrote:
> k.szczesny@gmail.com wrote:
>
>
>
> Perhaps some of the "pstat_static" stuff will talk about RAM. Perusal
> of the pstat include file(s) might find it. Otherwise, at the risk of
> it doing "something else" you could try the latest PD top sources
> and/or a tusc (aka system call) trace of top running on an HP-UX
> system (or of vmstat or other tools I suppose...)


Yeah -- I tried to point him at pstat() in comp.lang.c, but I guess that
didn't get read.

[Rick, this is directed at k.szczesny -- not at you.. ;) ]
What you want is some combination of pstat_getvminfo(),
pstat_getstatic() and pstat_getdynamic(). Exactly what usage depends
on exactly what you want... read "man 2 pstat" to find out where the
headers live, and check the fields and their descriptions for the
structures filled in by those.

If all you want is total RAM on the machine, and total RAM in
use [by kernel + user + firmware + bad pages, etc.],
physical_memory is in the pst_static structure [total RAM],
and psd_free in the pst_dynamic structure is your free RAM -
both should be in pages, I believe. Per-process RAM usage,
virtual memory consumption, swap and the like will take more
fields/calls.

More arcane machine-dependent things such as CPU types, hardware
bits and the like are best found via the sysconf interface.
"man 2 sysconf"

Take a look -- and feel free to follow up if you have specific
questions.

Don
Krystian

2006-11-17, 7:30 am


Don Morris wrote:
> Rick Jones wrote:
>
> Yeah -- I tried to point him at pstat() in comp.lang.c, but I guess that
> didn't get read.
>
> [Rick, this is directed at k.szczesny -- not at you.. ;) ]
> What you want is some combination of pstat_getvminfo(),
> pstat_getstatic() and pstat_getdynamic(). Exactly what usage depends
> on exactly what you want... read "man 2 pstat" to find out where the
> headers live, and check the fields and their descriptions for the
> structures filled in by those.
>
> If all you want is total RAM on the machine, and total RAM in
> use [by kernel + user + firmware + bad pages, etc.],
> physical_memory is in the pst_static structure [total RAM],
> and psd_free in the pst_dynamic structure is your free RAM -
> both should be in pages, I believe. Per-process RAM usage,
> virtual memory consumption, swap and the like will take more
> fields/calls.
>
> More arcane machine-dependent things such as CPU types, hardware
> bits and the like are best found via the sysconf interface.
> "man 2 sysconf"
>
> Take a look -- and feel free to follow up if you have specific
> questions.
>
> Don


Thank You Don,

that helped a lot.

My library is done, all i have to do is make it work with java.
On windows there was no problem, but on hp-ux it just can't see the
library, though it's in a directory defined in java.library.path.

Best regards to all,
thank You for help,

Krystian

Krystian

2006-11-17, 7:30 am


Krystian wrote:
> Don Morris wrote:
>
> Thank You Don,
>
> that helped a lot.
>
> My library is done, all i have to do is make it work with java.
> On windows there was no problem, but on hp-ux it just can't see the
> library, though it's in a directory defined in java.library.path.
>
> Best regards to all,
> thank You for help,
>
> Krystian


It's solved!
Thanks to Gordon Beaton from comp.lang.java.programmer.
He did same example file as I did, and run it with strace /i can't/.
java searches for lib+filename_from_application+.sl file, so i had to
rename my uxinfo.sl to libuxinfo.sl and now it works - well... at least
it loads the library!

Best regards, and thanks to all,
Krystian

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com