2
* Copyright (C) 2009 Tildeslash Ltd. All rights reserved.
2
* Copyright (C) 2010 Tildeslash Ltd. All rights reserved.
4
4
* This program is free software: you can redistribute it and/or modify
5
5
* it under the terms of the GNU General Public License version 3.
114
114
* @author Christian Hopp <chopp@iei.tu-clausthal.de>
115
115
* @author Joe Bryant <JBryant@RiteAid.com>
116
116
* @author Martin Pala, <martinp@tildeslash.com>
117
* @version \$Id: sysdep_HPUX.c,v 1.35 2009/02/13 09:18:17 hauk Exp $
123
122
* Helpful guide for implematation:
124
* "SunOS to HP-UX 9.05 Porting Guide" at
125
* http://www.interex.org/tech/9000/Tech/sun_hpux_port/portguide.html
123
* "SunOS to HP-UX 9.05 Porting Guide" at http://www.interex.org/tech/9000/Tech/sun_hpux_port/portguide.html
128
126
int init_process_info_sysdep(void) {
129
127
struct pst_dynamic psd;
130
128
struct pst_static pst;
132
if (pstat_getdynamic(&psd,sizeof(psd),(size_t)1,0)!=-1) {
130
if (pstat_getdynamic(&psd,sizeof(psd),(size_t)1,0) != -1)
134
131
systeminfo.cpus=psd.psd_proc_cnt;
142
135
if (pstat_getstatic(&pst, sizeof(pst), (size_t) 1, 0) != -1) {
144
136
systeminfo.mem_kbyte_max=(unsigned long)(pst.physical_memory * (pst.page_size / 1024));
145
137
page_size=pst.page_size;
157
147
* This routine returns 'na' double precision floats containing
158
148
* the load averages in 'a'; at most 3 values will be returned.
161
151
* @return: 0 if successful, -1 if failed (and all load averages are 0).
163
153
int getloadavg_sysdep (double *a, int na) {
165
154
struct pst_dynamic psd;
167
if (pstat_getdynamic(&psd,sizeof(psd),(size_t)1,0)!=-1) {
156
if (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) != -1) {
172
a[2]=psd.psd_avg_15_min;
159
a[2] = psd.psd_avg_15_min;
176
a[1]=psd.psd_avg_5_min;
162
a[1] = psd.psd_avg_5_min;
180
a[0]=psd.psd_avg_1_min;
165
a[0] = psd.psd_avg_1_min;
197
178
* @return treesize>0 if succeeded otherwise 0.
199
180
int initprocesstree_sysdep(ProcessTree_T ** reference) {
203
183
ProcessTree_T *pt;
205
185
ASSERT(reference);
207
/* Gather process data */
209
187
pstat_getdynamic(&pst_dyn, sizeof(struct pst_dynamic), 1, 0);
210
188
nproc = pst_dyn.psd_activeprocs;
212
if ((psall = (struct pst_status *) xresize(psall, nproc * sizeof(struct pst_status))) == NULL)
190
if ((psall = (struct pst_status *)xresize(psall, nproc * sizeof(struct pst_status))) == NULL)
215
if ((treesize=pstat_getproc(psall, sizeof(struct pst_status), nproc , 0))==-1) {
193
if ((treesize = pstat_getproc(psall, sizeof(struct pst_status), nproc , 0)) == -1) {
216
194
LogError("system statistic error 1 -- pstat_getproc failed: %s\n", strerror(errno));
220
/* Allocate the tree */
222
198
pt = xcalloc(sizeof(ProcessTree_T), treesize);
226
200
for (i = 0; i < treesize; i++) {
228
pt[i].pid = psall[i].pst_pid;
229
pt[i].ppid = psall[i].pst_ppid;
231
/* get the actual time */
233
pt[i].time = get_float_time();
235
pt[i].cputime = psall[i].pst_utime + psall[i].pst_stime * 10;
201
pt[i].pid = psall[i].pst_pid;
202
pt[i].ppid = psall[i].pst_ppid;
203
pt[i].time = get_float_time();
204
pt[i].cputime = psall[i].pst_utime + psall[i].pst_stime * 10;
236
205
pt[i].cpu_percent = (int)(1000. * psall[i].pst_pctcpu / (float)systeminfo.cpus);
237
pt[i].mem_kbyte = (unsigned long)(psall[i].pst_rssize * (page_size / 1024.0));
239
/* State is Zombie -> then we are a Zombie ... clear or? (-: */
241
if ( psall[i].pst_stat == PS_ZOMBIE ) {
206
pt[i].mem_kbyte = (unsigned long)(psall[i].pst_rssize * (page_size / 1024.0));
208
if ( psall[i].pst_stat == PS_ZOMBIE )
243
209
pt[i].status_flag |= PROCESS_ZOMBIE;
293
253
pstat_getdynamic(&psd, sizeof(psd), 1, 0);
295
255
for(i = 0; i < CPUSTATES; i++)
297
256
cpu_total_new += psd.psd_cpu_time[i];
299
257
cpu_total = cpu_total_new - cpu_total_old;
300
258
cpu_total_old = cpu_total_new;
301
259
cpu_user = psd.psd_cpu_time[CP_USER] + psd.psd_cpu_time[CP_NICE];
302
260
cpu_syst = psd.psd_cpu_time[CP_SYS];
303
261
cpu_wait = psd.psd_cpu_time[CP_WAIT];
305
si->total_cpu_user_percent =
306
(cpu_total > 0)?(int)(1000 * (double)(cpu_user - cpu_user_old) / cpu_total):-10;
307
si->total_cpu_syst_percent =
308
(cpu_total > 0)?(int)(1000 * (double)(cpu_syst - cpu_syst_old) / cpu_total):-10;
309
si->total_cpu_wait_percent =
310
(cpu_total > 0)?(int)(1000 * (double)(cpu_wait - cpu_wait_old) / cpu_total):-10;
263
si->total_cpu_user_percent = (cpu_total > 0)?(int)(1000 * (double)(cpu_user - cpu_user_old) / cpu_total):-10;
264
si->total_cpu_syst_percent = (cpu_total > 0)?(int)(1000 * (double)(cpu_syst - cpu_syst_old) / cpu_total):-10;
265
si->total_cpu_wait_percent = (cpu_total > 0)?(int)(1000 * (double)(cpu_wait - cpu_wait_old) / cpu_total):-10;
312
267
cpu_user_old = cpu_user;
313
268
cpu_syst_old = cpu_syst;