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.

Definition in file rktimes.c.

Include dependency graph for rktimes.c:

Include dependency graph

Go to the source code of this file.

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
 Maximum number of processes to query in the resource set.


Enumerations

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

Functions

void rktClientWrite (unsigned int index, const 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 (rk_resource_set_t rs, const char *requested_name, const char *default_name, unsigned int child_period, unsigned int child_compute)
 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
   const char *   rkt_UtilityName
   timeval   rkt_StartTime
   const char *   rkt_OutputBase
   const char *   rkt_Name
   unsigned int   rkt_ChildPeriod
   unsigned int   rkt_ChildCompute
   rk_resource_set_t   rkt_ResourceSet
   pid_t   rkt_ChildPID
   int   rkt_ServerSocket
   char   rkt_ClientBuffer [CLIENT_BUFFER_MAX]
   int   rkt_ClientSockets [MAX_CLIENTS]
   unsigned long   rkt_ClientFlags [MAX_CLIENTS]
rktimes_data


Define Documentation

#define __XSTRING  )     __STRING(x)
 

Convert a macro argument to a string.

Parameters:
x The macro to expand to a string.

Definition at line 73 of file rktimes.c.

#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.

Definition at line 81 of file rktimes.c.

Referenced by rktChildPart(), rktCreateSelfResourceSet(), rktGetChildResourceSet(), rktParentPart(), rktProcessOptions(), sigalrm(), and sigpass().


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 execvp(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 execvp(3).
See also:
rktParentPart

Definition at line 1055 of file rktimes.c.

References ensure, my_perror, NULL_RESOURCE_SET, require, rk_inherit_mode(), rk_resource_set_attach_process(), and rk_resource_set_t.

Here is the call graph for this function:

void rktClientWrite unsigned int  index,
const 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.

Definition at line 158 of file rktimes.c.

References MAX_CLIENTS, and require.

Referenced by sigalrm(), and sigio().

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.

Definition at line 431 of file rktimes.c.

References cpu_reserve_attr::blocking_time, cpu_reserve_attr::compute_time, cpu_reserve_attr::deadline, rk_reserve_param::enf_mode, my_perror, NULL_RESOURCE_SET, cpu_reserve_attr::period, cpu_reserve_attr::processor, rk_reserve_param::rep_mode, require, cpu_reserve_attr::reserve_type, RK_ANY_CPU, rk_cpu_reserve_create(), RK_NAME_LEN, rk_reserve_t, rk_resource_set_create(), rk_resource_set_destroy(), rk_resource_set_t, RSV_SOFT, rk_reserve_param::sch_mode, and cpu_reserve_attr::start_time.

Here is the call graph for this function:

rk_resource_set_t rktGetChildResourceSet rk_resource_set_t  rs,
const char *  requested_name,
const char *  default_name,
unsigned int  child_period,
unsigned int  child_compute
[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:
rs An existing resource set that should be used.
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.
child_period The child's period in microseconds or zero if no CPU reserve should be created.
child_compute The child's compute time in microseconds.
Returns:
The resource set to use for the child process or NULL_RESOURCE_SET if a set could not be created.

Definition at line 494 of file rktimes.c.

References cpu_reserve_attr::blocking_time, cpu_reserve_attr::compute_time, cpu_reserve_attr::deadline, rk_reserve_param::enf_mode, my_perror, NULL_RESERVE, NULL_RESOURCE_SET, cpu_reserve_attr::period, cpu_reserve_attr::processor, rk_reserve_param::rep_mode, require, cpu_reserve_attr::reserve_type, RK_ANY_CPU, rk_cpu_reserve_create(), rk_cpu_reserve_delete(), RK_NAME_LEN, rk_reserve_t, rk_resource_set_create(), rk_resource_set_get_cpu_rsv(), rk_resource_set_get_num_procs(), rk_resource_set_t, RSV_SOFT, rk_reserve_param::sch_mode, and cpu_reserve_attr::start_time.

Here is the call graph for this function:

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

Definition at line 885 of file rktimes.c.

References ensure, my_perror, NULL_RESOURCE_SET, require, rk_resource_set_attach_process(), rk_resource_set_t, SAMPLES_PER_SECOND, sigalrm(), sigchld(), sigexit(), sigio(), and sigpass().

Here is the call graph for this function:

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:
Zero if the options were processed correctly, > 0 if there was an error and the usage should be printed, or < 0 if the program should exit immediately.

Definition at line 644 of file rktimes.c.

References my_perror, NULL_RESOURCE_SET, require, RK_NAME_LEN, rk_resource_set_get_by_name(), string_to_microsec(), and us_time.

Here is the call graph for this function:

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.

Definition at line 594 of file rktimes.c.

References require.

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

Definition at line 212 of file rktimes.c.

References CLIENT_BUFFER_MAX, cpu_reserve_attr::compute_time, cpCreateChildProcess(), cpFindChildProcess(), cpOpenOutput(), cpSampleUsage(), cpu_reserve_attr::deadline, GKA_CPUIdle, GKA_CPUReserveIdle, GKA_CPUReserveNice, GKA_CPUReserveUser, GKA_CPUUser, GKA_Processes, GKA_ProcessesRunning, GKA_TAG_DONE, GKA_UpTime, gkFormatUpdate(), gkInitialUpdateClose, gkInitialUpdateOpen, MAX_CLIENTS, MAX_PROC_LIST, my_perror, NULL_RESERVE, cpu_reserve_attr::period, require, rk_cpu_reserve_get_attr(), rk_reserve_t, rk_resource_set_get_cpu_rsv(), rk_resource_set_get_proclist(), rktClientWrite(), and SAMPLES_PER_SECOND.

Referenced by rktParentPart().

Here is the call graph for this function:

void sigchld int  sig  )  [static]
 

Handle a SIGCHLD signal.

This function will be called when the child exits.

Parameters:
sig The actual signal number received.

Definition at line 347 of file rktimes.c.

References require.

Referenced by rktParentPart().

void sigexit int  sig  )  [static]
 

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

Parameters:
sig The actual signal number received.

Definition at line 360 of file rktimes.c.

References require.

Referenced by rktParentPart().

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:
sig The actual signal number received.

Definition at line 373 of file rktimes.c.

References CLIENT_BUFFER_MAX, GKA_HostName, GKA_SystemName, GKA_TAG_DONE, gkFormatPreamble(), MAX_CLIENTS, require, and rktClientWrite().

Referenced by rktParentPart().

Here is the call graph for this function:

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.

Definition at line 188 of file rktimes.c.

References my_perror, and require.

Referenced by rktParentPart().


Generated on Mon Dec 1 16:30:17 2003 for CPU Broker by doxygen 1.3.4