From: k.szczesny on
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

From: moi on
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
From: Rick Jones on
moi <root(a)localhost.localdomain> wrote:
> 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.

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...
From: k.szczesny on
moi wrote:
> 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

Hi,

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

From: k.szczesny on

Rick Jones wrote:
> moi <root(a)localhost.localdomain> wrote:
> > 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.
>
> 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,sizeof(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