mirror of
https://github.com/gnustep/libs-gsweb.git
synced 2025-02-22 11:11:21 +00:00
* GSWeb.framework/GSWProcFS.h/m: Make class more portable.
Replace all system dependent types with standard types. Replace usage of NSDebugFLog with NSDebugMLog in methods. ([GSWProcFSProcInfo filledProcInfo]): Use -processIdentifier instead of getpid. ([GSWProcFSProcInfo filledProcInfoWithPID:]): Update types. Use standard GC macro. ([GSWProcFSProcInfo initFilledWithPID:]): Update types. ([GSWProcFSProcInfo description]): Use NSPageSize instead of getpagesize. Remove obsolete casts. ([GSWProcFSProcInfo contentOfProcFile:]): Use standard NSString API to read the file. ([GSWProcFSProcInfo contentOfPIDFile:]): Adapt to new types and reformat. ([GSWProcFSProcInfo residentMemory]), ([GSWProcFSProcInfo sharedMemory]): Adapt to new types. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@19366 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
6cc2ee18c5
commit
cd1944a9e5
3 changed files with 80 additions and 75 deletions
19
ChangeLog
19
ChangeLog
|
@ -1,3 +1,22 @@
|
|||
2004-05-18 David Ayers <d.ayers@inode.at>
|
||||
|
||||
* GSWeb.framework/GSWProcFS.h/m: Make class more portable.
|
||||
Replace all system dependent types with standard types. Replace
|
||||
usage of NSDebugFLog with NSDebugMLog in methods.
|
||||
([GSWProcFSProcInfo filledProcInfo]): Use -processIdentifier
|
||||
instead of getpid.
|
||||
([GSWProcFSProcInfo filledProcInfoWithPID:]): Update types. Use
|
||||
standard GC macro.
|
||||
([GSWProcFSProcInfo initFilledWithPID:]): Update types.
|
||||
([GSWProcFSProcInfo description]): Use NSPageSize instead of
|
||||
getpagesize. Remove obsolete casts.
|
||||
([GSWProcFSProcInfo contentOfProcFile:]): Use standard NSString
|
||||
API to read the file.
|
||||
([GSWProcFSProcInfo contentOfPIDFile:]): Adapt to new types and
|
||||
reformat.
|
||||
([GSWProcFSProcInfo residentMemory]),
|
||||
([GSWProcFSProcInfo sharedMemory]): Adapt to new types.
|
||||
|
||||
2004-05-16 David Wetzel <dave@turbocat.de>
|
||||
|
||||
* GSWeb.framework/GSWApplication.m ([GSWApplication
|
||||
|
|
|
@ -44,13 +44,13 @@ typedef enum _GSWProcState
|
|||
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 _uid; // user id
|
||||
int _pid; // process id [/proc/#/stat]
|
||||
int _ppid; // pid of parent process [/proc/#/stat]
|
||||
int _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 _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]
|
||||
|
@ -89,8 +89,8 @@ typedef enum _GSWProcState
|
|||
};
|
||||
|
||||
+(GSWProcFSProcInfo*)filledProcInfo;
|
||||
+(GSWProcFSProcInfo*)filledProcInfoWithPID:(pid_t)pid_;
|
||||
-(id)initFilledWithPID:(pid_t)pid_;
|
||||
+(GSWProcFSProcInfo*)filledProcInfoWithPID: (int)processID;
|
||||
-(id)initFilledWithPID: (int)processID;
|
||||
-(void)dealloc;
|
||||
-(BOOL)fill;
|
||||
+(NSString*)contentOfProcFile:(NSString*)procFile;
|
||||
|
|
|
@ -37,43 +37,46 @@
|
|||
RCS_ID("$Id$")
|
||||
|
||||
#include "GSWeb.h"
|
||||
#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)];
|
||||
return [NSString stringWithFormat:@"%.3f Kb",
|
||||
(((double)value)/1024)];
|
||||
else if (value<1024L*1024L*1024L)
|
||||
return [NSString stringWithFormat:@"%.3f Mb",(((double)value)/(1024L*1024L))];
|
||||
return [NSString stringWithFormat:@"%.3f Mb",
|
||||
(((double)value)/(1024L*1024L))];
|
||||
else
|
||||
return [NSString stringWithFormat:@"%.3f Gb",(((double)value)/(1024L*1024L*1024L))];
|
||||
return [NSString stringWithFormat:@"%.3f Gb",
|
||||
(((double)value)/(1024L*1024L*1024L))];
|
||||
};
|
||||
|
||||
@implementation GSWProcFSProcInfo
|
||||
|
||||
+(GSWProcFSProcInfo*)filledProcInfo
|
||||
+ (GSWProcFSProcInfo *)filledProcInfo
|
||||
{
|
||||
return [self filledProcInfoWithPID:getpid()];
|
||||
};
|
||||
int processID = [[NSProcessInfo processInfo] processIdentifier];
|
||||
return [self filledProcInfoWithPID: processID];
|
||||
}
|
||||
|
||||
+(GSWProcFSProcInfo*)filledProcInfoWithPID:(pid_t)pid_
|
||||
+ (GSWProcFSProcInfo *)filledProcInfoWithPID: (int)processID
|
||||
{
|
||||
GSWProcFSProcInfo* obj=[[[self alloc] initFilledWithPID:pid_]autorelease];
|
||||
GSWProcFSProcInfo *obj
|
||||
= AUTORELEASE([[self alloc] initFilledWithPID: processID]);
|
||||
return obj;
|
||||
};
|
||||
}
|
||||
|
||||
-(id)initFilledWithPID:(pid_t)pid
|
||||
- (id)initFilledWithPID: (int)processID
|
||||
{
|
||||
if ((self=[super init]))
|
||||
{
|
||||
_pid=pid;
|
||||
[self fill];
|
||||
};
|
||||
if ((self = [super init]))
|
||||
{
|
||||
_pid = processID;
|
||||
[self fill];
|
||||
};
|
||||
return self;
|
||||
};
|
||||
}
|
||||
|
||||
-(void)dealloc
|
||||
{
|
||||
|
@ -88,7 +91,7 @@ NSString* formattedByteSizeValue(unsigned int value)
|
|||
-(NSString*)description
|
||||
{
|
||||
NSString* dscr=nil;
|
||||
size_t pageSize=getpagesize();
|
||||
unsigned int pageSize=NSPageSize();
|
||||
char* stateCString=NULL;
|
||||
switch(_state)
|
||||
{
|
||||
|
@ -120,13 +123,13 @@ NSString* formattedByteSizeValue(unsigned int value)
|
|||
_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,
|
||||
_uid,
|
||||
_pid,
|
||||
_ppid,
|
||||
_pgrp,
|
||||
_session,
|
||||
_tty,
|
||||
(int)_tpgid,
|
||||
_tpgid,
|
||||
_priority,
|
||||
_nice,
|
||||
_signal,
|
||||
|
@ -179,49 +182,31 @@ NSString* formattedByteSizeValue(unsigned int value)
|
|||
return YES;
|
||||
};
|
||||
|
||||
+(NSString*)contentOfProcFile:(NSString*)procFile
|
||||
+ (NSString *)contentOfProcFile: (NSString *)procFile
|
||||
{
|
||||
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)
|
||||
NSString *path;
|
||||
NSString *content;
|
||||
|
||||
path = [NSString stringWithFormat: @"/proc/%@", procFile];
|
||||
content = [NSString stringWithContentsOfFile: path];
|
||||
|
||||
if ([content length] == 0)
|
||||
{
|
||||
LOGSeriousError(@"Open (%@) attempt failed - bad path",
|
||||
path);
|
||||
LOGSeriousError(@"Read (%@) attempt failed", 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];
|
||||
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];
|
||||
NSString* path
|
||||
= [NSString stringWithFormat:@"%d/%@",
|
||||
(_pid ? _pid
|
||||
: [[NSProcessInfo processInfo] processIdentifier]),
|
||||
pidFile];
|
||||
content=[[self class] contentOfProcFile: path];
|
||||
return content;
|
||||
};
|
||||
|
||||
|
@ -229,11 +214,11 @@ NSString* formattedByteSizeValue(unsigned int value)
|
|||
{
|
||||
BOOL ok=NO;
|
||||
NSString* pidstat=[self contentOfPIDFile:@"statm"];
|
||||
NSDebugFLog(@"pidstat=%@",pidstat);
|
||||
NSDebugMLog(@"pidstat=%@",pidstat);
|
||||
if (pidstat)
|
||||
{
|
||||
const char* statsChars=[pidstat cString];
|
||||
NSDebugFLog(@"pidstat=%@",pidstat);
|
||||
NSDebugMLog(@"pidstat=%@",pidstat);
|
||||
if (sscanf(statsChars, "%ld %ld %ld %ld %ld %ld %ld",
|
||||
&_pagesNb,//size
|
||||
&_residentPagesNb,//resident
|
||||
|
@ -251,15 +236,16 @@ NSString* formattedByteSizeValue(unsigned int value)
|
|||
-(BOOL)fillStat
|
||||
{
|
||||
BOOL ok=NO;
|
||||
NSString* pidstat=[self contentOfPIDFile:@"stat"];
|
||||
NSDebugFLog(@"pidstat=%@",pidstat);
|
||||
NSString* pidstat = [self contentOfPIDFile: @"stat"];
|
||||
|
||||
NSDebugMLog(@"pidstat=%@",pidstat);
|
||||
if (pidstat)
|
||||
{
|
||||
NSRange cmdEnd=[pidstat rangeOfString:@") "];
|
||||
if (cmdEnd.length>0)
|
||||
{
|
||||
NSString* pid_cmd=[pidstat substringToIndex:cmdEnd.location];
|
||||
NSDebugFLog(@"pid_cmd=%@",pid_cmd);
|
||||
NSDebugMLog(@"pid_cmd=%@",pid_cmd);
|
||||
if (cmdEnd.location+cmdEnd.length<[pidstat length])
|
||||
{
|
||||
NSString* stats=[pidstat substringFromIndex:cmdEnd.location+cmdEnd.length];
|
||||
|
@ -278,7 +264,7 @@ NSString* formattedByteSizeValue(unsigned int value)
|
|||
long cstime;
|
||||
long startTime;
|
||||
|
||||
NSDebugFLog(@"stats=%@",stats);
|
||||
NSDebugMLog(@"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",
|
||||
|
@ -355,7 +341,7 @@ NSString* formattedByteSizeValue(unsigned int value)
|
|||
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);
|
||||
NSDebugMLog(@"residentMemorySize=%lu",_residentMemorySize);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -365,13 +351,13 @@ NSString* formattedByteSizeValue(unsigned int value)
|
|||
|
||||
-(unsigned int)residentMemory
|
||||
{
|
||||
size_t pageSize=getpagesize();
|
||||
unsigned int pageSize=NSPageSize();
|
||||
return (unsigned int)(_residentPagesNb*pageSize);
|
||||
};
|
||||
|
||||
-(unsigned int)sharedMemory
|
||||
{
|
||||
size_t pageSize=getpagesize();
|
||||
unsigned int pageSize=NSPageSize();
|
||||
return (unsigned int)(_sharedPagesNb*pageSize);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue