[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/workspace/ksysguard/ksysguardd
From: John Tapsell <john.tapsell () kdemail ! net>
Date: 2006-09-19 10:02:34
Message-ID: 1158660154.299372.16594.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 586280 by johnflux:
Don't use Container. Speeds it up by a small amount (5% or so)
M +27 -97 Linux/ProcessList.c
M +0 -2 Linux/ProcessList.h
M +1 -1 modules.h
--- trunk/KDE/kdebase/workspace/ksysguard/ksysguardd/Linux/ProcessList.c #586279:586280
@@ -42,8 +42,6 @@
#define TAGSIZE 32
#define KDEINITLEN strlen( "kdeinit: " )
-static CONTAINER ProcessList = 0;
-
#include "config-ksysguardd.h" /*For HAVE_XRES*/
#ifdef HAVE_XRES
extern int setup_xres();
@@ -154,25 +152,8 @@
strcpy( str, " " );
}
-static int processCmp( void* p1, void* p2 )
+static ProcessInfo* getProcess( int pid )
{
- return ( ((ProcessInfo*)p1)->pid - ((ProcessInfo*)p2)->pid );
-}
-
-static ProcessInfo* findProcessInList( int pid )
-{
- ProcessInfo key;
- long idx;
-
- key.pid = pid;
- if ( ( idx = search_ctnr( ProcessList, processCmp, &key ) ) < 0 )
- return 0;
-
- return get_ctnr( ProcessList, idx );
-}
-
-static int updateProcess( int pid )
-{
ProcessInfo* ps;
FILE* fd;
char buf[ BUFSIZE ];
@@ -183,24 +164,19 @@
const char* uName;
char status;
- if ( ( ps = findProcessInList( pid ) ) == 0 ) {
- struct timeval tv;
+ struct timeval tv;
- ps = (ProcessInfo*)malloc( sizeof( ProcessInfo ) );
- ps->pid = pid;
- ps->alive = 0;
+ ps = (ProcessInfo*)malloc( sizeof( ProcessInfo ) );
+ ps->pid = pid;
+ ps->alive = 0;
- gettimeofday( &tv, 0 );
- ps->centStamp = tv.tv_sec * 100 + tv.tv_usec / 10000;
+ gettimeofday( &tv, 0 );
+ ps->centStamp = tv.tv_sec * 100 + tv.tv_usec / 10000;
- push_ctnr( ProcessList, ps );
- bsort_ctnr( ProcessList, processCmp );
- }
-
snprintf( buf, BUFSIZE - 1, "/proc/%d/status", pid );
if ( ( fd = fopen( buf, "r" ) ) == 0 ) {
/* process has terminated in the mean time */
- return -1;
+ return NULL;
}
ps->uid = 0;
ps->gid = 0;
@@ -227,12 +203,12 @@
}
if ( fclose( fd ) )
- return -1;
+ return NULL;
snprintf( buf, BUFSIZE - 1, "/proc/%d/stat", pid );
buf[ BUFSIZE - 1 ] = '\0';
if ( ( fd = fopen( buf, "r" ) ) == 0 )
- return -1;
+ return NULL;
if ( fscanf( fd, "%*d %*s %c %d %*d %*d %d %*d %*u %*u %*u %*u %*u %d %d"
"%*d %*d %*d %d %*u %*u %*d %u %u",
@@ -240,11 +216,11 @@
&userTime, &sysTime, &ps->niceLevel, &ps->vmSize,
&ps->vmRss) != 8 ) {
fclose( fd );
- return -1;
+ return NULL;
}
if ( fclose( fd ) )
- return -1;
+ return NULL;
/* status decoding as taken from fs/proc/array.c */
if ( status == 'R' )
@@ -297,7 +273,7 @@
snprintf( buf, BUFSIZE - 1, "/proc/%d/cmdline", pid );
if ( ( fd = fopen( buf, "r" ) ) == 0 )
- return -1;
+ return NULL;
ps->cmdline[ 0 ] = '\0';
sprintf( buf, "%%%d[^\n]", (int)sizeof( ps->cmdline ) - 1 );
@@ -305,7 +281,7 @@
ps->cmdline[ sizeof( ps->cmdline ) - 1 ] = '\0';
validateStr( ps->cmdline );
if ( fclose( fd ) )
- return -1;
+ return NULL;
/* Ugly hack to "fix" program name for kdeinit launched programs. */
if ( strcmp( ps->name, "kdeinit" ) == 0 &&
@@ -336,35 +312,12 @@
- return 0;
+ return ps;
}
-static void cleanupProcessList( void )
+void printProcessList( const char* cmd)
{
- ProcessInfo* ps;
-
- ProcessCount = 0;
- /**
- All processes that do not have the active flag set are assumed dead
- and will be removed from the list. The alive flag is cleared.
- */
- for ( ps = first_ctnr( ProcessList ); ps; ps = next_ctnr( ProcessList ) ) {
- if ( ps->alive ) {
- /* Process is still alive. Just clear flag. */
- ps->alive = 0;
- ProcessCount++;
- } else {
- /**
- Process has probably died. We remove it from the list and
- destruct the data structure.
- */
- free( remove_ctnr( ProcessList ) );
- }
- }
-}
-
-int updateProcessList( void )
-{
+ (void)cmd;
DIR* dir;
struct dirent* entry;
@@ -373,7 +326,7 @@
print_error( "Cannot open directory \'/proc\'!\n"
"The kernel needs to be compiled with support\n"
"for /proc file system enabled!\n" );
- return 0;
+ return;
}
while ( ( entry = readdir( dir ) ) ) {
@@ -381,13 +334,18 @@
int pid;
pid = atoi( entry->d_name );
- updateProcess( pid );
+ ProcessInfo* ps = getProcess( pid );
+ fprintf( CurrentClient, "%s\t%ld\t%ld\t%ld\t%ld\t%s\t%.2f\t%.2f\t%d\t%d\t%d\t%s\t%ld\t%s\n",
+ ps->name, (long)ps->pid, (long)ps->ppid,
+ (long)ps->uid, (long)ps->gid, ps->status, ps->userLoad,
+ ps->sysLoad, ps->niceLevel, ps->vmSize / 1024, ps->vmRss / 1024,
+ ps->userName, (long)ps->tracerpid, ps->cmdline
+ );
}
}
+ fprintf( CurrentClient, "\n" );
closedir( dir );
-
- cleanupProcessList();
- return 0;
+ return;
}
/*
@@ -398,8 +356,6 @@
{
initPWUIDCache();
- ProcessList = new_ctnr();
-
registerMonitor( "pscount", "integer", printProcessCount, printProcessCountInfo, sm );
registerMonitor( "ps", "table", printProcessList, printProcessListInfo, sm );
@@ -414,8 +370,6 @@
registerMonitor( "xres", "table", printXresList, printXresListInfo, sm);
}
#endif
-
- updateProcessList();
}
void exitProcessList( void )
@@ -432,8 +386,6 @@
removeCommand( "setpriority" );
}
- destr_ctnr( ProcessList, free );
-
exitPWUIDCache();
}
#ifdef HAVE_XRES
@@ -460,28 +412,6 @@
fprintf( CurrentClient, "s\td\td\td\td\tS\tf\tf\td\tD\tD\ts\td\ts\n" );
}
-void printProcessList( const char* cmd )
-{
- ProcessInfo* ps;
-
- (void)cmd;
- /*We return 0 for tracerpid (the pid of any debugger attached to the process) if there is none
- x_identifier is empty if none was found
- x_pxmmem is -1 if not found
- x_numpxm is -1 if not found
- */
- for ( ps = first_ctnr( ProcessList ); ps; ps = next_ctnr( ProcessList ) ) {
- fprintf( CurrentClient, "%s\t%ld\t%ld\t%ld\t%ld\t%s\t%.2f\t%.2f\t%d\t%d\t%d\t%s\t%ld\t%s\n",
- ps->name, (long)ps->pid, (long)ps->ppid,
- (long)ps->uid, (long)ps->gid, ps->status, ps->userLoad,
- ps->sysLoad, ps->niceLevel, ps->vmSize / 1024, ps->vmRss / 1024,
- ps->userName, (long)ps->tracerpid, ps->cmdline
- );
- }
-
- fprintf( CurrentClient, "\n" );
-}
-
void printProcessCount( const char* cmd )
{
(void)cmd;
--- trunk/KDE/kdebase/workspace/ksysguard/ksysguardd/Linux/ProcessList.h #586279:586280
@@ -27,8 +27,6 @@
void initProcessList( struct SensorModul* );
void exitProcessList( void );
-int updateProcessList( void );
-
void printProcessList( const char* );
void printProcessListInfo( const char* );
void printProcessCount( const char* );
--- trunk/KDE/kdebase/workspace/ksysguard/ksysguardd/modules.h #586279:586280
@@ -126,7 +126,7 @@
{ "Memory", initMemory, exitMemory, updateMemory, NULLVVFUNC, 0, NULLTIME },
{ "NetDev", initNetDev, exitNetDev, updateNetDev, NULLVVFUNC, 0, NULLTIME },
{ "NetStat", initNetStat, exitNetStat, NULLIVFUNC, NULLVVFUNC, 0, NULLTIME },
- { "ProcessList", initProcessList, exitProcessList, updateProcessList, NULLVVFUNC, 0, NULLTIME },
+ { "ProcessList", initProcessList, exitProcessList, NULLIVFUNC, NULLVVFUNC, 0, NULLTIME },
{ "Stat", initStat, exitStat, updateStat, NULLVVFUNC, 0, NULLTIME },
{ "Uptime", initUptime, exitUptime, NULLIVFUNC, NULLVVFUNC, 0, NULLTIME },
#endif /* OSTYPE_Linux */
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic