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:
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 |
|
Convert a macro argument to a string.
|
|
A version of perror(3) that prints out the file and line number.
|
|
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.
|
|
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.
|
|
Create a resource set and CPU reserve for ourself. Otherwise, we might not get CPU time to do the recording.
|
|
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.
|
|
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.
|
|
Process the command line options.
|
|
Print out the usage statement to a file handle.
|
|
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.
|
|
Handle a SIGCHLD signal. This function will be called when the child exits.
|
|
Handle a SIGINT/SIGTERM signal when no utility is being monitored.
|
|
Handle a SIGIO signal. This function will be called when the server socket has a new connection waiting to be accept(2)'d.
|
|
A signal handler that passes the received signal on to the child process.
|