SolarisProcessList.c 20.8 KB
Newer Older
gmbroome's avatar
gmbroome committed
1
2
3
/*
htop - SolarisProcessList.c
(C) 2014 Hisham H. Muhammad
4
(C) 2017,2018 Guy M. Broome
gmbroome's avatar
gmbroome committed
5
6
7
8
9
10
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/

#include "ProcessList.h"
#include "SolarisProcess.h"
11
#include "SolarisProcessList.h"
gmbroome's avatar
gmbroome committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/user.h>
#include <err.h>
#include <fcntl.h>
#include <limits.h>
#include <string.h>
#include <procfs.h>
#include <errno.h>
#include <pwd.h>
#include <dirent.h>
#include <math.h>
#include <time.h>

#define MAXCMDLINE 255

/*{

#include <kstat.h>
#include <sys/param.h>
34
#include <zone.h>
gmbroome's avatar
gmbroome committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <sys/uio.h>
#include <sys/resource.h>
#include <sys/sysconf.h>
#include <sys/sysinfo.h>
#include <sys/swap.h>

#define ZONE_ERRMSGLEN 1024
char zone_errmsg[ZONE_ERRMSGLEN];

typedef struct CPUData_ {
   double userPercent;
   double nicePercent;
   double systemPercent;
   double irqPercent;
   double idlePercent;
   double systemAllPercent;
   uint64_t luser;
   uint64_t lkrnl;
   uint64_t lintr;
   uint64_t lidle;
} CPUData;

typedef struct SolarisProcessList_ {
   ProcessList super;
   kstat_ctl_t* kd;
   CPUData* cpus;
} SolarisProcessList;

}*/

65
66
char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) {
  char* zname;
gmbroome's avatar
gmbroome committed
67
  if ( sproc->zoneid == 0 ) {
68
     zname = xStrdup("global    ");
gmbroome's avatar
gmbroome committed
69
  } else if ( kd == NULL ) {
70
     zname = xStrdup("unknown   ");
gmbroome's avatar
gmbroome committed
71
72
  } else {
     kstat_t* ks = kstat_lookup( kd, "zones", sproc->zoneid, NULL );
73
     zname = xStrdup(ks->ks_name);
gmbroome's avatar
gmbroome committed
74
  }
75
  return zname;
gmbroome's avatar
gmbroome committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
}

ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
   SolarisProcessList* spl = xCalloc(1, sizeof(SolarisProcessList));
   ProcessList* pl = (ProcessList*) spl;
   ProcessList_init(pl, Class(SolarisProcess), usersTable, pidWhiteList, userId);

   spl->kd = kstat_open();

   pl->cpuCount = sysconf(_SC_NPROCESSORS_ONLN);

   if (pl->cpuCount == 1 ) {
      spl->cpus = xRealloc(spl->cpus, sizeof(CPUData));
   } else {
      spl->cpus = xRealloc(spl->cpus, (pl->cpuCount + 1) * sizeof(CPUData));
   }

   return pl;
}

static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) {
   const SolarisProcessList* spl = (SolarisProcessList*) pl;
   int cpus = pl->cpuCount;
   kstat_t *cpuinfo = NULL;
   int kchain = 0;
   kstat_named_t *idletime = NULL;
   kstat_named_t *intrtime = NULL;
   kstat_named_t *krnltime = NULL;
   kstat_named_t *usertime = NULL;
   double idlebuf = 0;
   double intrbuf = 0;
   double krnlbuf = 0;
   double userbuf = 0;
   uint64_t totaltime = 0;
   int arrskip = 0;

   assert(cpus > 0);

   if (cpus > 1) {
       // Store values for the stats loop one extra element up in the array
       // to leave room for the average to be calculated afterwards
       arrskip++;
   }

   // Calculate per-CPU statistics first
   for (int i = 0; i < cpus; i++) {
      if (spl->kd != NULL) { cpuinfo = kstat_lookup(spl->kd,"cpu",i,"sys"); }
      if (cpuinfo != NULL) { kchain = kstat_read(spl->kd,cpuinfo,NULL); }
      if (kchain  != -1  ) {
         idletime = kstat_data_lookup(cpuinfo,"cpu_nsec_idle");
         intrtime = kstat_data_lookup(cpuinfo,"cpu_nsec_intr");
         krnltime = kstat_data_lookup(cpuinfo,"cpu_nsec_kernel");
         usertime = kstat_data_lookup(cpuinfo,"cpu_nsec_user");
      }

      assert( (idletime != NULL) && (intrtime != NULL)
           && (krnltime != NULL) && (usertime != NULL) );

      CPUData* cpuData = &(spl->cpus[i+arrskip]);
      totaltime = (idletime->value.ui64 - cpuData->lidle)
                + (intrtime->value.ui64 - cpuData->lintr)
                + (krnltime->value.ui64 - cpuData->lkrnl)
                + (usertime->value.ui64 - cpuData->luser);
      // Calculate percentages of deltas since last reading
      cpuData->userPercent      = ((usertime->value.ui64 - cpuData->luser) / (double)totaltime) * 100.0;
      cpuData->nicePercent      = (double)0.0; // Not implemented on Solaris
      cpuData->systemPercent    = ((krnltime->value.ui64 - cpuData->lkrnl) / (double)totaltime) * 100.0;
      cpuData->irqPercent       = ((intrtime->value.ui64 - cpuData->lintr) / (double)totaltime) * 100.0;
      cpuData->systemAllPercent = cpuData->systemPercent + cpuData->irqPercent;
      cpuData->idlePercent      = ((idletime->value.ui64 - cpuData->lidle) / (double)totaltime) * 100.0;
      // Store current values to use for the next round of deltas
      cpuData->luser            = usertime->value.ui64;
      cpuData->lkrnl            = krnltime->value.ui64;
      cpuData->lintr            = intrtime->value.ui64;
      cpuData->lidle            = idletime->value.ui64;
      // Accumulate the current percentages into buffers for later average calculation
      if (cpus > 1) {
         userbuf               += cpuData->userPercent;
         krnlbuf               += cpuData->systemPercent;
         intrbuf               += cpuData->irqPercent;
         idlebuf               += cpuData->idlePercent;
      }
   }
   
   if (cpus > 1) {
      CPUData* cpuData          = &(spl->cpus[0]);
      cpuData->userPercent      = userbuf / cpus;
      cpuData->nicePercent      = (double)0.0; // Not implemented on Solaris
      cpuData->systemPercent    = krnlbuf / cpus;
      cpuData->irqPercent       = intrbuf / cpus;
      cpuData->systemAllPercent = cpuData->systemPercent + cpuData->irqPercent;
      cpuData->idlePercent      = idlebuf / cpus;
   }
}

static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) {
   SolarisProcessList* spl = (SolarisProcessList*) pl;
   kstat_t             *meminfo = NULL;
   int                 ksrphyserr = 0;
   kstat_named_t       *totalmem_pgs = NULL;
   kstat_named_t       *lockedmem_pgs = NULL;
   kstat_named_t       *pages = NULL;
   struct swaptable    *sl = NULL;
   struct swapent      *swapdev = NULL;
   uint64_t            totalswap = 0;
   uint64_t            totalfree = 0;
   int                 nswap = 0;
   char                *spath = NULL; 
   // PAGE_SIZE is a macro to a function call.
   // Since we use it so much in here, go ahead copy
   // the value locally.
   int              pgsiz = PAGE_SIZE;

   // Part 1 - physical memory
   if (spl->kd != NULL) { meminfo    = kstat_lookup(spl->kd,"unix",0,"system_pages"); }
   if (meminfo != NULL) { ksrphyserr = kstat_read(spl->kd,meminfo,NULL); }
   if (ksrphyserr != -1) {
      totalmem_pgs   = kstat_data_lookup( meminfo, "physmem" );
      lockedmem_pgs  = kstat_data_lookup( meminfo, "pageslocked" );
      pages          = kstat_data_lookup( meminfo, "pagestotal" );

      pl->totalMem   = ((totalmem_pgs->value.ui64)/1024)  * pgsiz;
      pl->usedMem    = ((lockedmem_pgs->value.ui64)/1024) * pgsiz;
      // Not sure how to implement this on Solaris - suggestions welcome!
      pl->cachedMem  = 0;     
      // Not really "buffers" but the best Solaris analogue that I can find to
      // "memory in use but not by programs or the kernel itself"
      pl->buffersMem = (((totalmem_pgs->value.ui64)/1024) - (pages->value.ui64)/1024) * pgsiz;
   } else {
      // Fall back to basic sysconf if kstat isn't working
      pl->totalMem = sysconf(_SC_PHYS_PAGES) * pgsiz;
      pl->buffersMem = 0;
      pl->cachedMem  = 0;
      pl->usedMem    = pl->totalMem - (sysconf(_SC_AVPHYS_PAGES) * pgsiz);
   }
   
   // Part 2 - swap
   nswap = swapctl(SC_GETNSWP, NULL);
   if (nswap >     0) { sl  = malloc(nswap * sizeof(swapent_t) + sizeof(int)); }
   if (sl    != NULL) { spath = malloc( nswap * MAXPATHLEN ); }
   if (spath != NULL) { 
      swapdev = sl->swt_ent;
      for (int i = 0; i < nswap; i++, swapdev++) {
         swapdev->ste_path = spath;
         spath += MAXPATHLEN;
      }
      sl->swt_n = nswap;
   }
   nswap = swapctl(SC_LIST, sl);
   if (nswap > 0) { 
      swapdev = sl->swt_ent;
      for (int i = 0; i < nswap; i++, swapdev++) {
         totalswap += swapdev->ste_pages;
         totalfree += swapdev->ste_free;
         free(swapdev->ste_path);
      }
      free(sl);
   }
   pl->totalSwap = (totalswap * pgsiz)/1024;
   pl->usedSwap  = pl->totalSwap - ((totalfree * pgsiz)/1024); 
}

