CMS 3D CMS Logo

ResourceInfo.h

Go to the documentation of this file.
00001 #ifndef CLASSLIB_RESOURCE_INFO_H
00002 # define CLASSLIB_RESOURCE_INFO_H
00003 
00004 //<<<<<< INCLUDES                                                       >>>>>>
00005 
00006 # include "classlib/sysapi/system.h"
00007 # include <map>
00008 
00009 namespace lat {
00010 //<<<<<< PUBLIC DEFINES                                                 >>>>>>
00011 //<<<<<< PUBLIC CONSTANTS                                               >>>>>>
00012 //<<<<<< PUBLIC TYPES                                                   >>>>>>
00013 //<<<<<< PUBLIC VARIABLES                                               >>>>>>
00014 //<<<<<< PUBLIC FUNCTIONS                                               >>>>>>
00015 //<<<<<< CLASS DECLARATIONS                                             >>>>>>
00016 
00018 class ResourceInfo
00019 {
00020 public:
00021     typedef unsigned long       Value;
00022     static const Value          LIM_INFINITE = ~0UL; /* FIXME: RLIM_INFINITY? */
00023 
00024     // Resource limit hardness
00025     enum Kind { SOFT, HARD };
00026 
00027     // Known resource limit types
00028     enum Limit
00029     {
00030         LIMIT_CPU_TIME,
00031         LIMIT_FILE_SIZE,
00032         LIMIT_CORE_SIZE,
00033         LIMIT_N_PROCESSES,
00034         LIMIT_N_OPEN_FILES,
00035 
00036         LIMIT_VMEMORY,
00037         LIMIT_VMEMORY_RSS,
00038         LIMIT_VMEMORY_LOCKED,
00039         LIMIT_VMEMORY_DATA,
00040         LIMIT_VMEMORY_STACK,
00041 
00042         LIMIT_MAX = LIMIT_VMEMORY_STACK
00043     };
00044 
00045     // Known resource types
00046     enum Resource
00047     {
00048         // Resources for usage consumption (rusage)
00049         RES_USER_TIME,          // seconds
00050         RES_SYSTEM_TIME,        // seconds
00051         RES_MAX_RSS,            // kB
00052         RES_TEXT_RSS,           // kB*s
00053         RES_DATA_RSS,           // kB*s
00054         RES_STACK_RSS,          // kB*s
00055         RES_MINOR_PAGE_FAULTS,
00056         RES_MAJOR_PAGE_FAULTS,
00057         RES_SWAPS,
00058         RES_FILESYS_OPS_IN,
00059         RES_FILESYS_OPS_OUT,
00060         RES_IPC_MSGS_SENT,
00061         RES_IPC_MSGS_RECEIVED,
00062         RES_SIGNALS,
00063         RES_VOLUNTARY_CONTEXT_SWITCHES,
00064         RES_INVOLUNTARY_CONTEXT_SWITCHES,
00065 
00066         // minfault (process / process + children)
00067         // majfault (process / process + children)
00068         // utime (process / process + children)
00069         // stime (process / process + children)
00070         // swaps (process / process + children)
00071         // times: user/system = cpu, idle (see TimeInfo)
00072 
00073         RES_VMEMORY,
00074         RES_VMEMORY_LOCKED,
00075         RES_VMEMORY_RSS,
00076         RES_VMEMORY_RSS_LIMIT,
00077         RES_VMEMORY_DATA,
00078         RES_VMEMORY_STACK,
00079         RES_VMEMORY_EXE,
00080         RES_VMEMORY_LIBRARIES,
00081         RES_VMEMORY_SHARED,
00082         RES_VMEMORY_DIRTY,
00083         RES_VMEMORY_PERCENTAGE,
00084 
00085         RES_VMEMORY_TEXT_BASE,
00086         RES_VMEMORY_TEXT_TOP,
00087         RES_VMEMORY_BSS_BASE,
00088         RES_VMEMORY_BSS_TOP,
00089         RES_VMEMORY_DATA_BASE,
00090         RES_VMEMORY_DATA_TOP,
00091         RES_VMEMORY_BREAK_BASE,
00092         RES_VMEMORY_BREAK_TOP,
00093         RES_VMEMORY_STACK_BASE,
00094         RES_VMEMORY_STACK_TOP,
00095 
00096         RES_VMEMORY_KERNEL_SP,
00097         RES_VMEMORY_KERNEL_IP,
00098 
00099         // file descriptors? (/proc/self/fd?)
00100         RES_N_FILE_DESCRIPTORS,
00101         RES_MAX_FILE_DESCRIPTORS,
00102 
00103         // process state
00104         RES_PROCESS_STATE,
00105         RES_PROCESS_FLAGS,
00106         RES_PROCESS_LWPS,
00107         RES_PROCESS_ADDRESS,
00108         RES_TIME_SLICE_SIZE,
00109         RES_PRIORITY_NICE,
00110         RES_PRIORITY,
00111         RES_TIMEOUT,
00112         RES_INTERVAL_TIME_LEFT,
00113         RES_START_TIME,
00114         RES_CPU,
00115         RES_CPU_PERCENTAGE,
00116 
00117         RES_INITIAL_ARGC,
00118         RES_INITIAL_ARGV,
00119         RES_INITIAL_ENVP,
00120 
00121         RES_DATA_MODEL,
00122 
00123         // pid, ppid, pgrp, sid, tty, tpgid?
00124         // memory area maps? mmaps?
00125         // root?
00126         // pending signals?
00127         // blocked signals?
00128         // ignored signals?
00129         // caught signals?
00130         // wait channel?
00131 
00132         // system resource status? (total vmem, swap, ...)?
00133         RES_MAX
00134     };
00135 
00136     enum Source {
00137         RES_FOR_SYSTEM,
00138         RES_FOR_SELF,
00139         RES_FOR_SELF_AND_CHILDREN
00140     };
00141 
00142     typedef std::map<Resource,Value> Status;
00143 
00144     static Value        getlimit  (Limit type, Kind which);
00145     static void         getlimits (Limit type, Value &soft, Value &hard);
00146     static Value        setlimit  (Limit type, Kind which, Value value);
00147     static void         setlimits (Limit type, Value soft, Value hard);
00148 
00149     static Status       info (Source from);
00150     static Status &     info (Source from, Status &which);
00151 
00152     static Status       info_system (void);
00153     static Status       info_self (void);
00154     static Status       info_self_cumulative (void);
00155 
00156     static const char * name (Resource type);
00157     static const char * unit (Resource type);
00158     static const char * format (Resource type, Value value,
00159                                 char *buffer, size_t size);
00160 
00161     // FIXME: get vmstats
00162     //   - linux:   /proc/self/status
00163     //   - solaris: /proc/self/status (read pstatus.pr_brkbase,
00164     //               .pr_brksize, .pr_stkbase, .pr_stksize)
00165     //              or maybe psinfo (psinfo.pr_size, .pr_rssize)
00166     //   - unix: ps -o vsz= -o rss= -p <PID>
00167 
00168     // FIXME: file descriptor limits: getdtablehi() (maxfd + 1)
00169 
00170     // FIXME: resource usage
00171     //   - linux: read /proc/self/stat (or status)
00172     //   - solaris: read /proc/self/usage
00173 
00174     // FIXME: system information
00175     //   - linux: /proc/cpuinfo etc.
00176     //   - hpux:  pstat_getstatic(), pstat_getdynamic(), pstat_getvminfo()
00177 
00178     // FIXME: open files
00179     //   - linux, solaris: /proc/self/fd/N
00180     //   - hpux: pstat_getfile()
00181 
00182     // FIXME: for hp-ux, look pstat man page and Mike Stroyan's mails.
00183 
00184     // FIXME: for IRIX, look at https://reality.sgi.com/davea/software.html
00185     // and https://reality.sgi.com/performer/perf-95-09/0153.html
00186     // and IRIX Device Driver Programmer's Guide at
00187     //     https://dmawww.epfl.ch/ebt-bin/nph-dweb/dynaweb/SGI_Developer/
00188     //     DevDriver_PG/@Generic__BookTextView/2687
00189     // and https://dmawww.epfl.ch:80/ebt-bin/nph-dweb/dynaweb/SGI_Developer/
00190     //     T_IRIX_Prog/@Generic__BookView?DwebQuery=syssgi
00191     // Virtual and resident sizes of a process: syssgi(SGI_PROCSZ,
00192     // pid, &uiSZ, &uiRSS);
00193     // https://www.mcsr.olemiss.edu/cgi-bin/man-cgi?syssgi+2
00194 
00195     // FIXME: on linux, use /proc/self/statm to get process memory stats
00196     // FIXME: on solaris, use /proc/self/status, usage, map (or rmap?)
00197 
00198     // FIXME: get resource limits with getrlimit
00199 
00200     // FIXME: time usage: times(2)
00201 
00202 private:
00203     struct Details
00204     {
00205         Resource        resource;
00206         const char      *name;
00207         const char      *unit;
00208         const char      *format;
00209     };
00210 
00211     static const Details        s_resource_details [];
00212 };
00213 
00214 //<<<<<< INLINE PUBLIC FUNCTIONS                                        >>>>>>
00215 
00216 } // namespace lat
00217 #endif // CLASSLIB_RESOURCE_INFO_H

Generated on Tue Jun 9 17:38:53 2009 for CMSSW by  doxygen 1.5.4