Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

rktimes.c File Reference


Detailed Description

Main file for a sampling time(1)-like command.

Unlike time(1) though, it will not wait until the end of a run to report the CPU usage, it continuously reports the usage in a form fit for consumption by gnuplot. In addition, it can act as a server for a GKrellm client so the data can be viewed instantaneously in a nice GUI.

Include dependency graph for rktimes.c:

Include dependency graph

Defines

#define SAMPLES_PER_SECOND   1
 Number of times per second to record CPU usage samples.

#define MAX_CLIENTS   8
 Maximum number of gkrellm clients.

#define CLIENT_BUFFER_MAX   4096
 Size of the buffer used to format gkrellm output.

#define __XSTRING(x)   __STRING(x)
 Convert a macro argument to a string.

#define my_perror(x)   perror(x ", file " __FILE__ ", line " __XSTRING(__LINE__))
 A version of perror(3) that prints out the file and line number.

#define MAX_PROC_LIST   128
#define MAX_RK_SETS   128

Enumerations

enum  { RKTB_DONE, RKTB_CREATED_RESOURCE_SET }
enum  { RKTF_DONE = (1L << RKTB_DONE), RKTF_CREATED_RESOURCE_SET = (1L << RKTB_CREATED_RESOURCE_SET) }

Functions

void rktClientWrite (unsigned int index, char *buffer, size_t len)
 Write a byte array to a client's socket.

void sigpass (int sig)
 A signal handler that passes the received signal on to the child process.

void sigalrm (int sig)
 The SIGALRM signal handler.

void sigchld (int sig)
 Handle a SIGCHLD signal.

void sigexit (int sig)
 Handle a SIGINT/SIGTERM signal when no utility is being monitored.

void sigio (int sig)
 Handle a SIGIO signal.

rk_resource_set_t rktCreateSelfResourceSet (char *name)
 Create a resource set and CPU reserve for ourself.

rk_resource_set_t rktGetChildResourceSet (char *requested_name, char *default_name)
 Get a resource set for the child process.

void rktUsage (FILE *file, char *prog_name)
 Print out the usage statement to a file handle.

int rktProcessOptions (int *argc_inout, char **argv_inout[])
 Process the command line options.

int rktParentPart (rk_resource_set_t rs)
 The parent portion of the fork(2) between rktimes and the monitored utility.

int rktChildPart (rk_resource_set_t rs, char *argv[])
 The child portion of the fork(2) between rktimes and the monitored utility.

int main (int argc, char *argv[])

Variables

struct {
   unsigned long   rkt_Flags
   char *   rkt_UtilityName
   timeval   rkt_StartTime
   char *   rkt_OutputBase
   char *   rkt_Name
   rk_resource_set_t   rkt_ResourceSet
   pid_t   rkt_ChildPID
   int   rkt_ServerSocket
   char   rkt_ClientBuffer [CLIENT_BUFFER_MAX]
   int   rkt_ClientSockets [MAX_CLIENTS]
rktimes_data

Define Documentation

#define __XSTRING  )     __STRING(x)
 

Convert a macro argument to a string.

Parameters:
The macro to expand to a string.

#define my_perror  )     perror(x ", file " __FILE__ ", line " __XSTRING(__LINE__))
 

A version of perror(3) that prints out the file and line number.

Parameters:
x The prefix string for the error string.


Function Documentation

int rktChildPart rk_resource_set_t  rs,
char *  argv[]
[static]
 

The child portion of the fork(2) between rktimes and the monitored utility.

This function will attach the child to the given resource set and exec(3) the utility to monitor with the given arguments.

Parameters:
rs The child's resource set.
argv The utility to startup and its arguments.
Returns:
A failure exit code, otherwise this function will not return because of the exec(3).
See also:
rktParentPart

void rktClientWrite unsigned int  index,
char *  buffer,
size_t  len
[static]
 

Write a byte array to a client's socket.

If they happen to fall behind or some other error is encountered, the socket is closed immediately and erased from the rktimes_data.rkt_ClientSockets array.

Parameters:
index The client index in rktimes_data.rkt_ClientSockets.
buffer The buffer to write to the socket.
len The length of the buffer.

rk_resource_set_t rktCreateSelfResourceSet char *  name  )  [static]
 

Create a resource set and CPU reserve for ourself.

Otherwise, we might not get CPU time to do the recording.

Parameters:
name The name for the resource set.
Returns:
A resource set for this process.

rk_resource_set_t rktGetChildResourceSet char *  requested_name,
char *  default_name
[static]
 

Get a resource set for the child process.

If a resource set already exists with the requested name, that will be used. Otherwise, a new one will be created. If no name is requested, a new set will be created with the default name.

Parameters:
requested_name The requested resource set name or NULL if the default should be used.
default_name The default resource set name to use if requested_name is NULL.
Returns:
The resource set to use for the child process or NULL_RESOURCE_SET if a set could not be created.

int rktParentPart rk_resource_set_t  rs  )  [static]
 

The parent portion of the fork(2) between rktimes and the monitored utility.

This function will attach itself to a resource set to ensure that it has some CPU time to work and then wait for gkrellm connections or the child's death.

Parameters:
rs The resource set for the rktimes process.
Returns:
The return code for main().
See also:
rktChildPart

int rktProcessOptions int *  argc_inout,
char **  argv_inout[]
[static]
 

Process the command line options.

Parameters:
argc_inout Pointer to main's argc variable. On return, the variable will contain the number of arguments remaining after option processing.
argv_inout Pointer to main's argv variable. On return, the variable will contain the remaining argument values.
Returns:
True if the options were processed correctly, false otherwise.

void rktUsage FILE *  file,
char *  prog_name
[static]
 

Print out the usage statement to a file handle.

Parameters:
file The destination file handle for the usage output.
prog_name The program name.

void sigalrm int  sig  )  [static]
 

The SIGALRM signal handler.

This function will be called SAMPLES_PER_SECOND times a second to read the CPU usage of the resource set's processes. The data is then output to a file and echoed to any gkrellm clients.

Parameters:
sig The actual signal number received.
See also:
gkemu.h

childProcess.h

void sigchld int  sig  )  [static]
 

Handle a SIGCHLD signal.

This function will be called when the child exits.

Parameters:
The actual signal number received.

void sigexit int  sig  )  [static]
 

Handle a SIGINT/SIGTERM signal when no utility is being monitored.

Parameters:
The actual signal number received.

void sigio int  sig  )  [static]
 

Handle a SIGIO signal.

This function will be called when the server socket has a new connection waiting to be accept(2)'d.

Parameters:
The actual signal number received.

void sigpass int  sig  )  [static]
 

A signal handler that passes the received signal on to the child process.

Parameters:
sig The actual signal number received.


Generated on Mon Dec 1 16:22:30 2003 for CPUBroker by doxygen 1.3.4