void ProcessList_delete(ProcessList* this) {
   const SolarisProcessList* spl = (SolarisProcessList*) this;
   if (spl->kd) kstat_close(spl->kd);
   free(spl->cpus);
   ProcessList_done(this);
   free(this);
}

246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
void ProcessList_enumerateLWPs(Process* proc, char* name, ProcessList* pl, struct timeval tv) {
   Process *lwp;
   SolarisProcess *slwp;
   SolarisProcess *sproc = (SolarisProcess*) proc;
   Settings* settings = pl->settings;
   bool hideKernelThreads = settings->hideKernelThreads;
   bool hideUserlandThreads = settings->hideUserlandThreads;
   char lwpdir[MAX_NAME+1];
   DIR* dir = NULL;
   FILE* fp = NULL;
   pid_t lwpid;
   bool preExisting = false;   
   char filename[MAX_NAME+1];
   lwpsinfo_t _lwpsinfo;
   prusage_t _lwprusage;
   struct tm date;
   xSnprintf(lwpdir, MAX_NAME, "%s/%s/lwp", PROCDIR, name);
   struct dirent* entry;
   char* lwpname;
   bool haveUsage = false;

   dir = opendir(lwpdir);
   if (!dir) return;
   while ((entry = readdir(dir)) != NULL) {
      lwpname = entry->d_name;
      // With 10 bits to spare, we can only list up to 1023 unique LWPs per process
      if (atoi(lwpname) > 1023) break;
      lwpid   = proc->pid + atoi(lwpname);
      lwp     = ProcessList_getProcess(pl, lwpid, &preExisting, (Process_New) SolarisProcess_new);
      slwp    = (SolarisProcess*) lwp;
      xSnprintf(filename, MAX_NAME, "%s/%s/lwp/%s/lwpsinfo", PROCDIR, name, lwpname);
      fp   = fopen(filename, "r");
      if ( fp == NULL ) continue;
      fread(&_lwpsinfo,sizeof(lwpsinfo_t),1,fp);
      fclose(fp);
      xSnprintf(filename, MAX_NAME, "%s/%s/lwp/%s/lwpusage", PROCDIR, name, lwpname);
      fp   = fopen(filename, "r");
      if ( fp != NULL ) {
         haveUsage = true;
         fread(&_lwprusage,sizeof(prusage_t),1,fp);
         fclose(fp);
      }
      slwp->is_lwp = TRUE;

      if (!preExisting) {
         lwp->basenameOffset  = -1;
         slwp->kernel         = sproc->kernel;
         // Fake values used for sorting
         lwp->pid             = lwpid;
         lwp->ppid            = proc->pid;
         lwp->tgid            = proc->pid;
         // Corresponding real values used for display
         slwp->realpid        = sproc->realpid;
         slwp->realppid       = sproc->realpid;
         slwp->lwpid          = atoi(lwpname);
         slwp->zoneid         = sproc->zoneid;
         lwp->tty_nr          = proc->tty_nr;
         lwp->pgrp            = proc->pgrp;
         lwp->percent_cpu     = ((uint16_t)_lwpsinfo.pr_pctcpu/(double)32768)*(double)100.0;
         // Not tracked per thread
         lwp->percent_mem     = (double)0.0;
         lwp->st_uid          = proc->st_uid;
         lwp->user            = UsersTable_getRef(pl->usersTable, lwp->st_uid);
         lwp->nlwp            = 0;
         lwp->session         = proc->session;
         lwp->comm            = xStrdup(proc->comm);
         lwp->commLen         = strnlen(proc->comm,PRFNSZ);
         slwp->zname          = sproc->zname;
         if (haveUsage) {
            lwp->majflt       = _lwprusage.pr_majf;
            lwp->minflt       = _lwprusage.pr_minf;
         } else {
            lwp->majflt       = 0;
            lwp->minflt       = 0;
         }
         lwp->m_resident      = 0;
         lwp->m_size          = 0;
         lwp->priority        = _lwpsinfo.pr_pri;
         lwp->nice            = _lwpsinfo.pr_nice;
         lwp->processor       = _lwpsinfo.pr_onpro;
         lwp->state           = _lwpsinfo.pr_sname;
         lwp->time            = _lwpsinfo.pr_time.tv_sec;
         slwp->taskid         = sproc->taskid;
         slwp->projid         = sproc->projid;
         slwp->poolid         = sproc->poolid;
         slwp->contid         = sproc->contid;
         lwp->starttime_ctime = _lwpsinfo.pr_start.tv_sec;
         (void) localtime_r((time_t*) &lwp->starttime_ctime, &date);
         strftime(lwp->starttime_show, 7, ((lwp->starttime_ctime > tv.tv_sec - 86400) ? "%R " : "%b%d "), &date);
         ProcessList_add(pl, lwp);
      } else {
         slwp->zoneid         = sproc->zoneid;
         lwp->pgrp            = proc->pgrp;
         lwp->percent_cpu     = ((uint16_t)_lwpsinfo.pr_pctcpu/(double)32768)*(double)100.0;
         // Not tracked per thread
         lwp->percent_mem     = (double)0.0;
         lwp->st_uid          = proc->st_uid;
         lwp->user            = UsersTable_getRef(pl->usersTable, lwp->st_uid);
         lwp->nlwp            = 0;
         lwp->session         = proc->session;
         lwp->comm            = xStrdup(proc->comm);
         lwp->commLen         = strnlen(proc->comm,PRFNSZ);
         slwp->zname          = sproc->zname;
         if (haveUsage) {
            lwp->majflt       = _lwprusage.pr_majf;
            lwp->minflt       = _lwprusage.pr_minf;
         }
         lwp->m_resident      = 0;
         lwp->m_size          = 0;
         lwp->priority        = _lwpsinfo.pr_pri;
         lwp->nice            = _lwpsinfo.pr_nice;
         lwp->processor       = _lwpsinfo.pr_onpro;
         lwp->state           = _lwpsinfo.pr_sname;
         lwp->time            = _lwpsinfo.pr_time.tv_sec;
         slwp->taskid         = sproc->taskid;
         slwp->projid         = sproc->projid;
         slwp->poolid         = sproc->poolid;
         slwp->contid         = sproc->contid;
      }
365
366
      // Top-level process only gets this for the representative LWP
      if (lwp->state == 'O') proc->state = 'O';
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
      if (slwp->kernel) {
         if(!hideKernelThreads) {
            lwp->show = true;
         } else {
            lwp->show = false;
         }
      } else {
         if(!hideUserlandThreads) {
            lwp->show = true;
         } else {
            lwp->show = false;
         }
      }
      lwp->updated = true;
   }
   closedir(dir);
}


