00001 #ifndef CLASSLIB_RESOURCE_INFO_H
00002 # define CLASSLIB_RESOURCE_INFO_H
00003
00004
00005
00006 # include "classlib/sysapi/system.h"
00007 # include <map>
00008
00009 namespace lat {
00010
00011
00012
00013
00014
00015
00016
00018 class ResourceInfo
00019 {
00020 public:
00021 typedef unsigned long Value;
00022 static const Value LIM_INFINITE = ~0UL;
00023
00024
00025 enum Kind { SOFT, HARD };
00026
00027
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
00046 enum Resource
00047 {
00048
00049 RES_USER_TIME,
00050 RES_SYSTEM_TIME,
00051 RES_MAX_RSS,
00052 RES_TEXT_RSS,
00053 RES_DATA_RSS,
00054 RES_STACK_RSS,
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
00067
00068
00069
00070
00071
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
00100 RES_N_FILE_DESCRIPTORS,
00101 RES_MAX_FILE_DESCRIPTORS,
00102
00103
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
00124
00125
00126
00127
00128
00129
00130
00131
00132
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
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
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
00215
00216 }
00217 #endif // CLASSLIB_RESOURCE_INFO_H