- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Use of library pstat.h
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2002 01:01 PM
03-11-2002 01:01 PM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2002 01:19 PM
03-11-2002 01:19 PM
Re: Use of library pstat.h
You may be able to tell from the pst_status structure. There's a thing called pst_cpu and another called pst_pctcpu
int32_t pst_cpu; /* processor utilization for scheduling */
float pst_pctcpu; /* %cpu for this process during p_time */
although these may only be for per process information.
Hope this helps
Scott.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2002 01:43 PM
03-11-2002 01:43 PM
Re: Use of library pstat.h
Here's a simple example (I hacked this up from one of my existing tools, so pardon any sloppy coding):
/*
* Description:
*
* program to collect cpu state data during
* execution of a command
*
* Usage:
*
* prstats [-l] [-i int]
*
*/
#define MAXCPU 128
#define MAXSTATES 5
char *cpstates[9] = {"USER","NICE","SYS","IDLE","WAIT","BLOCK","SWAIT","INTR","SSYS"};
#include
#include
#include
#include
#include
main(argc,argv)
int argc;
char * argv[];
{
int i,j,n;
pid_t child;
char * ProgName;
int wstat;
struct pst_dynamic psd,psdinit;
struct pst_processor psptot,pspinit[MAXCPU],psp[MAXCPU];
long cpucycles[PST_MAX_CPUSTATES],cycles[PST_MAX_CPUSTATES],totcycles;
if (argc < 2) {
fprintf(stderr, "usage: stats
exit(1);
}
/* get initial per processor data */
if(pstat_getprocessor(&pspinit[0], sizeof(pspinit[0]), (size_t)MAXCPU, 0) <0) {
perror("pstat_getprocessor");
exit(-1);
}
ProgName = argv[0];
if ((child = fork()) == -1) {
fprintf(stderr, "%s: unable to fork child: %s\n",
ProgName, strerror(errno));
exit(1);
}
if (child == 0) {
/*
* Child: execute command.
*/
if (execvp(argv[1], &argv[1]) == -1) {
fprintf(stderr, "%s: unable to execv %s: %s\n",
ProgName, argv[1], strerror(errno));
exit(1);
}
}
else {
while ((waitpid(child, &wstat, 0) == -1) && (errno == EINTR))
;
/*collect final system stats*/
if(pstat_getprocessor(&psp[0], sizeof(psp[0]), (size_t)MAXCPU, 0) <0) {
perror("pstat_getprocessor");
exit(-1);
}
if(pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) <0) {
perror("pstat_getdynamic");
exit(-1);
}
printf("cpu ");
for(i=0;i
for(i=0;i
totcycles = 0;
for(i=0;i
cpucycles[i] += cycles[i];
totcycles += cycles[i];
}
for(i=0;i
}
printf("\n");
}
printf("tot cpu");
for(i=0;i
}
for(i=0;i
}
printf("\n");
}
exit(0);
}
kiara [182] cc prstats.c
kiara [183] a.out sleep 1
cpu USER NICE SYS IDLE WAIT
0 0.0 0.0 0.0 100.0 0.0
1 0.0 0.0 0.0 100.0 0.0
2 0.0 0.0 0.0 100.0 0.0
3 0.0 0.0 0.0 100.0 0.0
4 0.0 0.0 0.0 100.0 0.0
5 0.0 0.0 0.0 100.0 0.0
6 0.0 0.0 0.0 100.0 0.0
7 0.0 0.0 0.0 100.0 0.0
8 0.0 0.0 0.0 100.0 0.0
9 0.0 0.0 0.0 100.0 0.0
10 0.0 0.0 0.0 100.0 0.0
11 1.0 0.0 0.0 99.0 0.0
12 1.0 0.0 0.0 98.0 1.0
13 0.0 0.0 0.0 100.0 0.0
14 0.0 0.0 0.0 100.0 0.0
15 0.0 0.0 0.0 100.0 0.0
tot cpu 0.1 0.0 0.0 93.9 0.1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2002 01:54 PM
03-11-2002 01:54 PM
SolutionI'll try adding the code as an attachment - perhaps it will be more readable that way.
Oh, and this code carries no warranty of any kind...$-).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2002 02:47 PM
03-11-2002 02:47 PM
Re: Use of library pstat.h
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2002 02:51 PM
03-12-2002 02:51 PM