gmbroome's avatar
gmbroome committed
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
void ProcessList_goThroughEntries(ProcessList* this) {
   SolarisProcessList* spl = (SolarisProcessList*) this;
   Settings* settings = this->settings;
   bool hideKernelThreads = settings->hideKernelThreads;
   bool hideUserlandThreads = settings->hideUserlandThreads;
   DIR* dir = NULL;
   struct dirent* entry = NULL;
   char*  name = NULL;
   int    pid;
   bool   preExisting = false;
   Process* proc = NULL;
   SolarisProcess* sproc = NULL;
   psinfo_t _psinfo;
   pstatus_t _pstatus;
   prusage_t _prusage;
   char filename[MAX_NAME+1];
   FILE *fp = NULL;
   uint64_t addRunning = 0;
   uint64_t addTotal = 0;
   struct timeval tv;
   struct tm date;

   gettimeofday(&tv, NULL);

   // If these fail, then the relevant metrics will simply display as zero
   SolarisProcessList_scanCPUTime(this);
   SolarisProcessList_scanMemoryInfo(this);

   dir = opendir(PROCDIR); 
   if (!dir) return; // Is proc mounted?
   while ((entry = readdir(dir)) != NULL) {
      addRunning = 0;
      addTotal = 0;
      name = entry->d_name;
      pid = atoi(name);
      proc = ProcessList_getProcess(this, pid, &preExisting, (Process_New) SolarisProcess_new);
      sproc = (SolarisProcess *) proc;
      xSnprintf(filename, MAX_NAME, "%s/%s/psinfo", PROCDIR, name);
      fp = fopen(filename, "r");
      if ( fp == NULL ) continue;
      fread(&_psinfo,sizeof(psinfo_t),1,fp);
      fclose(fp);
      xSnprintf(filename, MAX_NAME, "%s/%s/status", PROCDIR, name);
      fp   = fopen(filename, "r");
      if ( fp != NULL ) {
         fread(&_pstatus,sizeof(pstatus_t),1,fp);
      }
      fclose(fp);
      xSnprintf(filename, MAX_NAME, "%s/%s/usage", PROCDIR, name);
      fp = fopen(filename,"r");
      if ( fp == NULL ) continue;
      fread(&_prusage,sizeof(prusage_t),1,fp);
      fclose(fp);
439
      sproc->is_lwp = FALSE;
440

gmbroome's avatar
gmbroome committed
441
      if(!preExisting) {
442
443
444
445
446
447
448
449
         // Fake PID values used for sorting, since Solaris LWPs lack unique PIDs
         proc->pid             = (_psinfo.pr_pid * 1024);
         proc->ppid            = (_psinfo.pr_ppid * 1024); 
         proc->tgid            = (_psinfo.pr_ppid * 1024);
         // Corresponding real values used for display
         sproc->realpid        = _psinfo.pr_pid;
         sproc->realppid       = _psinfo.pr_ppid;
         sproc->lwpid          = 0; 
gmbroome's avatar
gmbroome committed
450
451
452
453
454
455
456
457
458
459
460
461
         sproc->zoneid         = _psinfo.pr_zoneid;
         proc->tty_nr          = _psinfo.pr_ttydev;
         proc->pgrp            = _psinfo.pr_pgid;
         // NOTE: These 'percentages' are 16-bit BINARY FRACTIONS where 1.0 = 0x8000
         // Source: https://docs.oracle.com/cd/E19253-01/816-5174/proc-4/index.html
         // (accessed on 18 November 2017)
         proc->percent_cpu     = ((uint16_t)_psinfo.pr_pctcpu/(double)32768)*(double)100.0;
         proc->percent_mem     = ((uint16_t)_psinfo.pr_pctmem/(double)32768)*(double)100.0;
         proc->st_uid          = _psinfo.pr_euid;
         proc->user            = UsersTable_getRef(this->usersTable, proc->st_uid);
         proc->nlwp            = _psinfo.pr_nlwp;
         proc->session         = _pstatus.pr_sid;
462
463
         proc->comm            = xStrdup(_psinfo.pr_fname);
         proc->commLen         = strnlen(_psinfo.pr_fname,PRFNSZ); 
464
         sproc->zname          = SolarisProcessList_readZoneName(spl->kd,sproc);
gmbroome's avatar
gmbroome committed
465
466
         proc->majflt          = _prusage.pr_majf;
         proc->minflt          = _prusage.pr_minf; 
467
468
         proc->m_resident      = _psinfo.pr_rssize/PAGE_SIZE_KB;
         proc->m_size          = _psinfo.pr_size/PAGE_SIZE_KB;
gmbroome's avatar
gmbroome committed
469
470
471
472
473
474
475
476
477
478
         proc->priority        = _psinfo.pr_lwp.pr_pri;
         proc->nice            = _psinfo.pr_lwp.pr_nice;
         proc->processor       = _psinfo.pr_lwp.pr_onpro;
         proc->state           = _psinfo.pr_lwp.pr_sname;
         proc->time            = _psinfo.pr_time.tv_sec;
         sproc->taskid         = _psinfo.pr_taskid;
         sproc->projid         = _psinfo.pr_projid;
         sproc->poolid         = _psinfo.pr_poolid;
         sproc->contid         = _psinfo.pr_contract;
         proc->starttime_ctime = _psinfo.pr_start.tv_sec;
479
480
481
482
483
         if ((sproc->realppid <= 0) && !(sproc->realpid <= 1)) {
            sproc->kernel = true;
         } else {
            sproc->kernel = false;
         }
gmbroome's avatar
gmbroome committed
484
485
486
487
         (void) localtime_r((time_t*) &proc->starttime_ctime, &date);
         strftime(proc->starttime_show, 7, ((proc->starttime_ctime > tv.tv_sec - 86400) ? "%R " : "%b%d "), &date); 
         ProcessList_add(this, proc);
      } else {
488
489
490
491
         proc->ppid            = (_psinfo.pr_ppid * 1024);
         proc->tgid            = (_psinfo.pr_ppid * 1024);
         sproc->realppid       = _psinfo.pr_ppid;
         sproc->lwpid          = 0; 
gmbroome's avatar
gmbroome committed
492
493
494
495
496
497
498
499
         sproc->zoneid         = _psinfo.pr_zoneid;
         // See note above about these percentages
         proc->percent_cpu     = ((uint16_t)_psinfo.pr_pctcpu/(double)32768)*(double)100.0;
         proc->percent_mem     = ((uint16_t)_psinfo.pr_pctmem/(double)32768)*(double)100.0;
         proc->st_uid          = _psinfo.pr_euid;
         proc->pgrp            = _psinfo.pr_pgid;
         proc->nlwp            = _psinfo.pr_nlwp;
         proc->user            = UsersTable_getRef(this->usersTable, proc->st_uid);
gmbroome's avatar
gmbroome committed
500
         proc->comm            = xStrdup(_psinfo.pr_fname);
501
         proc->commLen         = strnlen(_psinfo.pr_fname,PRFNSZ);
502
         sproc->zname          = SolarisProcessList_readZoneName(spl->kd,sproc);
gmbroome's avatar
gmbroome committed
503
504
         proc->majflt          = _prusage.pr_majf;
         proc->minflt          = _prusage.pr_minf;
505
506
         proc->m_resident      = _psinfo.pr_rssize/PAGE_SIZE_KB; 
         proc->m_size          = _psinfo.pr_size/PAGE_SIZE_KB; 
gmbroome's avatar
gmbroome committed
507
508
509
510
511
512
513
514
515
516
         proc->priority        = _psinfo.pr_lwp.pr_pri;
         proc->nice            = _psinfo.pr_lwp.pr_nice;
         proc->processor       = _psinfo.pr_lwp.pr_onpro;
         proc->state           = _psinfo.pr_lwp.pr_sname;
         proc->time            = _psinfo.pr_time.tv_sec;
         sproc->taskid         = _psinfo.pr_taskid;
         sproc->projid         = _psinfo.pr_projid;
         sproc->poolid         = _psinfo.pr_poolid;
         sproc->contid         = _psinfo.pr_contract;
      }
517
518
519
520
521
      if (proc->nlwp > 1) {
         ProcessList_enumerateLWPs(proc, name, this, tv);
      }
      proc->show = !(hideKernelThreads && sproc->kernel);
      if (_pstatus.pr_flags & sproc->kernel) {
gmbroome's avatar
gmbroome committed
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
         if (hideKernelThreads) {
            addRunning = 0;
            addTotal   = 0;
         } else {
            this->kernelThreads += proc->nlwp;
            if (proc->state == 'O') {
               addRunning++;
               addTotal = proc->nlwp+1;
            } else {
               addTotal = proc->nlwp+1;
            }
         }
      } else {
         if (hideUserlandThreads) {
            if(proc->state == 'O') {
               addRunning++;
               addTotal++;
            } else {
               addTotal++;
            }
         } else {
            this->userlandThreads += proc->nlwp;
            if(proc->state == 'O') {
               addRunning++;
               addTotal = proc->nlwp+1;
            } else {
               addTotal = proc->nlwp+1;
            }
         }
      }
      this->runningTasks+=addRunning;
      this->totalTasks+=addTotal;
      proc->updated = true;
   } // while ((entry = readdir(dir)) != NULL)
   closedir(dir);
}