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

childProcess.h

Go to the documentation of this file.
00001 /*
00002  * childProcess.h
00003  *
00004  * Copyright (c) 2003 The University of Utah and the Flux Group.
00005  * All rights reserved.
00006  *
00007  * This file is licensed under the terms of the GNU Public License.  
00008  * See the file "license.terms" for restrictions on redistribution 
00009  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00010  */
00011 
00012 /**
00013  * @file childProcess.h
00014  *
00015  * Header file for the child process accounting functions.
00016  */
00017 
00018 #ifndef _child_process_h
00019 #define _child_process_h
00020 
00021 #ifdef __cplusplus
00022 extern "C" {
00023 #endif
00024 
00025 #include <sys/types.h>
00026 
00027 #include <listNode.h>
00028 
00029 /*
00030  * A cpChildProcess is used to track and record the resource usage of a child
00031  * process.
00032  *
00033  * cp_Link - List link.
00034  * cp_PID - The process ID of the child.
00035  * cp_ProcFileName - The path to the process stats for this child in /proc.
00036  * cp_Output - The statistics file for this child.
00037  * cp_LastUsage - The last recorded usage for this child.  Used to compute
00038  *   the difference in usage between the current and last sample time.
00039  */
00040 struct cpChildProcess {
00041     struct lnMinNode cp_Link;
00042     pid_t cp_PID;
00043     const char *cp_ProcFileName;
00044     FILE *cp_Output;
00045 #if defined(linux) || defined(__FreeBSD__)
00046     struct timeval cp_LastUsage;
00047 #else
00048 #error "Implement me"
00049 #endif
00050 };
00051 
00052 enum {
00053     CPDB_INITIALIZED,
00054 };
00055 
00056 /*
00057  * Flags for the cpChildProcessData structure.
00058  *
00059  * CPDF_INITIALIZED - The global data is initialized.
00060  */
00061 enum {
00062     CPDF_INITIALIZED = (1L << CPDB_INITIALIZED),
00063 };
00064 
00065 /*
00066  * Global data for tracking child processes.
00067  *
00068  * cpd_Flags - Holds the CPDF_ flags.
00069  * cpd_Children - The list of child processes.
00070  */
00071 struct cpChildProcessData {
00072     unsigned long cpd_Flags;
00073     struct lnMinList cpd_Children;
00074 };
00075 
00076 /**
00077  * Initialize the internal accounting data structures.
00078  *
00079  * @return True on success, false otherwise.
00080  */
00081 int cpInitChildProcessData(void);
00082 
00083 /**
00084  * Deinitialize the internal accounting data structures.
00085  */
00086 void cpKillChildProcessData(void);
00087 
00088 /**
00089  * Find the cpChildProcess structure that corresponds to the given ID.
00090  *
00091  * @param child_pid The child process to track.
00092  * @return The cpChildProcess object that corresponds to the given ID or NULL
00093  * if one has not been created yet.
00094  */
00095 struct cpChildProcess *cpFindChildProcess(pid_t child_pid);
00096 
00097 /**
00098  * Create a cpChildProcess object for a child that does not have one yet.
00099  *
00100  * @callgraph
00101  *
00102  * @param child_pid The child process to track.
00103  * @return The newly created object or NULL if a problem was encountered
00104  * during creation.
00105  */
00106 struct cpChildProcess *cpCreateChildProcess(pid_t child_pid);
00107 
00108 /**
00109  * Delete the given cpChildProcess object.
00110  *
00111  * @param cp NULL or a previously created cpChildProcess object.
00112  */
00113 void cpDeleteChildProcess(struct cpChildProcess *cp);
00114 
00115 /**
00116  * Open and initialize the statistics output file for the given cpChildProcess
00117  * object.  The created file will have the form "<base_name>-<pid>.out".
00118  *
00119  * @param cp A valid cpChildProcess object.
00120  * @param base_name The file name prefix.
00121  * @param start_time The start time for the parent process.
00122  * @return True if the file was created successfully, false otherwise.
00123  */
00124 int cpOpenOutput(struct cpChildProcess *cp,
00125                  const char *base_name,
00126                  struct timeval *start_time);
00127 
00128 /**
00129  * Sample the resource usage for a given child process.
00130  *
00131  * @param cp A valid cpChildProcess object.
00132  * @param run_time The amount of time the parent process has been running.
00133  * @return The CPU usage, in microseconds, for the given child process.
00134  */
00135 unsigned long long cpSampleUsage(struct cpChildProcess *cp,
00136                                  struct timeval *run_time);
00137 
00138 #ifdef __cplusplus
00139 }
00140 #endif
00141 
00142 #endif

Generated on Fri Oct 22 07:50:24 2004 for CPU Broker by  doxygen 1.3.9.1