o better format byte size data

o ivar names changes to conform to coding standards


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@18141 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Manuel Guesdon 2003-11-24 09:02:57 +00:00
parent a4f4bede38
commit 1e4a2c3607
2 changed files with 384 additions and 293 deletions

View file

@ -38,54 +38,54 @@ typedef enum _GSWProcState
} GSWProcState;
@interface GSWProcFSProcInfo : NSObject <NSCoding,NSCopying>
{
NSString* user; // user name corresponding to owner of process [/proc/#/stat]
NSString* cmd; // basename of executable file in call to exec(2) [/proc/#/stat]
GSWProcState state; // single-char code for process state (S=sleeping) [/proc/#/stat]
NSString* ttyc; // string representation of controlling tty device [/proc/#/stat]
NSArray* environ; // environment string vector (/proc/#/environ)
NSArray* cmdline; // command line string vector (/proc/#/cmdline)
uid_t uid; // user id
pid_t pid; // process id [/proc/#/stat]
pid_t ppid; // pid of parent process [/proc/#/stat]
pid_t pgrp; // process group id [/proc/#/stat]
int session; // session id [/proc/#/stat]
int tty; // full device number of controlling terminal [/proc/#/stat]
pid_t tpgid; // terminal process group id [/proc/#/stat]
int priority; // kernel scheduling priority [/proc/#/stat]
int nice; // standard unix nice level of process [/proc/#/stat]
long long signal; // mask of pending signals [/proc/#/stat]
long long blocked; // mask of blocked signals [/proc/#/stat]
long long sigIgnore; // mask of ignored signals [/proc/#/stat]
long long sigCatch; // mask of caught signals [/proc/#/stat]
NSTimeInterval startTime; // start time of process (Absolute)[/proc/#/stat]
NSTimeInterval userTime; // user-mode CPU time accumulated by process [/proc/#/stat]
NSTimeInterval systemTime; // kernel-mode CPU time accumulated by process [/proc/#/stat]
NSTimeInterval cumulativeUserTime; // cumulative utime of process and reaped children [/proc/#/stat]
NSTimeInterval cumulativeSystemTime; // cumulative stime of process and reaped children [/proc/#/stat]
long pagesNb; // total # of pages of memory [/proc/#/statm]
long residentPagesNb; // number of resident set (non-swapped) pages (4k) [/proc/#/statm]
long sharedPagesNb; // number of pages of shared (mmap'd) memory [/proc/#/statm]
long textResidentSize; // text resident set size [/proc/#/statm]
long sharedLibResidentSize; // shared-lib resident set size [/proc/#/statm]
long dataResidentSize; // data resident set size [/proc/#/statm]
long dirtyPagesNb; // dirty pages [/proc/#/statm]
unsigned cpuUsagePC; // %CPU usage (is not filled in by readproc!!!)
unsigned long virtualPagesNb; // number of pages of virtual memory ... [/proc/#/stat]
unsigned long residentMemorySize; // resident set size from /proc/#/stat
unsigned long residentMemorySizeLimit; // resident set size ... ?
unsigned long timeout; // ? [/proc/#/stat]
unsigned long it_real_value; // ? [/proc/#/stat]
unsigned long flags; // kernel flags for the process [/proc/#/stat]
unsigned long minorPageFaultNb; // number of minor page faults since process start [/proc/#/stat]
unsigned long majorPageFaultNb; // number of major page faults since process start [/proc/#/stat]
unsigned long cumulativeMinorPageFaultNb; // cumulative min_flt of process and child processes [/proc/#/stat]
unsigned long cumulativeMajorPageFaultNb; // cumulative maj_flt of process and child processes [/proc/#/stat]
unsigned long startCodeAddress; // address of beginning of code segment [/proc/#/stat]
unsigned long endCodeAddress; // address of end of code segment [/proc/#/stat]
unsigned long startStackAddress; // address of the bottom of stack for the process [/proc/#/stat]
unsigned long kernelStackPointerESP; // kernel stack pointer [/proc/#/stat]
unsigned long kernelStackPointerEIP; // kernel stack pointer [/proc/#/stat]
unsigned long kernelWaitChannelProc; // address of kernel wait channel proc is sleeping in [/proc/#/stat]
NSString* _user; // user name corresponding to owner of process [/proc/#/stat]
NSString* _command; // basename of executable file in call to exec(2) [/proc/#/stat]
GSWProcState _state; // single-char code for process state (S=sleeping) [/proc/#/stat]
NSString* _ttyc; // string representation of controlling tty device [/proc/#/stat]
NSArray* _environ; // environment string vector (/proc/#/environ)
NSArray* _commandLine; // command line string vector (/proc/#/cmdline)
uid_t _uid; // user id
pid_t _pid; // process id [/proc/#/stat]
pid_t _ppid; // pid of parent process [/proc/#/stat]
pid_t _pgrp; // process group id [/proc/#/stat]
int _session; // session id [/proc/#/stat]
int _tty; // full device number of controlling terminal [/proc/#/stat]
pid_t _tpgid; // terminal process group id [/proc/#/stat]
int _priority; // kernel scheduling priority [/proc/#/stat]
int _nice; // standard unix nice level of process [/proc/#/stat]
long long _signal; // mask of pending signals [/proc/#/stat]
long long _blocked; // mask of blocked signals [/proc/#/stat]
long long _sigIgnore; // mask of ignored signals [/proc/#/stat]
long long _sigCatch; // mask of caught signals [/proc/#/stat]
NSTimeInterval _startTime; // start time of process (Absolute)[/proc/#/stat]
NSTimeInterval _userTime; // user-mode CPU time accumulated by process [/proc/#/stat]
NSTimeInterval _systemTime; // kernel-mode CPU time accumulated by process [/proc/#/stat]
NSTimeInterval _cumulativeUserTime; // cumulative utime of process and reaped children [/proc/#/stat]
NSTimeInterval _cumulativeSystemTime; // cumulative stime of process and reaped children [/proc/#/stat]
long _pagesNb; // total # of pages of memory [/proc/#/statm]
long _residentPagesNb; // number of resident set (non-swapped) pages (4k) [/proc/#/statm]
long _sharedPagesNb; // number of pages of shared (mmap'd) memory [/proc/#/statm]
long _textResidentSize; // text resident set size [/proc/#/statm]
long _sharedLibResidentSize; // shared-lib resident set size [/proc/#/statm]
long _dataResidentSize; // data resident set size [/proc/#/statm]
long _dirtyPagesNb; // dirty pages [/proc/#/statm]
unsigned _cpuUsagePC; // %CPU usage (is not filled in by readproc!!!)
unsigned long _virtualMemorySize; // Virtual memory size in bytes ... [/proc/#/stat]
unsigned long _residentMemorySize; // resident set size from /proc/#/stat
unsigned long _residentMemorySizeLimit; // resident set size ... ?
unsigned long _timeout; // ? [/proc/#/stat]
unsigned long _it_real_value; // ? [/proc/#/stat]
unsigned long _flags; // kernel flags for the process [/proc/#/stat]
unsigned long _minorPageFaultNb; // number of minor page faults since process start [/proc/#/stat]
unsigned long _majorPageFaultNb; // number of major page faults since process start [/proc/#/stat]
unsigned long _cumulativeMinorPageFaultNb; // cumulative min_flt of process and child processes [/proc/#/stat]
unsigned long _cumulativeMajorPageFaultNb; // cumulative maj_flt of process and child processes [/proc/#/stat]
unsigned long _startCodeAddress; // address of beginning of code segment [/proc/#/stat]
unsigned long _endCodeAddress; // address of end of code segment [/proc/#/stat]
unsigned long _startStackAddress; // address of the bottom of stack for the process [/proc/#/stat]
unsigned long _kernelStackPointerESP; // kernel stack pointer [/proc/#/stat]
unsigned long _kernelStackPointerEIP; // kernel stack pointer [/proc/#/stat]
unsigned long _kernelWaitChannelProc; // address of kernel wait channel proc is sleeping in [/proc/#/stat]
};
+(GSWProcFSProcInfo*)filledProcInfo;
@ -97,6 +97,16 @@ typedef enum _GSWProcState
-(NSString*)contentOfPIDFile:(NSString*)pidFile;
-(BOOL)fillStatm;
-(BOOL)fillStat;
-(unsigned int)residentMemory;
-(unsigned int)sharedMemory;
-(unsigned int)virtualMemory;
-(unsigned int)swapMemory;
-(unsigned int)usedMemory;
-(NSString*)formattedResidentMemory;
-(NSString*)formattedSharedMemory;
-(NSString*)formattedVirtualMemory;
-(NSString*)formattedSwapMemory;
-(NSString*)formattedUsedMemory;
@end

