latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 00024 00025 /*---------------------------------------------------------------- 00026 * project ....: LTI Digital Image/Signal Processing Library 00027 * file .......: ltiProcessInfo.h 00028 * authors ....: Jochen Wickel 00029 * organization: LTI, RWTH Aachen 00030 * creation ...: 30.10.00 00031 * revisions ..: $Id: ltiProcessInfo.h,v 1.5 2006/02/08 12:54:06 ltilib Exp $ 00032 */ 00033 00034 #ifndef _LTI_PROCESSINFO_H_ 00035 #define _LTI_PROCESSINFO_H_ 00036 00037 #include "ltiObject.h" 00038 #include <string> 00039 00040 #ifndef _LTI_WIN32 00041 #else 00042 00043 /* 00044 * In case of WinNT queriing system registry using performance- 00045 * datahelper Pdh (you may need to specify its library in 00046 * Project..Settings..Link..Object/Library Modules.) 00047 * Pdh.lib and pdh.dll are needed. 00048 * 00049 * Microsoft didn't include PDH.DLL in some releases of Windows NT. 00050 * You can download the PDH file for winnt from 00051 * http://support.microsoft.com/default.aspx?scid=kb;en-us;Q284996, 00052 * or search the Microsoft Knowledge Base for article "Q284996". 00053 * 00054 * NOTE: For Windows 2000-based systems, use the system-supplied Pdh.dll file. 00055 * Do not install a new version of Pdh.dll over the system-supplied version. 00056 * This will fail because of Windows File Protection. For Windows NT 4.0, 00057 * install Pdh.dll into the private directory of the application ltilib\bin 00058 * (not into the system directory). 00059 * You have the following nonexclusive, royalty-free rights subject to the 00060 * Distribution Requirements: You may distribute PDH.dll on Windows NT 4.0. 00061 */ 00062 00063 struct PROCESS_MEMORY_COUNTERS; 00064 00065 #endif 00066 00067 namespace lti { 00068 00069 /** 00070 * LTI-Lib process info class. An object of this class can be used 00071 * among other things to get the amount of memory used by the process. 00072 * 00073 * For MS Windows NT you will require the library Pdh.lib/pdh.dll 00074 * available under: http://support.microsoft.com/default.aspx?scid=kb;en-us;Q284996 00075 * or search the Microsoft Knowledge Base for article "Q284996" 00076 */ 00077 class processInfo : public object { 00078 #ifndef _LTI_WIN32 00079 /** 00080 * buffer to construct a device path 00081 */ 00082 char procPath[80]; 00083 #endif 00084 protected: 00085 /** 00086 * system depended structure 00087 */ 00088 struct procStatus { 00089 public: 00090 #ifdef _LTI_LINUX 00091 /** 00092 * default constructor 00093 * set default values and init array for cpu clockrate storage 00094 */ 00095 procStatus(); 00096 00097 /** 00098 * destructor 00099 * delete memory allocated in constructor 00100 */ 00101 ~procStatus(); 00102 00103 /** 00104 * number of processors in this system (available for Linux only) 00105 */ 00106 static const int MAX_SYSTEM_CPUS; 00107 00108 /** 00109 * @name Linux attributes 00110 */ 00111 //@{ 00112 00113 /** 00114 * The process id 00115 */ 00116 int pid; 00117 00118 /** 00119 * The filename of the executable 00120 */ 00121 char *comm; 00122 00123 /** 00124 * State of process, in Linux: one of [RSDZT] 00125 */ 00126 char state; 00127 00128 /** 00129 * parent process id 00130 */ 00131 int ppid; 00132 00133 /** 00134 * group id 00135 */ 00136 int pgrp; 00137 00138 /** 00139 * number of page faults so far 00140 */ 00141 unsigned int majflt; 00142 00143 /** 00144 * number of page faults of process and its children 00145 */ 00146 unsigned int cmajflt; 00147 00148 /** 00149 * priority, i.e. nice level 00150 */ 00151 int priority; 00152 00153 /** 00154 * virtual memory size 00155 */ 00156 int vsize; 00157 00158 /** 00159 * resident set size 00160 */ 00161 int rss; 00162 00163 /** 00164 * total core memory 00165 */ 00166 int coremem; 00167 00168 /** 00169 * total swap memory 00170 */ 00171 int swapmem; 00172 00173 /** 00174 * free core memory 00175 */ 00176 int freecoremem; 00177 00178 /** 00179 * buffers actual used 00180 */ 00181 int buffers; 00182 00183 /** 00184 * cached memory used 00185 */ 00186 int cached; 00187 00188 /** 00189 * free swap memo 00190 */ 00191 int freeswapmem; 00192 00193 /** 00194 * cpu number 00195 */ 00196 int numberofcpus; 00197 00198 /** 00199 * clockrate 00200 */ 00201 int* clockrate; 00202 00203 /** 00204 * processorload 00205 */ 00206 float processorload; 00207 //@} 00208 #endif 00209 00210 #ifdef _LTI_WIN32 00211 /** 00212 * @name Windows Attributes 00213 */ 00214 //@{ 00215 /** 00216 * default constructor 00217 * set default values and init array for cpu clockrate storage 00218 */ 00219 procStatus(); 00220 00221 /** 00222 * destructor 00223 * delete memory allocated in constructor 00224 */ 00225 ~procStatus(); 00226 /** 00227 * number of processors in this system 00228 */ 00229 static const int MAX_SYSTEM_CPUS; 00230 /** 00231 * process id 00232 */ 00233 void* pid; 00234 /** 00235 * working set size 00236 */ 00237 unsigned int wss; 00238 /** 00239 * page file usage 00240 */ 00241 unsigned int pfu; 00242 /** 00243 * clockrate 00244 */ 00245 int* clockrate; 00246 /** 00247 * number of CPUs 00248 */ 00249 int numberOfCPUs; 00250 //@} 00251 #endif 00252 }; 00253 00254 public: 00255 /** 00256 * default constructor 00257 */ 00258 processInfo(); 00259 00260 /** 00261 * destructor. 00262 */ 00263 virtual ~processInfo(); 00264 00265 /** 00266 * returns the name of this type 00267 */ 00268 virtual const char* getTypeName() const; 00269 00270 /** 00271 * Returns the amount of virtual memory used by this process in kBytes. 00272 * The actual meaning of this value depends on the operating system: 00273 * In Unix-like OSs it really means the total amount of virtual memory 00274 * allocated to this process. In WinNT, it means the size of the page 00275 * file fragment that has been reserved to the process. 00276 */ 00277 int getUsedVirtualMemory(); 00278 00279 /** 00280 * Returns the amount of core memory. What this means, differs 00281 * depending on the OS. In Unix, it really is the amount of physical 00282 * RAM that is occupied by this process. In WinNT, it is the size of 00283 * the working set, which may be larger than the allocated pagefile 00284 * segment. It is not quite clear what the term "working set" in 00285 * windows actually means. One document states that it is the amount 00286 * of physical RAM the process occupies. Another document states that it 00287 * is the average amount of memory the process accesses without causing 00288 * a page fault. So, in WinNT, the result of this function is best 00289 * interpreted as a guess. 00290 */ 00291 int getUsedCoreMemory(); 00292 00293 /** 00294 * Returns the amount of total available virtual memory in kBytes. 00295 * In case of an error the function returns (-1) 00296 */ 00297 int getVirtualMemory(); 00298 00299 /** 00300 * Returns the amount of total available core memory in kBytes. 00301 * In case of an error the function returns (-1) 00302 */ 00303 int getCoreMemory(); 00304 00305 /** 00306 * Returns the amount of free core memory in kBytes. 00307 * In case of an error the function returns (-1) 00308 */ 00309 int getFreeCoreMemory(); 00310 00311 /** 00312 * Returns the amount of used buffers in kBytes. 00313 * In case of an error and in WinNT the function returns (-1) 00314 */ 00315 int getBuffers(); 00316 00317 /** 00318 * Returns the amount of memory cached in kBytes. 00319 * In case of an error and in WinNT the function returns (-1) 00320 */ 00321 int getCachedMemory(); 00322 00323 /** 00324 * Returns the amount of free swap memory in kBytes. 00325 * In case of WinNT the function returns the free disk space 00326 * available to the PageFile. 00327 * In case of an error the function returns (-1) 00328 */ 00329 int getFreeSwapMemory(); 00330 00331 /** 00332 * Returns the amount of free virtual system memory in kBytes. 00333 * In case of an error the function returns (-1) 00334 */ 00335 int getFreeVirtualMemory(); 00336 00337 /** 00338 * Returns the number of CPUs in the measured system. 00339 * Uses the /proc/cpuinfo file in linux systems. 00340 * In case of an error the function returns (0). 00341 */ 00342 int getNumberOfCPUs(); 00343 00344 /** 00345 * Returns an array of the processor clock rates. 00346 * Uses the /proc/cpuinfo file in linux systems. 00347 * In WinNT the function returns clock rate 00348 * only for systems with one processor 00349 */ 00350 int* getProcessorClockRate(); 00351 00352 /** 00353 * Returns the ProcessorLoad of the last minute. 00354 * Uses the /proc/loadavg file in linux systems. 00355 * In case of an error the function returns (-1). 00356 * In case of WinNT calling Win32 API routine, 00357 * you may need to specify its library in 00358 * Project..Settings..Link..Object/Library Modules. 00359 * here: Pdh.lib and you also need Pdh.dll 00360 */ 00361 float getProcessorLoad(); 00362 00363 /** 00364 * Return the actual meaning of "k" (1000 or 1024) 00365 */ 00366 inline int getSizeOfK() const { return sizeOfK; }; 00367 00368 /** 00369 * Set the meaning of "k" as 1024 (2^10) 00370 */ 00371 inline void kEquals1024() { sizeOfK=1024; }; 00372 00373 /** 00374 * Set the meaning of "k" as 10^3 00375 */ 00376 inline void kEquals1000() { sizeOfK=1000; }; 00377 00378 /** 00379 * Returns the name of the host this process is running on. 00380 */ 00381 std::string getHostname() const; 00382 00383 /** 00384 * Returns the user ID of the user that has started the process. 00385 */ 00386 std::string getUsername() const; 00387 00388 /** 00389 * Returns the process ID of the current process/thread. 00390 */ 00391 long getPid() const; 00392 00393 private: 00394 procStatus state; 00395 int sizeOfK; 00396 #ifndef _LTI_WIN32 00397 char *commBuffer; 00398 int bufLength; 00399 void getCurrentCPUStatus(); 00400 void getCurrentStatus(); 00401 void getCurrentSystemStatus(); 00402 void readBuffer(); 00403 #else 00404 PROCESS_MEMORY_COUNTERS *commBuffer; 00405 void getCurrentStatus(); 00406 long ReadRDTSCTimer(); 00407 void getCpuStatus(); 00408 #endif 00409 }; 00410 00411 } 00412 00413 #endif