* GSWeb.framework/GSWUtils.h/m: (struct proc_s, proc_t): Removed.

(pidstat, pidstatm, pidproccontent): Removed.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@19367 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
David Ayers 2004-05-18 09:45:21 +00:00
parent 41c36413c4
commit 3b1ee04d74
4 changed files with 3 additions and 188 deletions

View file

@ -1,5 +1,8 @@
2004-05-18 David Ayers <d.ayers@inode.at>
* GSWeb.framework/GSWUtils.h/m: (struct proc_s, proc_t): Removed.
(pidstat, pidstatm, pidproccontent): Removed.
* 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.

View file

@ -890,12 +890,6 @@ RCS_ID("$Id$")
NSDebugMLog(@"ru_nivcsw=%ld",rusageStruct.ru_nivcsw); /* involuntary context switches */
};
};
{
proc_t P;
memset(&P,0,sizeof(proc_t));
pidstat(getpid(),&P);
pidstatm(getpid(),&P);
};
NSDebugMLog(@"ProcInfo:%@",[GSWProcFSProcInfo filledProcInfo]);
//{Committed = 14184448; Reserved = 19025920; }

View file

@ -123,72 +123,6 @@ GSWEB_EXPORT BOOL SBIsValueIsIn(id id1,id id2);
GSWEB_EXPORT id GetTmpName(NSString* dir,NSString* prefix);
GSWEB_EXPORT NSTimeInterval NSTimeIntervalFromTimeVal(struct timeval* tv);
GSWEB_EXPORT void NSTimeIntervalSleep(NSTimeInterval ti);
/* Basic data structure which holds all information we can get about a process.
* (unless otherwise specified, fields are read from /proc/#/stat)
*/
typedef struct proc_s {
char
user[10], /* user name corresponding to owner of process */
cmd[40], /* basename of executable file in call to exec(2) */
state, /* single-char code for process state (S=sleeping) */
ttyc[5], /* string representation of controlling tty device */
**environ, /* environment string vector (/proc/#/environ) */
**cmdline; /* command line string vector (/proc/#/cmdline) */
int
uid, /* user id */
pid, /* process id */
ppid, /* pid of parent process */
pgrp, /* process group id */
session, /* session id */
tty, /* full device number of controlling terminal */
tpgid, /* terminal process group id */
priority, /* kernel scheduling priority */
nice; /* standard unix nice level of process */
long long
signal, /* mask of pending signals */
blocked, /* mask of blocked signals */
sigignore, /* mask of ignored signals */
sigcatch; /* mask of caught signals */
long
start_time, /* start time of process -- seconds since 1-1-70 */
utime, /* user-mode CPU time accumulated by process */
stime, /* kernel-mode CPU time accumulated by process */
cutime, /* cumulative utime of process and reaped children */
cstime, /* cumulative stime of process and reaped children */
/* the next 7 members come from /proc/#/statm */
size, /* total # of pages of memory */
resident, /* number of resident set (non-swapped) pages (4k) */
share, /* number of pages of shared (mmap'd) memory */
trs, /* text resident set size */
lrs, /* shared-lib resident set size */
drs, /* data resident set size */
dt; /* dirty pages */
unsigned
pcpu; /* %CPU usage (is not filled in by readproc!!!) */
unsigned long
vsize, /* number of pages of virtual memory ... */
rss, /* resident set size from /proc/#/stat */
rss_rlim, /* resident set size ... ? */
timeout, /* ? */
it_real_value, /* ? */
flags, /* kernel flags for the process */
min_flt, /* number of minor page faults since process start */
maj_flt, /* number of major page faults since process start */
cmin_flt, /* cumulative min_flt of process and child processes */
cmaj_flt, /* cumulative maj_flt of process and child processes */
start_code, /* address of beginning of code segment */
end_code, /* address of end of code segment */
start_stack, /* address of the bottom of stack for the process */
kstk_esp, /* kernel stack pointer */
kstk_eip, /* kernel stack pointer */
wchan; /* address of kernel wait channel proc is sleeping in */
struct proc_s *l, /* ptrs for building arbitrary linked structs */
*r; /* (i.e. singly/doubly-linked lists and trees */
} proc_t;
GSWEB_EXPORT void pidstat(pid_t pid, proc_t* P);
GSWEB_EXPORT void pidstatm(pid_t pid, proc_t* P);
GSWEB_EXPORT NSString* GSWGetDefaultDocRoot();

View file

@ -222,122 +222,6 @@ void NSTimeIntervalSleep(NSTimeInterval ti)
};
};
NSString* pidproccontent(NSString* path)
{
NSString* content=nil;
char thePath[BUFSIZ*2];
FILE* theFile = 0;
if ([path getFileSystemRepresentation:thePath
maxLength:sizeof(thePath)-1] == NO)
{
LOGSeriousError(@"Open (%@) attempt failed - bad path",
path);
}
else
{
#if defined(__WIN32__)
theFile = fopen(thePath, "rb");
#else
theFile = fopen(thePath, "r");
#endif
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;
};
void pidstat(pid_t pid, proc_t* P)
{
NSString* filename=[NSString stringWithFormat:@"/proc/%d/stat",(int)pid];
NSString* pidstat=pidproccontent(filename);
NSDebugFLog(@"pidstat=%@",pidstat);
NSDebugFLog(@"filename=%@",filename);
NSDebugFLog(@"pid=%d",(int)pid);
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);
*/
const char* statsChars=[stats cString];
NSDebugFLog(@"stats=%@",stats);
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",
&P->state, &P->ppid, &P->pgrp, &P->session, &P->tty, &P->tpgid,
&P->flags, &P->min_flt, &P->cmin_flt, &P->maj_flt, &P->cmaj_flt,
&P->utime, &P->stime, &P->cutime, &P->cstime, &P->priority, &P->nice,
&P->timeout, &P->it_real_value, &P->start_time, &P->vsize, &P->rss,
&P->rss_rlim, &P->start_code, &P->end_code, &P->start_stack,
&P->kstk_esp, &P->kstk_eip, &P->signal, &P->blocked, &P->sigignore,
&P->sigcatch, &P->wchan);
if (P->tty == 0)
P->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(@"P->vsize=%lu",P->vsize);
NSDebugFLog(@"P->rss=%lu",P->rss);
};
};
};
};
void pidstatm(pid_t pid, proc_t* P)
{
NSString* filename=[NSString stringWithFormat:@"/proc/%d/statm",(int)pid];
NSString* pidstat=pidproccontent(filename);
NSDebugFLog(@"pidstat=%@",pidstat);
NSDebugFLog(@"filename=%@",filename);
NSDebugFLog(@"pid=%d",(int)pid);
if (pidstat)
{
const char* statsChars=[pidstat cString];
NSDebugFLog(@"pidstat=%@",pidstat);
sscanf(statsChars, "%ld %ld %ld %ld %ld %ld %ld",
&P->size, &P->resident, &P->share,
&P->trs, &P->lrs, &P->drs, &P->dt);
NSDebugFLog(@"P->size=%ld",P->size);
NSDebugFLog(@"P->resident=%ld",P->resident);
NSDebugFLog(@"P->share=%ld",P->share);
NSDebugFLog(@"P->trs=%ld",P->trs);
NSDebugFLog(@"P->lrs=%ld",P->lrs);
NSDebugFLog(@"P->drs=%ld",P->drs);
NSDebugFLog(@"P->dt=%ld",P->dt);
};
};
//--------------------------------------------------------------------
void StackTraceIFND()
{