View file

@ -1,11 +1,21 @@
/* GSWProcFS - /proc management
Copyright (C) 1999 Free Software Foundation, Inc.
/** GSWProcFS.m - <title>GSWeb: Class GSWApplication</title>
Copyright (C) 1999-2003 Free Software Foundation, Inc.
Written by: Manuel Guesdon <mguesdon@sbuilders.com>
Date: Oct 1999
Written by: Manuel Guesdon <mguesdon@orange-concept.com>
Date: Oct 1999
$Revision$
$Date$
$Id$
This file is part of the GNUstep Web Library.
<abstract>
/proc management
</abstract>
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
@ -19,7 +29,8 @@
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
</license>
**/
#include "config.h"
@ -29,6 +40,18 @@ RCS_ID("$Id$")
#include <unistd.h>
#include <sys/time.h>
NSString* formattedByteSizeValue(unsigned int value)
{
if (value<1024)
return [NSString stringWithFormat:@"%lu b",value];
else if (value<1024L*1024L)
return [NSString stringWithFormat:@"%.3f Kb",(((double)value)/1024)];
else if (value<1024L*1024L*1024L)
return [NSString stringWithFormat:@"%.3f Mb",(((double)value)/(1024L*1024L))];
else
return [NSString stringWithFormat:@"%.3f Gb",(((double)value)/(1024L*1024L*1024L))];
};
@implementation GSWProcFSProcInfo
+(GSWProcFSProcInfo*)filledProcInfo
@ -42,11 +65,11 @@ RCS_ID("$Id$")
return obj;
};
-(id)initFilledWithPID:(pid_t)pid_
-(id)initFilledWithPID:(pid_t)pid
{
if ((self=[super init]))
{
pid=pid_;
_pid=pid;
[self fill];
};
return self;
@ -54,99 +77,98 @@ RCS_ID("$Id$")
-(void)dealloc
{
DESTROY(user);
DESTROY(cmd);
DESTROY(ttyc);
DESTROY(environ);
DESTROY(cmdline);
DESTROY(_user);
DESTROY(_command);
DESTROY(_ttyc);
DESTROY(_environ);
DESTROY(_commandLine);
[super dealloc];
};
-(NSString*)description
{
NSString* dscr=nil;
size_t _pageSize=getpagesize();
char* _state=NULL;
switch(state)
{
case GSWProcState__Sleeping:
_state="Sleeping";
break;
case GSWProcState__Running:
_state="Running";
break;
case GSWProcState__Zombie:
_state="Zombie";
break;
case GSWProcState__Stopped:
_state="Stopped";
break;
case GSWProcState__SleepWait:
_state="Waiting-Sleeping";
break;
case GSWProcState__Unknown:
default:
_state="Unknown";
break;
};
size_t pageSize=getpagesize();
char* stateCString=NULL;
switch(_state)
{
case GSWProcState__Sleeping:
stateCString="Sleeping";
break;
case GSWProcState__Running:
stateCString="Running";
break;
case GSWProcState__Zombie:
stateCString="Zombie";
break;
case GSWProcState__Stopped:
stateCString="Stopped";
break;
case GSWProcState__SleepWait:
stateCString="Waiting-Sleeping";
break;
case GSWProcState__Unknown:
default:
stateCString="Unknown";
break;
};
dscr=[NSString stringWithFormat:@"user: %@\ncmd: %@\nState: %s\nttyc: %@\nenviron: %@\ncommand line:%@\n",
user,
cmd,
_state,
ttyc,
environ,
cmdline];
_user,
_command,
stateCString,
_ttyc,
_environ,
_commandLine];
dscr=[dscr stringByAppendingFormat:@"uid: %d\npid: %d\nppid: %d\npgrp: %d\nsession: %d\ntty: %d\ntpgid: %d\npriority: %d\nnice: %d\nsignal: %LX\nblocked: %LX\nsigIgnore: %LX\nsigCache: %LX\n",
(int)uid,
(int)pid,
(int)ppid,
(int)pgrp,
session,
tty,
(int)tpgid,
priority,
nice,
signal,
blocked,
sigIgnore,
sigCatch];
(int)_uid,
(int)_pid,
(int)_ppid,
(int)_pgrp,
_session,
_tty,
(int)_tpgid,
_priority,
_nice,
_signal,
_blocked,
_sigIgnore,
_sigCatch];
dscr=[dscr stringByAppendingFormat:@"startTime: %@\nuserTime: %f\nsystemTime: %f\ncumulativeUserTime: %f\ncumulativeSystemTime: %f\n",
[NSDate dateWithTimeIntervalSinceReferenceDate:startTime],
userTime,
systemTime,
cumulativeUserTime,
cumulativeSystemTime];
dscr=[dscr stringByAppendingFormat:@"pagesNb=%ld (size: %ld)\nresidentPagesNb: %ld (size: %ld)\nsharedPagesNb: %ld (size: %ld)\ntextResidentSize: %ld\nsharedLibResidentSize: %ld\ndataResidentSize: %ld\ndirtyPagesNb: %ld\n",
pagesNb,
(long)(pagesNb*_pageSize),
residentPagesNb,
(long)(residentPagesNb*_pageSize),
sharedPagesNb,
(long)(sharedPagesNb*_pageSize),
textResidentSize,
sharedLibResidentSize,
dataResidentSize,
dirtyPagesNb];
dscr=[dscr stringByAppendingFormat:@"cpuUsage: %u%%\nvirtualPagesNb: %lu (size: %lu)\nresidentMemorySize: %lu\nresidentMemorySizeLimit: %lu\ntimeout: %lu\nit_real_value: %lu\n",
cpuUsagePC,
virtualPagesNb,
(long)(virtualPagesNb*_pageSize),
residentMemorySize,
residentMemorySizeLimit,
timeout,
it_real_value];
/* unsigned long flags,
unsigned long minorPageFaultNb,
unsigned long majorPageFaultNb,
unsigned long cumulativeMinorPageFaultNb,
unsigned long cumulativeMajorPageFaultNb,
unsigned long startCodeAddress,
unsigned long endCodeAddress,
unsigned long startStackAddress,
unsigned long kernelStackPointerESP,
unsigned long kernelStackPointerEIP,
unsigned long kernelWaitChannelProc,
*/
[NSDate dateWithTimeIntervalSinceReferenceDate:_startTime],
_userTime,
_systemTime,
_cumulativeUserTime,
_cumulativeSystemTime];
dscr=[dscr stringByAppendingFormat:@"pagesNb=%ld (size: %@)\nresidentPagesNb: %ld (size: %@)\nsharedPagesNb: %ld (size: %@)\ntextResidentSize: %@\nsharedLibResidentSize: %@\ndataResidentSize: %@\ndirtyPagesNb: %ld\n",
_pagesNb,
formattedByteSizeValue(_pagesNb*pageSize),
_residentPagesNb,
formattedByteSizeValue(_residentPagesNb*pageSize),
_sharedPagesNb,
formattedByteSizeValue(_sharedPagesNb*pageSize),
formattedByteSizeValue(_textResidentSize),
formattedByteSizeValue(_sharedLibResidentSize),
formattedByteSizeValue(_dataResidentSize),
_dirtyPagesNb];
dscr=[dscr stringByAppendingFormat:@"cpuUsage: %u%%\nvirtualMemorySize: %@\nresidentMemorySize: %@\nresidentMemorySizeLimit: %@\ntimeout: %lu\nit_real_value: %lu\n",
_cpuUsagePC,
formattedByteSizeValue(_virtualMemorySize),
formattedByteSizeValue(_residentMemorySize),
formattedByteSizeValue(_residentMemorySizeLimit),
_timeout,
_it_real_value];
/* unsigned long flags,
unsigned long minorPageFaultNb,
unsigned long majorPageFaultNb,
unsigned long cumulativeMinorPageFaultNb,
unsigned long cumulativeMajorPageFaultNb,
unsigned long startCodeAddress,
unsigned long endCodeAddress,
unsigned long startStackAddress,
unsigned long kernelStackPointerESP,
unsigned long kernelStackPointerEIP,
unsigned long kernelWaitChannelProc,
*/
return dscr;
};
-(BOOL)fill
@ -159,47 +181,48 @@ RCS_ID("$Id$")
+(NSString*)contentOfProcFile:(NSString*)procFile
{
NSString* _content=nil;
char thePath[BUFSIZ*2];
FILE *theFile = 0;
NSString* _path=[NSString stringWithFormat:@"/proc/%@",procFile];
if ([_path getFileSystemRepresentation:thePath
maxLength:sizeof(thePath)-1] == NO)
NSString* content=nil;
char thePath[BUFSIZ*2];
FILE *theFile = NULL;
NSString* path=[NSString stringWithFormat:@"/proc/%@",procFile];
if ([path getFileSystemRepresentation:thePath
maxLength:sizeof(thePath)-1] == NO)
{
LOGSeriousError(@"Open (%@) attempt failed - bad path",
_path);
LOGSeriousError(@"Open (%@) attempt failed - bad path",
path);
}
else
{
theFile = fopen(thePath, "r");
if (theFile == NULL) // We failed to open the file.
{
LOGSeriousError(@"Open (%s) attempt failed - %s", thePath, strerror(errno));
}
else
{
char buff[1024]="";
if (!fgets(buff,1024,theFile))
{
LOGSeriousError(@"Read (%s) attempt failed",thePath);
}
else
{
_content=[NSString stringWithCString:buff];
};
fclose(theFile);
};
};
return _content;
{
theFile = fopen(thePath, "r");
if (theFile == NULL) // We failed to open the file.
{
LOGSeriousError(@"Open (%s) attempt failed - %s", thePath, strerror(errno));
}
else
{
char buff[1024]="";
if (!fgets(buff,1024,theFile))
{
LOGSeriousError(@"Read (%s) attempt failed",thePath);
}
else
{
content=[NSString stringWithCString:buff];
NSDebugMLog(@"content=%@",content);
};
fclose(theFile);
};
};
return content;
};
-(NSString*)contentOfPIDFile:(NSString*)pidFile
{
NSString* _content=nil;
NSString* _path=[NSString stringWithFormat:@"%d/%@",(int)(pid ? pid : getpid()),pidFile];
_content=[[self class] contentOfProcFile:_path];
return _content;
NSString* content=nil;
NSString* path=[NSString stringWithFormat:@"%d/%@",(int)(_pid ? _pid : getpid()),pidFile];
content=[[self class] contentOfProcFile:path];
return content;
};
-(BOOL)fillStatm
@ -208,20 +231,20 @@ RCS_ID("$Id$")
NSString* pidstat=[self contentOfPIDFile:@"statm"];
NSDebugFLog(@"pidstat=%@",pidstat);
if (pidstat)
{
char* _statsChars=[pidstat cString];
NSDebugFLog(@"pidstat=%@",pidstat);
if (sscanf(_statsChars, "%ld %ld %ld %ld %ld %ld %ld",
&pagesNb,//size
&residentPagesNb,//resident
&sharedPagesNb,//share
&textResidentSize, //trs
&sharedLibResidentSize,//lrs
&dataResidentSize,//drs
&dirtyPagesNb//dt
)==7)
ok=YES;
};
{
const char* statsChars=[pidstat cString];
NSDebugFLog(@"pidstat=%@",pidstat);
if (sscanf(statsChars, "%ld %ld %ld %ld %ld %ld %ld",
&_pagesNb,//size
&_residentPagesNb,//resident
&_sharedPagesNb,//share
&_textResidentSize, //trs
&_sharedLibResidentSize,//lrs
&_dataResidentSize,//drs
&_dirtyPagesNb//dt
)==7)
ok=YES;
};
return ok;
};
@ -231,113 +254,171 @@ RCS_ID("$Id$")
NSString* pidstat=[self contentOfPIDFile:@"stat"];
NSDebugFLog(@"pidstat=%@",pidstat);
if (pidstat)
{
NSRange _cmdEnd=[pidstat rangeOfString:@") "];
if (_cmdEnd.length>0)
{
NSString* _pid_cmd=[pidstat substringToIndex:_cmdEnd.location];
NSDebugFLog(@"_pid_cmd=%@",_pid_cmd);
if (_cmdEnd.location+_cmdEnd.length<[pidstat length])
{
NSString* _stats=[pidstat substringFromIndex:_cmdEnd.location+_cmdEnd.length];
/*
char* tmp = strrchr(S, ')'); // split into "PID (cmd" and "<rest>"
*tmp = '\0'; // replace trailing ')' with NUL
// parse these two strings separately, skipping the leading "(".
memset(P->cmd, 0, sizeof P->cmd); // clear even though *P xcalloc'd ?!
sscanf(S, "%d (%39c", &P->pid, P->cmd);
*/
char* _statsChars=[_stats cString];
char cState;
long _utime;
long _stime;
long _cutime;
long _cstime;
long _startTime;
NSDebugFLog(@"_stats=%@",_stats);
if (sscanf(_statsChars,
"%c %d %d %d %d %d %lu %lu %lu %lu %lu %ld %ld %ld %ld %d "
"%d %lu %lu %ld %lu %lu %lu %lu %lu %lu %lu %lu %LX %LX %LX %LX %lu",
&cState, //state
&ppid,//ppid
&pgrp,//pgrp
&session,//session
&tty,//tty
&tpgid,//tpgid,
&flags,//flags
&minorPageFaultNb,//min_flt
&cumulativeMinorPageFaultNb,//cmin_flt
&majorPageFaultNb,//maj_flt
&cumulativeMajorPageFaultNb,//cmaj_flt,
&_utime,//utime
&_stime,//stime
&_cutime,//cutime
&_cstime,//cstime
&priority,//priority
&nice,//nice,
&timeout,//timeout
&it_real_value,//it_real_value
&_startTime,//start_time
&virtualPagesNb,//vsize
&residentMemorySize,//rss,
&residentMemorySizeLimit,//rss_rlim
&startCodeAddress,//start_code
&endCodeAddress,//end_code
&startStackAddress,//start_stack,
&kernelStackPointerESP,//kstk_esp
&kernelStackPointerEIP,//kstk_eip
&signal,//signal
&blocked,//blocked
&sigIgnore,//sigignore,
&sigCatch,//sigcatch
&kernelWaitChannelProc//wchan
)==33)
{
ok=YES;
switch(cState)
{
case 'S':
state=GSWProcState__Sleeping;
break;
case 'R':
state=GSWProcState__Running;
break;
case 'Z':
state=GSWProcState__Zombie;
break;
case 'T':
state=GSWProcState__Stopped;
break;
case 'D':
state=GSWProcState__SleepWait;
break;
default:
state=GSWProcState__Unknown;
break;
};
userTime=_utime;
systemTime=_stime;
cumulativeUserTime=_cutime;
cumulativeSystemTime=_cstime;
startTime=[[NSDate dateWithTimeIntervalSince1970:(NSTimeInterval)_startTime]timeIntervalSinceReferenceDate];
if (tty == 0)
tty = -1; // the old notty val, update elsewhere bef. moving to 0
/* if (linux_version_code < LINUX_VERSION(1,3,39))
{
P->priority = 2*15 - P->priority; // map old meanings to new
P->nice = 15 - P->nice;
}
if (linux_version_code < LINUX_VERSION(1,1,30) && P->tty != -1)
P->tty = 4*0x100 + P->tty; // when tty wasn't full devno
*/
NSDebugFLog(@"residentMemorySize=%lu",residentMemorySize);
};
};
};
};
{
NSRange cmdEnd=[pidstat rangeOfString:@") "];
if (cmdEnd.length>0)
{
NSString* pid_cmd=[pidstat substringToIndex:cmdEnd.location];
NSDebugFLog(@"pid_cmd=%@",pid_cmd);
if (cmdEnd.location+cmdEnd.length<[pidstat length])
{
NSString* stats=[pidstat substringFromIndex:cmdEnd.location+cmdEnd.length];
/*
char* tmp = strrchr(S, ')'); // split into "PID (cmd" and "<rest>"
*tmp = '\0'; // replace trailing ')' with NUL
// parse these two strings separately, skipping the leading "(".
memset(P->cmd, 0, sizeof P->cmd); // clear even though *P xcalloc'd ?!
sscanf(S, "%d (%39c", &P->pid, P->cmd);
*/
const char* statsChars=[stats cString];
char cState;
long utime;
long stime;
long cutime;
long cstime;
long startTime;
NSDebugFLog(@"stats=%@",stats);
if (sscanf(statsChars,
"%c %d %d %d %d %d %lu %lu %lu %lu %lu %ld %ld %ld %ld %d "
"%d %lu %lu %ld %lu %lu %lu %lu %lu %lu %lu %lu %LX %LX %LX %LX %lu",
&cState, //state
&_ppid,//ppid
&_pgrp,//pgrp
&_session,//session
&_tty,//tty
&_tpgid,//tpgid,
&_flags,//flags
&_minorPageFaultNb,//min_flt
&_cumulativeMinorPageFaultNb,//cmin_flt
&_majorPageFaultNb,//maj_flt
&_cumulativeMajorPageFaultNb,//cmaj_flt,
&utime,//utime
&stime,//stime
&cutime,//cutime
&cstime,//cstime
&_priority,//priority
&_nice,//nice,
&_timeout,//timeout
&_it_real_value,//it_real_value
&startTime,//start_time
&_virtualMemorySize,//vsize
&_residentMemorySize,//rss,
&_residentMemorySizeLimit,//rss_rlim
&_startCodeAddress,//start_code
&_endCodeAddress,//end_code
&_startStackAddress,//start_stack,
&_kernelStackPointerESP,//kstk_esp
&_kernelStackPointerEIP,//kstk_eip
&_signal,//signal
&_blocked,//blocked
&_sigIgnore,//sigignore,
&_sigCatch,//sigcatch
&_kernelWaitChannelProc//wchan
)==33)
{
ok=YES;
switch(cState)
{
case 'S':
_state=GSWProcState__Sleeping;
break;
case 'R':
_state=GSWProcState__Running;
break;
case 'Z':
_state=GSWProcState__Zombie;
break;
case 'T':
_state=GSWProcState__Stopped;
break;
case 'D':
_state=GSWProcState__SleepWait;
break;
default:
_state=GSWProcState__Unknown;
break;
};
_userTime=utime;
_systemTime=stime;
_cumulativeUserTime=cutime;
_cumulativeSystemTime=cstime;
startTime=[[NSDate dateWithTimeIntervalSince1970:(NSTimeInterval)_startTime]timeIntervalSinceReferenceDate];
if (_tty == 0)
_tty = -1; // the old notty val, update elsewhere bef. moving to 0
/* if (linux_version_code < LINUX_VERSION(1,3,39))
{
P->priority = 2*15 - P->priority; // map old meanings to new
P->nice = 15 - P->nice;
}
if (linux_version_code < LINUX_VERSION(1,1,30) && P->tty != -1)
P->tty = 4*0x100 + P->tty; // when tty wasn't full devno
*/
NSDebugFLog(@"residentMemorySize=%lu",_residentMemorySize);
};
};
};
};
return ok;
};
-(unsigned int)residentMemory
{
size_t pageSize=getpagesize();
return (unsigned int)(_residentPagesNb*pageSize);
};
-(unsigned int)sharedMemory
{
size_t pageSize=getpagesize();
return (unsigned int)(_sharedPagesNb*pageSize);
};
-(unsigned int)virtualMemory
{
return (unsigned int)_virtualMemorySize;
};
-(unsigned int)swapMemory
{
//TODO
return 0;
};
-(unsigned int)usedMemory
{
unsigned int residentMemory=[self residentMemory];
unsigned int sharedMemory=[self sharedMemory];
unsigned int virtualMemory=[self virtualMemory];
return max(residentMemory+sharedMemory,virtualMemory);
};
-(NSString*)formattedResidentMemory
{
return formattedByteSizeValue([self residentMemory]);
};
-(NSString*)formattedSharedMemory
{
return formattedByteSizeValue([self sharedMemory]);
}
-(NSString*)formattedVirtualMemory
{
return formattedByteSizeValue([self virtualMemory]);
}
-(NSString*)formattedSwapMemory
{
return formattedByteSizeValue([self swapMemory]);
}
-(NSString*)formattedUsedMemory
{
return formattedByteSizeValue([self usedMemory]);
}
@end