![]() |
|
|
Generated: 8 Jan 2009 |
Note: OS specific details for process timing.
Note: OS specific details as well as Gaudi details may not occur in this definition file, because this header is the used by both, the OS specific implementations and the gaudi specific implementation.
ModuleInfo: OS specific details to access at run-time the module configuration of the process.
Note: OS specific details for memory usage.
Entrypoints:
Since e.g. IID is defined in both, this would lead automatically to complete comilation failures.....
Entrypoints:
On Windows NT Time is expressed as the amount of time that has elapsed since midnight on January 1, 1601 at Greenwich, England.
On Unix time is expressed as the amount of time that has elapsed since midnight on January 1, 1970 at Greenwich, England.
History :
+---------+----------------------------------------------+--------+
| Date | Comment | Who |
+---------+----------------------------------------------+--------+
| 11/11/00| Initial version. | MF |
+---------+----------------------------------------------+--------+
Classes | |
| class | PathResolver |
| struct | PROCESS_BASIC_INFORMATION |
| struct | QUOTA_LIMITS |
| Process Quotas NtQueryInformationProcess using ProcessQuotaLimits NtQueryInformationProcess using ProcessPooledQuotaLimits NtSetInformationProcess using ProcessQuotaLimits. More... | |
| struct | IO_COUNTERS |
| Process I/O Counters NtQueryInformationProcess using ProcessIoCounters. More... | |
| struct | VM_COUNTERS |
| Process Virtual Memory Counters NtQueryInformationProcess using ProcessVmCounters. More... | |
| struct | POOLED_USAGE_AND_LIMITS |
| Process Pooled Quota Usage and Limits NtQueryInformationProcess using ProcessPooledUsageAndLimits. More... | |
| struct | KERNEL_USER_TIMES |
| Process/Thread System and User Time NtQueryInformationProcess using ProcessTimes NtQueryInformationThread using ThreadTimes. More... | |
| class | ProcessDescriptor |
| Provides access to process information. More... | |
Typedefs | |
| typedef void * | ImageHandle |
| Definition of an image handle. | |
| typedef void * | ProcessHandle |
| Definition of the process handle. | |
| typedef unsigned long(* | EntryPoint )(const unsigned long iid, void **ppvObject) |
| Definition of the "generic" DLL entry point function. | |
| typedef void *(* | Creator )() |
| Definition of the "generic" DLL entry point function. | |
| typedef void * | ThreadHandle |
| A Thread handle. | |
| typedef struct _PEB * | PPEB |
| Basic Process Information NtQueryInformationProcess using ProcessBasicInfo. | |
Enumerations | |
| enum | MemoryUnit { Byte, kByte, MByte, GByte, TByte, PByte, EByte } |
| Unit of memory. More... | |
| enum | ModuleType { UNKNOWN, SHAREDLIB, EXECUTABLE } |
| enum | InfoType { NoFetch, RemainTime, Times, ProcessBasics, PriorityBoost, Memory, Quota, System, Modules, IO } |
| Enumeration for fetching information. More... | |
| enum | TimeType { Year, Month, Day, Hour, Min, Sec, milliSec, microSec, nanoSec } |
| Time type for conversion. More... | |
| enum | PR_file_type { PR_regular_file, PR_directory } |
| enum | PR_search_type { PR_local, PR_recursive } |
| enum | ProcessInfoCommand { ProcessBasicInformation, ProcessQuotaLimits, ProcessIoCounters, ProcessVmCounters, ProcessTimes, ProcessBasePriority, ProcessRaisePriority, ProcessDebugPort, ProcessExceptionPort, ProcessAccessToken, ProcessLdtInformation, ProcessLdtSize, ProcessDefaultHardErrorMode, ProcessIoPortHandlers, ProcessPooledUsageAndLimits, ProcessWorkingSetWatch, ProcessUserModeIOPL, ProcessEnableAlignmentFaultFixup, ProcessPriorityClass, ProcessWx86Information, ProcessHandleCount, ProcessAffinityMask, ProcessPriorityBoost, MaxProcessInfoClass, ProcessEllapsedTime } |
Functions | |
| long | breakExecution () |
| Break the execution of the application and invoke the debugger. | |
| long | breakExecution (long pid) |
| Break the execution of the application and invoke the debugger in a remote process. | |
| std::string | homeDirectory () |
| std::string | tempDirectory () |
| StatusCode | resolveEnv (const std::string &var, std::string &res, int recusions=124) |
| long | adjustMemory (MemoryUnit typ, long value) |
| Convert time from kByte to requested representation (Experts only). | |
| long | procID () |
| Basic Process Information: Process ID. | |
| long | parentID (InfoType fetch=ProcessBasics, long pid=-1) |
| Basic Process Information: Parent's process ID. | |
| long | affinityMask (InfoType fetch=ProcessBasics, long pid=-1) |
| Basic Process Information: Affinity mask. | |
| long | exitStatus (InfoType fetch=ProcessBasics, long pid=-1) |
| Basic Process Information: Exit status (does not really make sense for the running process, but for others!). | |
| long | basePriority (InfoType fetch=ProcessBasics, long pid=-1) |
| Basic Process Information: Base priority. | |
| long | priorityBoost (InfoType fetch=PriorityBoost, long pid=-1) |
| Basic Process Information: priority boost. | |
| long | numPageFault (InfoType fetch=Memory, long pid=-1) |
| Basic Process Information: Number of page faults. | |
| long | pagefileUsage (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1) |
| Basic Process Information: Current page file usage. | |
| long | pagefileUsagePeak (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1) |
| Basic Process Information: Peak usage of page file. | |
| long | pagefileUsageLimit (MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1) |
| Basic Process Information: Peak usage of page file. | |
| long | nonPagedMemory (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1) |
| Basic Process Information: Current usage of non paged memory. | |
| long | nonPagedMemoryPeak (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1) |
| Basic Process Information: Peak usage of non paged memory. | |
| long | nonPagedMemoryLimit (MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1) |
| System Process Limits: Maximum amount of non-paged memory this process is allowed to use. | |
| long | pagedMemory (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1) |
| Basic Process Information: Amount of paged memory currently occupied by the process 'pid'. | |
| long | pagedMemoryPeak (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1) |
| Basic Process Information: Maximum of paged memory occupied by the process 'pid'. | |
| long | pagedMemoryLimit (MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1) |
| Basic Process Information: Amount of paged memory that can be occupied by the process 'pid'. | |
| long | minMemoryLimit (MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1) |
| System Process Limits: Minimum amount of virtual memory this process may use. | |
| long | maxMemoryLimit (MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1) |
| System Process Limits: Maximum amount of virtual memory this process is allowed to use. | |
| long | mappedMemory (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1) |
| Basic Process Information: priority boost. | |
| long | mappedMemoryPeak (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1) |
| Basic Process Information: priority boost. | |
| long | virtualMemory (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1) |
| Basic Process Information: priority boost. | |
| long | virtualMemoryPeak (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1) |
| Basic Process Information: priority boost. | |
| long | virtualMemoryLimit (MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1) |
| System Process Limits: Maximum amount of the page file this process is allowed to use. | |
| const std::string & | moduleName () |
| Get the name of the (executable/DLL) file without file-type. | |
| const std::string & | moduleNameFull () |
| Get the full name of the (executable/DLL) file. | |
| ModuleType | moduleType () |
| Get type of the module. | |
| ProcessHandle | processHandle () |
| Handle to running process. | |
| ImageHandle | moduleHandle () |
| Handle to currently executed module. | |
| ImageHandle | exeHandle () |
| Handle to the executable file running. | |
| const std::string & | exeName () |
| Name of the executable file running. | |
| const std::vector< std::string > | linkedModules () |
| Vector of names of linked modules. | |
| void | setModuleHandle (ImageHandle handle) |
| Attach module handle. | |
| PathResolver::SearchPathStatus | PathResolverCheckSearchPath (const std::string &search_path) |
| std::string | PathResolverFindDirectory (const std::string &logical_file_name, const std::string &search_path) |
| std::string | PathResolverFindDirectoryFromList (const std::string &logical_file_name, const std::string &search_list) |
| std::string | PathResolverFindFile (const std::string &logical_file_name, const std::string &search_path) |
| std::string | PathResolverFindFileFromList (const std::string &logical_file_name, const std::string &search_list) |
| std::string | PathResolverFindXMLFile (const std::string &logical_file_name) |
| std::string | PathResolverFindDataFile (const std::string &logical_file_name) |
| unsigned long | loadDynamicLib (const std::string &name, ImageHandle *handle) |
| Load dynamic link library. | |
| unsigned long | unloadDynamicLib (ImageHandle handle) |
| unload dynamic link library | |
| unsigned long | getProcedureByName (ImageHandle handle, const std::string &name, EntryPoint *pFunction) |
| Get a specific function defined in the DLL. | |
| unsigned long | getProcedureByName (ImageHandle handle, const std::string &name, Creator *pFunction) |
| Get a specific function defined in the DLL. | |
| unsigned long | getLastError () |
| Get last system known error. | |
| const std::string | getLastErrorString () |
| Get last system error as string. | |
| const std::string | getErrorString (unsigned long error) |
| Retrieve error code as string for a given error. | |
| const std::string | typeinfoName (const std::type_info &) |
| Get platform independent information about the class type. | |
| const std::string | typeinfoName (const char *) |
| const std::string & | hostName () |
| Host name. | |
| const std::string & | osName () |
| OS name. | |
| const std::string & | osVersion () |
| OS version. | |
| const std::string & | machineType () |
| Machine type. | |
| const std::string & | accountName () |
| User login name. | |
| long | numCmdLineArgs () |
| Number of arguments passed to the commandline. | |
| long | argc () |
| Number of arguments passed to the commandline (==numCmdLineArgs()); just to match argv call... | |
| const std::vector< std::string > | cmdLineArgs () |
| Command line arguments including executable name as arg[0] as vector of strings. | |
| char ** | argv () |
| char** command line arguments including executable name as arg[0]; You may not modify them! | |
| const std::string | getEnv (const char *var) |
| get a particular environment variable | |
| const std::vector< std::string > | getEnv () |
| get all environment variables | |
| int | setEnv (const std::string &name, const std::string &value, int overwrite=1) |
| Set an environment variables. | |
| ThreadHandle | threadSelf () |
| thread handle "accessor" | |
| int | backTrace (void **addresses, const int depth) |
| bool | backTrace (std::string &btrace, const int depth, const int offset=0) |
| bool | getStackLevel (void *addresses, void *&addr, std::string &fnc, std::string &lib) |
| longlong | adjustTime (TimeType typ, longlong timevalue) |
| Convert time from OS native time to requested representation (Experts only). | |
| longlong | ellapsedTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1) |
| Ellapsed time since start of process in milli seconds. | |
| longlong | kernelTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1) |
| CPU kernel mode time of process in milli seconds. | |
| longlong | userTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1) |
| CPU user mode time of process in milli seconds. | |
| longlong | cpuTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1) |
| Consumed CPU time of process in milli seconds. | |
| longlong | remainingTime (TimeType typ=milliSec, InfoType fetch=Quota, long pid=-1) |
| Maximum processing time left for this process. | |
| longlong | creationTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1) |
| Process Creation time. | |
| longlong | systemStart (TimeType typ=Sec) |
| Maximum processing time left for this process. | |
| longlong | upTime (TimeType typ=Hour) |
| Maximum processing time left for this process. | |
| longlong | currentTime (TimeType typ=milliSec) |
| Retrieve absolute system time. | |
| longlong | tickCount () |
| Retrieve the number of ticks since system startup. | |
| static void | PR_compress_path (std::string &dir) |
| static void | PR_dirname (const std::string &file_name, std::string &result) |
| static bool | PR_absolute_path (const std::string &name) |
| static void | PR_basename (const std::string &file_name, std::string &result) |
| static bool | PR_test_exist (const std::string &name, std::string &real_name, PR_file_type file_type) |
| static void | PR_scan_dir (const std::string &dir_name, std::vector< std::string > &list) |
| static bool | PR_find (const std::string &search_base, const std::string &logical_file_prefix, const std::string &logical_file_name, PR_file_type file_type, PathResolver::SearchType search_type, std::string &result) |
| static bool | PR_find_from_list (const std::string &logical_file_name, const std::string &search_list, PR_file_type file_type, PathResolver::SearchType search_type, std::string &result) |
| System::ProcessDescriptor * | getProcess () |
| Retrieve Process structure. | |
| int | backTrace (void **addresses __attribute__((unused)), const int depth __attribute__((unused))) |
| bool | getStackLevel (void *addresses __attribute__((unused)), void *&addr __attribute__((unused)), std::string &fnc __attribute__((unused)), std::string &lib __attribute__((unused))) |
| typedef void*(* System::Creator)() |
| typedef unsigned long(* System::EntryPoint)(const unsigned long iid, void **ppvObject) |
| typedef void * System::ImageHandle |
| typedef struct _PEB* System::PPEB |
Basic Process Information NtQueryInformationProcess using ProcessBasicInfo.
Definition at line 18 of file ProcessDescriptor.h.
| typedef void * System::ProcessHandle |
| typedef void* System::ThreadHandle |
| enum System::InfoType |
Enumeration for fetching information.
Definition at line 18 of file SystemBase.h.
00018 { NoFetch, 00019 RemainTime, 00020 Times, 00021 ProcessBasics, 00022 PriorityBoost, 00023 Memory, 00024 Quota, 00025 System, 00026 Modules, 00027 IO };
| enum System::MemoryUnit |
| enum System::ModuleType |
| enum System::PR_file_type |
Definition at line 24 of file PathResolver.cpp.
00025 { 00026 PR_regular_file, 00027 PR_directory 00028 } PR_file_type;
Definition at line 30 of file PathResolver.cpp.
00030 { 00031 PR_local, 00032 PR_recursive } PR_search_type;
Definition at line 21 of file ProcessDescriptor.cpp.
00021 { 00022 ProcessBasicInformation, 00023 ProcessQuotaLimits, 00024 ProcessIoCounters, 00025 ProcessVmCounters, 00026 ProcessTimes, 00027 ProcessBasePriority, 00028 ProcessRaisePriority, 00029 ProcessDebugPort, 00030 ProcessExceptionPort, 00031 ProcessAccessToken, 00032 ProcessLdtInformation, 00033 ProcessLdtSize, 00034 ProcessDefaultHardErrorMode, 00035 ProcessIoPortHandlers, // Note: this is kernel mode only 00036 ProcessPooledUsageAndLimits, 00037 ProcessWorkingSetWatch, 00038 ProcessUserModeIOPL, 00039 ProcessEnableAlignmentFaultFixup, 00040 ProcessPriorityClass, 00041 ProcessWx86Information, 00042 ProcessHandleCount, 00043 ProcessAffinityMask, 00044 ProcessPriorityBoost, 00045 MaxProcessInfoClass, // 00046 ProcessEllapsedTime 00047 };
| enum System::TimeType |
| const std::string & System::accountName | ( | ) |
User login name.
Definition at line 562 of file System.cpp.
00562 { 00563 static std::string account = ""; 00564 if ( account == "" ) { 00565 #ifdef _WIN32 00566 char buffer[512]; 00567 unsigned long buflen = sizeof(buffer); 00568 ::GetUserName(buffer, &buflen); 00569 account = buffer; 00570 #else 00571 const char* acct = ::getlogin(); 00572 if ( 0 == acct ) acct = ::getenv("LOGNAME"); 00573 if ( 0 == acct ) acct = ::getenv("USER"); 00574 account = (acct) ? acct : "Unknown"; 00575 #endif 00576 } 00577 return account; 00578 }
| long System::adjustMemory | ( | MemoryUnit | typ, | |
| long | value | |||
| ) |
Convert time from kByte to requested representation (Experts only).
Convert requested memory value from kByte to requested value.
Definition at line 35 of file Memory.cpp.
00035 { 00036 if ( value != -1 ) { 00037 switch ( unit ) { 00038 case Byte: value = value; break; 00039 case kByte: value = value/1024; break; 00040 case MByte: value = (value/1024)/1024; break; 00041 case GByte: value = ((value/1024)/1024)/1024; break; 00042 case TByte: value = (((value/1024)/1024)/1024)/1024; break; 00043 case PByte: value = ((((value/1024)/1024)/1024)/1024)/1024; break; 00044 case EByte: value = (((((value/1024)/1024)/1024)/1024)/1024)/1024; break; 00045 default: value = -1; break; 00046 } 00047 } 00048 return value; 00049 }
Convert time from OS native time to requested representation (Experts only).
unfortunately "-ansi" flag turn off teh correct definition of CLK_TCK and forces it to be equal CLOCKS_PER_SEC, it is wrong!
t /= CLOCKS_PER_SEC; // needs division by clock tick unit
Definition at line 38 of file Timing.cpp.
00038 { 00039 if ( t != -1 ) { 00040 #ifndef _WIN32 00042 // t /= CLK_TCK ; // needs division by clock tick unit 00046 00048 #endif 00049 switch( typ ) { 00050 case Year: t /= 365; 00051 case Day: t /= 24; 00052 case Hour: t /= 60; 00053 case Min: t /= 60; 00054 case Sec: t /= 1000; 00055 case milliSec: t /= 1000; 00056 case microSec: t /= 10; break; 00057 case nanoSec: t *= 100; break; 00058 case Month: t /= (12*24*3600); 00059 t /= 10000000; break; 00060 default: break; 00061 } 00062 } 00063 return t; 00064 }
| long System::affinityMask | ( | InfoType | fetch = ProcessBasics, |
|
| long | pid = -1 | |||
| ) |
Basic Process Information: Affinity mask.
Definition at line 74 of file Memory.cpp.
00074 { 00075 PROCESS_BASIC_INFORMATION info; 00076 if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) ) 00077 return info.AffinityMask; 00078 return 0; 00079 }
| long System::argc | ( | ) |
Number of arguments passed to the commandline (==numCmdLineArgs()); just to match argv call...
Number of arguments passed to the commandline.
Definition at line 586 of file System.cpp.
00586 { 00587 return cmdLineArgs().size(); 00588 }
| char ** System::argv | ( | ) |
char** command line arguments including executable name as arg[0]; You may not modify them!
Const char** command line arguments including executable name as arg[0].
added by I.B.
Definition at line 648 of file System.cpp.
00648 { 00650 if( s_argvChars.empty() ) { cmdLineArgs(); } 00651 00652 // We rely here on the fact that a vector's allocation table is contiguous 00653 return (char**)&s_argvChars[0]; 00654 }
| int System::backTrace | ( | void **addresses | __attribute__(unused), | |
| const int depth | __attribute__(unused) | |||
| ) |
Definition at line 693 of file System.cpp.
00695 { 00696 00697 #ifdef __linux 00698 00699 int count = backtrace( addresses, depth ); 00700 if ( count > 0 ) { 00701 return count; 00702 } else { 00703 return 0; 00704 } 00705 00706 #else // windows and osx parts not implemented 00707 return 0; 00708 #endif 00709 00710 }
| bool System::backTrace | ( | std::string & | btrace, | |
| const int | depth, | |||
| const int | offset = 0 | |||
| ) |
Definition at line 712 of file System.cpp.
00713 { 00714 // Always hide the first two levels of the stack trace (that's us) 00715 const int totalOffset = offset + 2; 00716 const int totalDepth = depth + totalOffset; 00717 00718 std::string fnc, lib; 00719 00720 void** addresses = (void**) malloc(totalDepth*sizeof(void *)); 00721 if ( addresses != 0 ){ 00722 int count = System::backTrace(addresses,totalDepth); 00723 for (int i = totalOffset; i < count; ++i) { 00724 void *addr = 0; 00725 00726 if (System::getStackLevel(addresses[i],addr,fnc,lib)) { 00727 std::ostringstream ost; 00728 ost << "#" << std::setw(3) << std::setiosflags( std::ios::left ) << i-totalOffset+1; 00729 ost << std::hex << addr << std::dec << " " << fnc << " [" << lib << "]" << std::endl; 00730 btrace += ost.str(); 00731 } 00732 } 00733 free(addresses); 00734 } 00735 else { 00736 free(addresses); 00737 return false; 00738 } 00739 00740 return true; 00741 }
| int System::backTrace | ( | void ** | addresses, | |
| const int | depth | |||
| ) |
| long System::basePriority | ( | InfoType | fetch = ProcessBasics, |
|
| long | pid = -1 | |||
| ) |
Basic Process Information: Base priority.
Definition at line 52 of file Memory.cpp.
00052 { 00053 PROCESS_BASIC_INFORMATION info; 00054 if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) ) 00055 return info.BasePriority; 00056 return 0; 00057 }
| long System::breakExecution | ( | long | pid | ) |
Break the execution of the application and invoke the debugger in a remote process.
Break the execution of the application and invoke the debugger on a possibly remote process.
Definition at line 44 of file Debugger.cpp.
00044 { 00045 #ifdef _WIN32 00046 long result = 0; 00047 if ( pid == Win::_getpid() ) { 00048 _asm int 3 00049 return 1; 00050 } 00051 else { 00052 Win::LPTHREAD_START_ROUTINE fun; 00053 Win::HANDLE th, ph; 00054 Win::HINSTANCE mh; 00055 Win::DWORD id; 00056 mh = Win::LoadLibrary( "Kernel32" ); 00057 if ( 0 != mh ) { 00058 fun = (Win::LPTHREAD_START_ROUTINE)Win::GetProcAddress(mh, "DebugBreak"); 00059 if ( 0 != fun ) { 00060 ph = Win::OpenProcess (PROCESS_ALL_ACCESS, TRUE, pid); 00061 if ( 0 != ph ) { 00062 th = Win::CreateRemoteThread(ph,NULL,0,fun,0,0,&id); 00063 if ( 0 != th ) { 00064 Win::CloseHandle(th); 00065 result = 1; 00066 } 00067 Win::CloseHandle(ph); 00068 } 00069 } 00070 Win::FreeLibrary(mh); 00071 } 00072 } 00073 if ( result != 1 ) result = Win::GetLastError(); 00074 return result; 00075 #else 00076 // I have no clu how to do this in linux 00077 return pid; 00078 #endif 00079 }
| long System::breakExecution | ( | ) |
Break the execution of the application and invoke the debugger.
Definition at line 33 of file Debugger.cpp.
00033 { 00034 #ifdef _WIN32 00035 _asm int 3 00036 return 1; 00037 #else 00038 // I have no clu how to do this in linux 00039 return 0; 00040 #endif 00041 }
| const std::vector< std::string > System::cmdLineArgs | ( | ) |
Command line arguments including executable name as arg[0] as vector of strings.
Const char** command line arguments including executable name as arg[0].
Definition at line 591 of file System.cpp.
00591 { 00592 if ( s_argvChars.size() == 0 ) { 00593 char exe[1024]; 00594 #ifdef _WIN32 00595 // For compatibility with UNIX we CANNOT use strtok! 00596 // If we would use strtok, options like -g="My world" at 00597 // the command line level would result on NT in TWO options 00598 // instead in one as in UNIX. 00599 char *next, *tmp1, *tmp2; 00600 for(LPTSTR cmd = ::GetCommandLine(); *cmd; cmd=next) { 00601 memset(exe,0,sizeof(exe)); 00602 while ( *cmd == ' ' ) cmd++; 00603 next=::strchr(cmd,' '); 00604 if ( !next ) next = cmd + strlen(cmd); 00605 if ( (tmp1=::strchr(cmd,'\"')) > 0 && tmp1 < next ) { 00606 tmp2 = ::strchr(++tmp1,'\"'); 00607 if ( tmp2 > 0 ) { 00608 next = ++tmp2; 00609 if ( cmd < tmp1 ) strncpy(exe, cmd, tmp1-cmd-1); 00610 strncpy(&exe[strlen(exe)], tmp1, tmp2-tmp1-1); 00611 } 00612 else { 00613 std::cout << "Mismatched \" in command line arguments" << std::endl; 00614 s_argvChars.erase(s_argvChars.begin(), s_argvChars.end()); 00615 s_argvStrings.erase(s_argvStrings.begin(), s_argvStrings.end()); 00616 return s_argvStrings; 00617 } 00618 } 00619 else { 00620 strncpy(exe, cmd, next-cmd); 00621 } 00622 s_argvStrings.push_back(exe); 00623 s_argvChars.push_back( s_argvStrings.back().c_str()); 00624 } 00625 #elif defined(linux) || defined(__APPLE__) 00626 sprintf(exe, "/proc/%d/cmdline", ::getpid()); 00627 FILE *cmdLine = ::fopen(exe,"r"); 00628 char cmd[1024]; 00629 if ( cmdLine ) { 00630 long len = fread(cmd, sizeof(char), sizeof(cmd), cmdLine); 00631 if ( len > 0 ) { 00632 cmd[len] = 0; 00633 for ( char* token = cmd; token-cmd < len; token += strlen(token)+1 ) { 00634 s_argvStrings.push_back(token); 00635 s_argvChars.push_back( s_argvStrings.back().c_str()); 00636 } 00637 s_argvStrings[0] = exeName(); 00638 s_argvChars[0] = s_argvStrings[0].c_str(); 00639 } 00640 } 00641 ::fclose(cmdLine); 00642 #endif 00643 } 00644 return s_argvStrings; 00645 }
| longlong System::cpuTime | ( | TimeType | typ = milliSec, |
|
| InfoType | fetch = Times, |
|||
| long | pid = -1 | |||
| ) |
Consumed CPU time of process in milli seconds.
CPU kernel time of process in milli seconds.
| typ | Indicator or the unit the time will be returned. | |
| fetch | Indicator of the information to be fetched. If Fetch_None, the information will not be updated. | |
| pid | Process ID of which the information will be returned |
Definition at line 170 of file Timing.cpp.
00170 { 00171 longlong cputime = 0; 00172 KERNEL_USER_TIMES info; 00173 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) { 00174 cputime = adjustTime(typ, info.KernelTime+info.UserTime ); 00175 } 00176 return cputime; 00177 }
| longlong System::creationTime | ( | TimeType | typ = milliSec, |
|
| InfoType | fetch = Times, |
|||
| long | pid = -1 | |||
| ) |
Process Creation time.
Units of time between process creation and begin of epoche.
| typ | Indicator or the unit the time will be returned. | |
| fetch | Indicator of the information to be fetched. If Fetch_None, the information will not be updated. | |
| pid | Process ID of which the information will be returned |
Definition at line 116 of file Timing.cpp.
00116 { 00117 longlong created = 0; 00118 KERNEL_USER_TIMES info; 00119 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) { 00120 created = adjustTime(typ, info.CreateTime-UNIX_BASE_TIME); 00121 } 00122 return created; 00123 }
| longlong System::currentTime | ( | TimeType | typ = milliSec |
) |
Retrieve absolute system time.
Retrieve current system time.
| typ | Indicator or the unit the time will be returned. |
Definition at line 81 of file Timing.cpp.
00081 { 00082 longlong current = 0; 00083 #ifdef _WIN32 00084 ::GetSystemTimeAsFileTime((FILETIME*)¤t); 00085 current -= UNIX_BASE_TIME; 00086 #else 00087 struct timeval tv; 00088 struct timezone tz; 00089 ::gettimeofday(&tv, &tz); 00090 current = tv.tv_sec; 00091 current *= 1000000; 00092 current += tv.tv_usec; 00093 current *= 10; 00094 #endif 00095 return adjustTime(typ, current); 00096 }
| longlong System::ellapsedTime | ( | TimeType | typ = milliSec, |
|
| InfoType | fetch = Times, |
|||
| long | pid = -1 | |||
| ) |
Ellapsed time since start of process in milli seconds.
| typ | Indicator or the unit the time will be returned. | |
| timevalue | Time value to be converted. |
Definition at line 141 of file Timing.cpp.
00141 { 00142 KERNEL_USER_TIMES info; 00143 longlong ellapsed = currentTime(microSec)*10; 00144 getProcess()->query(pid, fetch, &info); 00145 ellapsed = adjustTime(typ, ellapsed+UNIX_BASE_TIME-info.CreateTime); 00146 return ellapsed; 00147 }
| System::ImageHandle System::exeHandle | ( | ) |
Handle to the executable file running.
Definition at line 164 of file ModuleInfo.cpp.
00164 { 00165 #ifdef _WIN32 00166 if ( processHandle() ) { 00167 static HINSTANCE handle = 0; 00168 DWORD cbNeeded; 00169 if ( 0 == handle && _psApi.isValid() ) { 00170 if ( _psApi.EnumProcessModules( processHandle(), &handle, sizeof(ModuleHandle), &cbNeeded) ) { 00171 } 00172 } 00173 return handle; 00174 } 00175 #elif defined(linux) || defined(__APPLE__) 00176 // This does NOT work! 00177 static Dl_info infoBuf, *info = &infoBuf; 00178 if ( 0 == info ) { 00179 void* handle = ::dlopen(0, RTLD_LAZY); 00180 //printf("Exe handle:%X\n", handle); 00181 if ( 0 != handle ) { 00182 void* func = ::dlsym(handle, "main"); 00183 //printf("Exe:Func handle:%X\n", func); 00184 if ( 0 != func ) { 00185 if ( 0 != ::dladdr(func, &infoBuf) ) { 00186 //std::cout << "All OK" << std::endl; 00187 info = &infoBuf; 00188 } 00189 } 00190 } 00191 } 00192 return info; 00193 #elif __hpux 00194 // Don't know how to solve this ..... 00195 #endif 00196 return 0; 00197 }
| const std::string & System::exeName | ( | ) |
Name of the executable file running.
Definition at line 199 of file ModuleInfo.cpp.
00199 { 00200 static std::string module(""); 00201 if ( module.length() == 0 ) { 00202 char name[512] = {"Unknown.module"}; 00203 name[0] = 0; 00204 #ifdef _WIN32 00205 if ( _psApi.isValid() && processHandle() ) { 00206 _psApi.GetModuleFileNameExA( processHandle(), (HINSTANCE)exeHandle(), name,sizeof(name) ); 00207 } 00208 #elif defined(linux) || defined(__APPLE__) 00209 char cmd[512]; 00210 ::sprintf(cmd, "/proc/%d/exe", ::getpid()); 00211 module = "Unknown"; 00212 ::readlink(cmd, name, sizeof(name)); 00213 #elif __hpux 00214 ::realpath(((HMODULE*)exeHandle())->dsc.filename, name); 00215 #endif 00216 module = name; 00217 } 00218 return module; 00219 }
| long System::exitStatus | ( | InfoType | fetch = ProcessBasics, |
|
| long | pid = -1 | |||
| ) |
Basic Process Information: Exit status (does not really make sense for the running process, but for others!).
Definition at line 82 of file Memory.cpp.
00082 { 00083 PROCESS_BASIC_INFORMATION info; 00084 if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) ) 00085 return info.ExitStatus; 00086 return -2; 00087 }
| const std::vector< std::string > System::getEnv | ( | ) |
get all environment variables
get all defined environment vars
Definition at line 671 of file System.cpp.
00671 { 00672 #if defined(_WIN32) 00673 # define environ _environ 00674 #elif defined(linux) 00675 extern char **environ; 00676 #elif defined(__APPLE__) 00677 static char **environ = *_NSGetEnviron(); 00678 #endif 00679 std::vector<std::string> vars; 00680 for (int i=0; environ[i] != 0; ++i) { 00681 vars.push_back(environ[i]); 00682 } 00683 return vars; 00684 }
| const std::string System::getEnv | ( | const char * | var | ) |
get a particular environment variable
get a particular env var, return "UNKNOWN" if not defined
Definition at line 657 of file System.cpp.
00657 { 00658 char* env; 00659 if ( (env = getenv(var)) != 0 ) { 00660 return env; 00661 } else { 00662 return "UNKNOWN"; 00663 } 00664 }
| const std::string System::getErrorString | ( | unsigned long | error | ) |
Retrieve error code as string for a given error.
Definition at line 251 of file System.cpp.
00251 { 00252 std::string errString = ""; 00253 #ifdef _WIN32 00254 LPVOID lpMessageBuffer; 00255 ::FormatMessage( 00256 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 00257 NULL, 00258 error, 00259 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), //The user default language 00260 (LPTSTR) &lpMessageBuffer, 00261 0, 00262 NULL ); 00263 errString = (const char*)lpMessageBuffer; 00264 // Free the buffer allocated by the system 00265 ::LocalFree( lpMessageBuffer ); 00266 #else 00267 char *cerrString(0); 00268 // Remember: for linux dl* routines must be handled differently! 00269 if ( error == 0xAFFEDEAD ) { 00270 cerrString = (char*)::dlerror(); 00271 if ( 0 == cerrString ) { 00272 cerrString = ::strerror(error); 00273 } 00274 if ( 0 == cerrString ) { 00275 cerrString = (char *)"Unknown error. No information found in strerror()!"; 00276 } 00277 else { 00278 errString = std::string(cerrString); 00279 } 00280 errno = 0; 00281 } 00282 else { 00283 cerrString = ::strerror(error); 00284 errString = std::string(cerrString); 00285 } 00286 #endif 00287 return errString; 00288 }
| unsigned long System::getLastError | ( | ) |
Get last system known error.
Retrieve last error code.
Definition at line 235 of file System.cpp.
00235 { 00236 #ifdef _WIN32 00237 return ::GetLastError(); 00238 #else 00239 // convert errno (int) to unsigned long 00240 return static_cast<unsigned long>(static_cast<unsigned int>(errno)); 00241 #endif 00242 }
| const std::string System::getLastErrorString | ( | ) |
Get last system error as string.
Retrieve last error code as string.
Definition at line 245 of file System.cpp.
00245 { 00246 const std::string errString = getErrorString(getLastError()); 00247 return errString; 00248 }
| unsigned long System::getProcedureByName | ( | ImageHandle | handle, | |
| const std::string & | name, | |||
| Creator * | pFunction | |||
| ) |
Get a specific function defined in the DLL.
Definition at line 230 of file System.cpp.
00230 { 00231 return getProcedureByName(handle, name, (EntryPoint*)pFunction); 00232 }
| unsigned long System::getProcedureByName | ( | ImageHandle | handle, | |
| const std::string & | name, | |||
| EntryPoint * | pFunction | |||
| ) |
Get a specific function defined in the DLL.
Definition at line 180 of file System.cpp.
00180 { 00181 #ifdef _WIN32 00182 *pFunction = (EntryPoint)::GetProcAddress((HINSTANCE)handle, name.data()); 00183 if ( 0 == *pFunction ) { 00184 return System::getLastError(); 00185 } 00186 return 1; 00187 #elif defined(linux) 00188 #if __GNUC__ < 4 00189 *pFunction = (EntryPoint)::dlsym(handle, name.c_str()); 00190 #else 00191 *pFunction = FuncPtrCast<EntryPoint>(::dlsym(handle, name.c_str())); 00192 #endif 00193 if ( 0 == *pFunction ) { 00194 errno = 0xAFFEDEAD; 00195 // std::cout << "System::getProcedureByName>" << getLastErrorString() << std::endl; 00196 return 0; 00197 } 00198 return 1; 00199 #elif defined(__APPLE__) 00200 *pFunction = (EntryPoint)::dlsym(handle, name.c_str()); 00201 if(!(*pFunction)) { 00202 // Try with an underscore : 00203 std::string sname = "_" + name; 00204 *pFunction = (EntryPoint)::dlsym(handle, sname.c_str()); 00205 } 00206 if ( 0 == *pFunction ) { 00207 errno = 0xAFFEDEAD; 00208 std::cout << "System::getProcedureByName>" << getLastErrorString() << std::endl; 00209 //std::cout << "System::getProcedureByName> failure" << std::endl; 00210 return 0; 00211 } 00212 return 1; 00213 #elif __hpux 00214 HMODULE* mod = (HMODULE*)handle; 00215 if ( 0 != mod ) { 00216 long ll1 = name.length(); 00217 for ( int i = 0; i < mod->numSym; i++ ) { 00218 long ll2 = strlen(mod->sym[i].name); 00219 if ( 0 != ::strncmp(mod->sym[i].name, name.c_str(), (ll1>ll2) ? ll1 : ll2)==0 ) { 00220 *pFunction = (EntryPoint) mod->sym[i].value; 00221 return 1; 00222 } 00223 } 00224 } 00225 return 0; 00226 #endif 00227 }
| ProcessDescriptor * System::getProcess | ( | ) |
Retrieve Process structure.
Definition at line 213 of file ProcessDescriptor.cpp.
00213 { 00214 static ProcessDescriptor p; 00215 #ifdef _WIN32 00216 static bool first = true; 00217 if ( first ) { 00218 first = false; 00219 void* mh = ::LoadLibrary("NTDll.dll"); 00220 if ( mh ) { 00221 NtApi::NtQueryInformationProcess = (NtApi::__NtQueryInformationProcess) 00222 ::GetProcAddress((HINSTANCE)mh, "NtQueryInformationProcess"); 00223 } 00224 } 00225 #endif 00226 return &p; 00227 }
| bool System::getStackLevel | ( | void *addresses | __attribute__(unused), | |
| void *&addr | __attribute__(unused), | |||
| std::string &fnc | __attribute__(unused), | |||
| std::string &lib | __attribute__(unused) | |||
| ) |
Definition at line 743 of file System.cpp.
00747 { 00748 00749 #ifdef __linux 00750 00751 Dl_info info; 00752 00753 if ( dladdr( addresses, &info ) && info.dli_fname 00754 && info.dli_fname[0] != '\0' ) { 00755 const char* symbol = info.dli_sname 00756 && info.dli_sname[0] != '\0' ? info.dli_sname : 0; 00757 00758 lib = info.dli_fname; 00759 addr = info.dli_saddr; 00760 const char* dmg(0); 00761 00762 if (symbol != 0) { 00763 int stat; 00764 dmg = abi::__cxa_demangle(symbol,0,0,&stat); 00765 fnc = (stat == 0) ? dmg : symbol; 00766 } else { 00767 fnc = "local"; 00768 } 00769 free((void*)dmg); 00770 return true ; 00771 } else { 00772 return false ; 00773 } 00774 00775 #else // not implemented for windows and osx 00776 return false ; 00777 #endif 00778 00779 }
| bool System::getStackLevel | ( | void * | addresses, | |
| void *& | addr, | |||
| std::string & | fnc, | |||
| std::string & | lib | |||
| ) |
| std::string System::homeDirectory | ( | ) |
Definition at line 58 of file Environment.cpp.
00058 { 00059 // Return the user's home directory. 00060 std::string home_dir = "./"; 00061 const char *h = 0; 00062 if ( 0 == (h = ::getenv("home"))) { 00063 h = ::getenv("HOME"); 00064 } 00065 if ( h ) { 00066 home_dir = h; 00067 } 00068 else { 00069 // for Windows NT HOME might be defined as either $(HOMESHARE)/$(HOMEPATH) 00070 // or $(HOMEDRIVE)/$(HOMEPATH) 00071 h = ::getenv("HOMESHARE"); 00072 if ( 0 == h ) { 00073 h = ::getenv("HOMEDRIVE"); 00074 } 00075 if (h) { 00076 home_dir = h; 00077 h = ::getenv("HOMEPATH"); 00078 if( h ) { 00079 home_dir += h; 00080 } 00081 } 00082 } 00083 return home_dir; 00084 }
| const std::string & System::hostName | ( | ) |
Host name.
Definition at line 487 of file System.cpp.
00487 { 00488 static std::string host = ""; 00489 if ( host == "" ) { 00490 char buffer[512]; 00491 memset(buffer,0,sizeof(buffer)); 00492 #ifdef _WIN32 00493 unsigned long len = sizeof(buffer); 00494 ::GetComputerName(buffer, &len); 00495 #else 00496 ::gethostname(buffer, sizeof(buffer)); 00497 #endif 00498 host = buffer; 00499 } 00500 return host; 00501 }
| longlong System::kernelTime | ( | TimeType | typ = milliSec, |
|
| InfoType | fetch = Times, |
|||
| long | pid = -1 | |||
| ) |
CPU kernel mode time of process in milli seconds.
CPU kernel time of process in milli seconds.
| typ | Indicator or the unit the time will be returned. | |
| fetch | Indicator of the information to be fetched. If Fetch_None, the information will not be updated. | |
| pid | Process ID of which the information will be returned |
Definition at line 150 of file Timing.cpp.
00150 { 00151 KERNEL_USER_TIMES info; 00152 longlong kerneltime = 0; 00153 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) { 00154 kerneltime = adjustTime(typ, info.KernelTime ); 00155 } 00156 return kerneltime; 00157 }
| const std::vector< std::string > System::linkedModules | ( | ) |
Vector of names of linked modules.
Definition at line 221 of file ModuleInfo.cpp.
00221 { 00222 if ( s_linkedModules.size() == 0 ) { 00223 #ifdef _WIN32 00224 char name[255]; // Maximum file name length on NT 4.0 00225 DWORD cbNeeded; 00226 HINSTANCE handle[1024]; 00227 if ( _psApi.isValid() ) { 00228 if ( _psApi.EnumProcessModules(processHandle(),handle,sizeof(handle),&cbNeeded) ) { 00229 for (size_t i = 0; i < cbNeeded/sizeof(HANDLE); i++ ) { 00230 if ( 0 < _psApi.GetModuleFileNameExA( processHandle(), handle[i], name, sizeof(name)) ) { 00231 s_linkedModules.push_back(name); 00232 } 00233 } 00234 } 00235 } 00236 #elif defined(linux) || defined(__APPLE__) 00237 char ff[512], cmd[1024], fname[1024], buf1[64], buf2[64], buf3[64], buf4[64]; 00238 ::sprintf(ff, "/proc/%d/maps", ::getpid()); 00239 FILE* maps = ::fopen(ff, "r"); 00240 while( ::fgets(cmd, sizeof(cmd), maps) ) { 00241 int len; 00242 sscanf(cmd, "%s %s %s %s %d %s", buf1, buf2, buf3, buf4, &len, fname); 00243 if ( len > 0 && strncmp(buf2,"r-xp",strlen("r-xp")) == 0 ) { 00244 s_linkedModules.push_back(fname); 00245 } 00246 } 00247 ::fclose(maps); 00248 #endif 00249 } 00250 return s_linkedModules; 00251 }
| unsigned long System::loadDynamicLib | ( | const std::string & | name, | |
| ImageHandle * | handle | |||
| ) |
Load dynamic link library.
Definition at line 123 of file System.cpp.
00123 { 00124 unsigned long res; 00125 // if name is empty, just load it 00126 if (name.length() == 0) { 00127 res = loadWithoutEnvironment(name, handle); 00128 } else { 00129 // If the name is a logical name (environment variable), the try 00130 // to load the corresponding library from there. 00131 std::string env = name; 00132 if ( 0 != ::getenv(env.c_str()) ) { 00133 std::string imgName = ::getenv(env.c_str()); 00134 res = loadWithoutEnvironment(imgName, handle); 00135 } else { 00136 // build the dll name 00137 std::string dllName = name; 00138 #if defined(linux) || defined(__APPLE__) 00139 dllName = "lib" + dllName; 00140 #endif 00141 dllName += SHLIB_SUFFIX; 00142 // try to locate the dll using the standard PATH 00143 res = loadWithoutEnvironment(dllName, handle); 00144 } 00145 if ( res != 1 ) { 00146 #if defined(linux) || defined(__APPLE__) 00147 errno = 0xAFFEDEAD; 00148 #endif 00149 // std::cout << "System::loadDynamicLib>" << getLastErrorString() << std::endl; 00150 } 00151 } 00152 return res; 00153 }
| const std::string & System::machineType | ( | ) |
Machine type.
Definition at line 542 of file System.cpp.
00542 { 00543 static std::string mach = ""; 00544 #ifdef _WIN32 00545 SYSTEM_INFO ut; 00546 ::GetSystemInfo(&ut); 00547 char arch[64]; 00548 sprintf(arch,"%d",ut.wProcessorArchitecture); 00549 mach = arch; 00550 #else 00551 struct utsname ut; 00552 if (uname(&ut) == 0) { 00553 mach = ut.machine; 00554 } else { 00555 mach = "UNKNOWN"; 00556 } 00557 #endif 00558 return mach; 00559 }
| long System::mappedMemory | ( | MemoryUnit | unit = kByte, |
|
| InfoType | fetch = Memory, |
|||
| long | pid = -1 | |||
| ) |
Basic Process Information: priority boost.
Definition at line 181 of file Memory.cpp.
00181 { 00182 VM_COUNTERS info; 00183 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00184 return adjustMemory(unit, info.WorkingSetSize); 00185 return -2; 00186 }
| long System::mappedMemoryPeak | ( | MemoryUnit | unit = kByte, |
|
| InfoType | fetch = Memory, |
|||
| long | pid = -1 | |||
| ) |
Basic Process Information: priority boost.
Definition at line 189 of file Memory.cpp.
00189 { 00190 VM_COUNTERS info; 00191 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00192 return adjustMemory(unit, info.PeakWorkingSetSize); 00193 return -2; 00194 }
| long System::maxMemoryLimit | ( | MemoryUnit | unit = kByte, |
|
| InfoType | fetch = Quota, |
|||
| long | pid = -1 | |||
| ) |
System Process Limits: Maximum amount of virtual memory this process is allowed to use.
Definition at line 205 of file Memory.cpp.
00205 { 00206 QUOTA_LIMITS quota; 00207 if ( fetch != NoFetch && getProcess()->query(pid, fetch, "a) ) 00208 return adjustMemory(unit, quota.MaximumWorkingSetSize); 00209 return 0; 00210 }
| long System::minMemoryLimit | ( | MemoryUnit | unit = kByte, |
|
| InfoType | fetch = Quota, |
|||
| long | pid = -1 | |||
| ) |
System Process Limits: Minimum amount of virtual memory this process may use.
Definition at line 197 of file Memory.cpp.
00197 { 00198 QUOTA_LIMITS quota; 00199 if ( fetch != NoFetch && getProcess()->query(pid, fetch, "a) ) 00200 return adjustMemory(unit, quota.MinimumWorkingSetSize); 00201 return 0; 00202 }
| System::ImageHandle System::moduleHandle | ( | ) |
Handle to currently executed module.
Definition at line 133 of file ModuleInfo.cpp.
00133 { 00134 if ( 0 == ModuleHandle ) { 00135 if ( processHandle() ) { 00136 #ifdef _WIN32 00137 static HINSTANCE handle = 0; 00138 DWORD cbNeeded; 00139 if ( 0 == handle && _psApi.isValid() ) { 00140 if ( _psApi.EnumProcessModules( processHandle(), &handle, sizeof(ModuleHandle), &cbNeeded) ) { 00141 } 00142 } 00143 return handle; 00144 #elif defined(linux) || defined(__APPLE__) 00145 static Dl_info info; 00146 if ( 0 != 00147 ::dladdr( 00148 #if __GNUC__ < 4 00149 (void*)System::moduleHandle 00150 #else 00151 FuncPtrCast<void*>(System::moduleHandle) 00152 #endif 00153 , &info) ) { 00154 return &info; 00155 } 00156 #elif __hpux 00157 return 0; // Don't know how to solve this ..... 00158 #endif 00159 } 00160 } 00161 return ModuleHandle; 00162 }
| const std::string & System::moduleName | ( | ) |
Get the name of the (executable/DLL) file without file-type.
Retrieve base name of module.
Definition at line 52 of file ModuleInfo.cpp.
00052 { 00053 static std::string module(""); 00054 if ( module == "" ) { 00055 if ( processHandle() && moduleHandle() ) { 00056 #ifdef _WIN32 00057 char moduleName[256] = {"Unknown.module"}; 00058 moduleName[0] = 0; 00059 if ( _psApi.isValid() ) { 00060 _psApi.GetModuleBaseNameA( processHandle(), (HINSTANCE)moduleHandle(), moduleName, sizeof(moduleName) ); 00061 } 00062 std::string mod = moduleName; 00063 #elif defined(linux) || defined(__APPLE__) 00064 std::string mod = ::basename((char*)((Dl_info*)moduleHandle())->dli_fname); 00065 #elif __hpux 00066 std::string mod = ::basename(((HMODULE*)moduleHandle())->dsc.filename); 00067 #endif 00068 module = mod.substr(0, mod.rfind('.')); 00069 } 00070 } 00071 return module; 00072 }
| const std::string & System::moduleNameFull | ( | ) |
Get the full name of the (executable/DLL) file.
Retrieve full name of module.
Definition at line 75 of file ModuleInfo.cpp.
00075 { 00076 static std::string module(""); 00077 if ( module == "" ) { 00078 if ( processHandle() && moduleHandle() ) { 00079 char name[512] = {"Unknown.module"}; 00080 name[0] = 0; 00081 #ifdef _WIN32 00082 if ( _psApi.isValid() ) { 00083 _psApi.GetModuleFileNameExA( processHandle(), (HINSTANCE)moduleHandle(), name,sizeof(name) ); 00084 } 00085 #elif defined(linux) || defined(__APPLE__) 00086 ::realpath(((Dl_info*)moduleHandle())->dli_fname, name); 00087 #elif __hpux 00088 ::realpath(((HMODULE*)moduleHandle())->dsc.filename, name); 00089 #endif 00090 module = name; 00091 } 00092 } 00093 return module; 00094 }
| System::ModuleType System::moduleType | ( | ) |
Get type of the module.
Definition at line 97 of file ModuleInfo.cpp.
00097 { 00098 static ModuleType type = UNKNOWN; 00099 if ( type == UNKNOWN ) { 00100 const std::string& module = moduleNameFull(); 00101 int loc = module.rfind('.')+1; 00102 if ( loc == 0 ) 00103 type = EXECUTABLE; 00104 else if ( module[loc] == 'e' || module[loc] == 'E' ) 00105 type = EXECUTABLE; 00106 #ifdef _WIN32 00107 else if ( module[loc] == 'd' || module[loc] == 'D' ) 00108 #else 00109 else if ( module[loc] == 's' && module[loc+1] == 'o' ) 00110 #endif 00111 type = SHAREDLIB; 00112 else 00113 type = UNKNOWN; 00114 } 00115 return type; 00116 }
| long System::nonPagedMemory | ( | MemoryUnit | unit = kByte, |
|
| InfoType | fetch = Memory, |
|||
| long | pid = -1 | |||
| ) |
Basic Process Information: Current usage of non paged memory.
Basic Process Information: priority boost.
Definition at line 106 of file Memory.cpp.
00106 { 00107 VM_COUNTERS info; 00108 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00109 return adjustMemory(unit, info.QuotaNonPagedPoolUsage); 00110 return -2; 00111 }
| long System::nonPagedMemoryLimit | ( | MemoryUnit | unit = kByte, |
|
| InfoType | fetch = Quota, |
|||
| long | pid = -1 | |||
| ) |
System Process Limits: Maximum amount of non-paged memory this process is allowed to use.
Definition at line 114 of file Memory.cpp.
00114 { 00115 POOLED_USAGE_AND_LIMITS quota; 00116 if ( fetch != NoFetch && getProcess()->query(pid, fetch, "a) ) 00117 return adjustMemory(unit, quota.NonPagedPoolLimit); 00118 return 0; 00119 }
| long System::nonPagedMemoryPeak | ( | MemoryUnit | unit = kByte, |
|
| InfoType | fetch = Memory, |
|||
| long | pid = -1 | |||
| ) |
Basic Process Information: Peak usage of non paged memory.
Basic Process Information: priority boost.
Definition at line 98 of file Memory.cpp.
00098 { 00099 VM_COUNTERS info; 00100 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00101 return adjustMemory(unit, info.QuotaPeakNonPagedPoolUsage); 00102 return -2; 00103 }
| long System::numCmdLineArgs | ( | ) |
Number of arguments passed to the commandline.
Definition at line 581 of file System.cpp.
00581 { 00582 return cmdLineArgs().size(); 00583 }
| long System::numPageFault | ( | InfoType | fetch = Memory, |
|
| long | pid = -1 | |||
| ) |
Basic Process Information: Number of page faults.
Basic Process Information: priority boost.
Definition at line 146 of file Memory.cpp.
00146 { 00147 VM_COUNTERS info; 00148 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00149 return info.PageFaultCount; 00150 return -2; 00151 }
| const std::string & System::osName | ( | ) |
OS name.
Definition at line 504 of file System.cpp.
00504 { 00505 static std::string osname = ""; 00506 #ifdef _WIN32 00507 osname = "Windows"; 00508 #else 00509 struct utsname ut; 00510 if (uname(&ut) == 0) { 00511 osname = ut.sysname; 00512 } else { 00513 osname = "UNKNOWN"; 00514 } 00515 #endif 00516 return osname; 00517 }
| const std::string & System::osVersion | ( | ) |
OS version.
Definition at line 521 of file System.cpp.
00521 { 00522 static std::string osver = ""; 00523 #ifdef _WIN32 00524 OSVERSIONINFO ut; 00525 ut.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 00526 ::GetVersionEx(&ut); 00527 char ver[64]; 00528 sprintf(ver,"%d.%d",ut.dwMajorVersion,ut.dwMinorVersion); 00529 osver = ver; 00530 #else 00531 struct utsname ut; 00532 if (uname(&ut) == 0) { 00533 osver = ut.release; 00534 } else { 00535 osver = "UNKNOWN"; 00536 } 00537 #endif 00538 return osver; 00539 }
| long System::pagedMemory | ( | MemoryUnit | unit = kByte, |
|
| InfoType | fetch = Memory, |
|||
| long | pid = -1 | |||
| ) |
Basic Process Information: Amount of paged memory currently occupied by the process 'pid'.
Definition at line 122 of file Memory.cpp.
00122 { 00123 VM_COUNTERS info; 00124 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00125 return adjustMemory(unit, info.QuotaPagedPoolUsage); 00126 return -2; 00127 }
| long System::pagedMemoryLimit | ( | MemoryUnit | unit = kByte, |
|
| InfoType | fetch = Quota, |
|||
| long | pid = -1 | |||
| ) |
Basic Process Information: Amount of paged memory that can be occupied by the process 'pid'.
Definition at line 138 of file Memory.cpp.
00138 { 00139 POOLED_USAGE_AND_LIMITS quota; 00140 if ( fetch != NoFetch && getProcess()->query(pid, fetch, "a) ) 00141 return adjustMemory(unit, quota.PagedPoolLimit); 00142 return 0; 00143 }
| long System::pagedMemoryPeak | ( | MemoryUnit | unit = kByte, |
|
| InfoType | fetch = Memory, |
|||
| long | pid = -1 | |||
| ) |
Basic Process Information: Maximum of paged memory occupied by the process 'pid'.
Definition at line 130 of file Memory.cpp.
00130 { 00131 VM_COUNTERS info; 00132 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00133 return adjustMemory(unit, info.QuotaPeakPagedPoolUsage); 00134 return -2; 00135 }
| long System::pagefileUsage | ( | MemoryUnit | unit = kByte, |
|
| InfoType | fetch = Memory, |
|||
| long | pid = -1 | |||
| ) |
Basic Process Information: Current page file usage.
Basic Process Information: priority boost.
Definition at line 154 of file Memory.cpp.
00154 { 00155 VM_COUNTERS info; 00156 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00157 return adjustMemory(unit, info.PagefileUsage); 00158 return -2; 00159 }
| long System::pagefileUsageLimit | ( | MemoryUnit | unit = kByte, |
|
| InfoType | fetch = Quota, |
|||
| long | pid = -1 | |||
| ) |
Basic Process Information: Peak usage of page file.
Basic Process Information: priority boost.
Definition at line 170 of file Memory.cpp.
00170 { 00171 POOLED_USAGE_AND_LIMITS quota; 00172 if ( fetch != NoFetch && getProcess()->query(pid, fetch, "a) ) { 00173 if ( long(quota.PagefileLimit) < 0 ) 00174 return -1;//LONG_MAX; 00175 return adjustMemory(unit, quota.PagefileLimit); 00176 } 00177 return -2; 00178 }
| long System::pagefileUsagePeak | ( | MemoryUnit | unit = kByte, |
|
| InfoType | fetch = Memory, |
|||
| long | pid = -1 | |||
| ) |
Basic Process Information: Peak usage of page file.
Basic Process Information: priority boost.
Definition at line 162 of file Memory.cpp.
00162 { 00163 VM_COUNTERS info; 00164 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00165 return adjustMemory(unit, info.PeakPagefileUsage); 00166 return -2; 00167 }
| long System::parentID | ( | InfoType | fetch = ProcessBasics, |
|
| long | pid = -1 | |||
| ) |
Basic Process Information: Parent's process ID.
Definition at line 66 of file Memory.cpp.
00066 { 00067 PROCESS_BASIC_INFORMATION info; 00068 if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) ) 00069 return info.InheritedFromUniqueProcessId; 00070 return 0; 00071 }
| PathResolver::SearchPathStatus System::PathResolverCheckSearchPath | ( | const std::string & | search_path | ) |
| std::string System::PathResolverFindDataFile | ( | const std::string & | logical_file_name | ) |
| std::string System::PathResolverFindDirectory | ( | const std::string & | logical_file_name, | |
| const std::string & | search_path | |||
| ) |
| std::string System::PathResolverFindDirectoryFromList | ( | const std::string & | logical_file_name, | |
| const std::string & | search_list | |||
| ) |
Definition at line 610 of file PathResolver.cpp.
00612 { 00613 return PathResolver::find_directory_from_list (logical_file_name, search_list); 00614 }
| std::string System::PathResolverFindFile | ( | const std::string & | logical_file_name, | |
| const std::string & | search_path | |||
| ) |
| std::string System::PathResolverFindFileFromList | ( | const std::string & | logical_file_name, | |
| const std::string & | search_list | |||
| ) |
| std::string System::PathResolverFindXMLFile | ( | const std::string & | logical_file_name | ) |
| static bool System::PR_absolute_path | ( | const std::string & | name | ) | [static] |
Definition at line 116 of file PathResolver.cpp.
00117 { 00118 if (name.size () == 0) return (false); 00119 00120 if ((name[0] == '/') || 00121 (name[0] == '\\')) return (true); 00122 00123 if (name.size () >= 2) 00124 { 00125 if (name[1] == ':') 00126 { 00127 return (true); 00128 } 00129 } 00130 return (false); 00131 }
| static void System::PR_basename | ( | const std::string & | file_name, | |
| std::string & | result | |||
| ) | [static] |
Definition at line 133 of file PathResolver.cpp.
00134 { 00135 std::string::size_type pos = file_name.find_last_of ('/'); 00136 00137 if (pos == std::string::npos) 00138 { 00139 pos = file_name.find_last_of ('\\'); 00140 } 00141 00142 if (pos == std::string::npos) 00143 { 00144 result = file_name; 00145 } 00146 else 00147 { 00148 result = file_name.substr (pos + 1); 00149 } 00150 }
| static void System::PR_compress_path | ( | std::string & | dir | ) | [static] |
Definition at line 34 of file PathResolver.cpp.
00035 { 00036 #ifdef _WIN32 00037 static const char pattern[] = "\\..\\"; 00038 #else 00039 static const char pattern[] = "/../"; 00040 #endif 00041 00042 #ifdef _WIN32 00043 static const char file_separator = '\\'; 00044 static const char double_file_separator[] = "\\\\"; 00045 #else 00046 static const char file_separator = '/'; 00047 static const char double_file_separator[] = "//"; 00048 #endif 00049 00050 if (dir.size () == 0) return; 00051 00052 // 00053 // We first synchronize to using file_separator() in any case. 00054 // 00055 00056 for (;;) 00057 { 00058 std::string::size_type pos; 00059 pos = dir.find (double_file_separator); 00060 if (pos == std::string::npos) break; 00061 dir.erase (pos, 1); 00062 } 00063 00064 for (;;) 00065 { 00066 std::string::size_type pos1; 00067 std::string::size_type pos2; 00068 00069 pos1 = dir.find (pattern); 00070 if (pos1 == std::string::npos) break; 00071 00072 // 00073 // extract "aaaa/xxxx" from "aaaa/xxxx/../bbbb" 00074 // 00075 std::string p = dir.substr (0, pos1); 00076 00077 // 00078 // Is "aaaa/xxxx" only made of "xxxx" ? 00079 // 00080 pos2 = p.find_last_of (file_separator); 00081 00082 if (pos2 == std::string::npos) break; 00083 00084 // 01234567890123456 00085 // aaaa/xxxx/../bbbb 00086 // 2 1 3 00087 // 00088 // erase the "/xxxx/../" pattern 00089 // result will be "aaaa/bbbb" 00090 // 00091 dir.erase (pos2, pos1 + 4 - pos2 - 1); 00092 } 00093 00094 //if (dir[dir.size () - 1] == file_separator ()) dir.erase (dir.size () - 1); 00095 }
| static void System::PR_dirname | ( | const std::string & | file_name, | |
| std::string & | result | |||
| ) | [static] |
Definition at line 97 of file PathResolver.cpp.
00098 { 00099 std::string::size_type pos = file_name.find_last_of ('/'); 00100 if (pos == std::string::npos) 00101 { 00102 pos = file_name.find_last_of ('\\'); 00103 } 00104 00105 if (pos == std::string::npos) 00106 { 00107 result = ""; 00108 } 00109 else 00110 { 00111 result = file_name; 00112 result.erase (pos); 00113 } 00114 }
| static bool System::PR_find | ( | const std::string & | search_base, | |
| const std::string & | logical_file_prefix, | |||
| const std::string & | logical_file_name, | |||
| PR_file_type | file_type, | |||
| PathResolver::SearchType | search_type, | |||
| std::string & | result | |||
| ) | [static] |
Definition at line 321 of file PathResolver.cpp.
00327 { 00328 static int level = 0; 00329 00330 #ifdef _WIN32 00331 static const char file_separator = '\\'; 00332 #else 00333 static const char file_separator = '/'; 00334 #endif 00335 00336 std::string file_path = ""; 00337 std::string real_name = ""; 00338 00339 bool found = false; 00340 00341 //PR_indent (level); std::cout << "PR_find> sb=" << search_base << " lfp=" << logical_file_prefix << " lfn=" << logical_file_name << std::endl; 00342 00343 if (search_base != "") 00344 { 00345 file_path = search_base; 00346 file_path += file_separator; 00347 } 00348 else 00349 { 00350 file_path = ""; 00351 } 00352 00353 file_path += logical_file_name; 00354 00355 //PR_indent (level); std::cout << "PR_find> test1 file_path=" << file_path << std::endl; 00356 00357 result = file_path; 00358 if (PR_test_exist (file_path, result, file_type)) 00359 { 00360 found = true; 00361 } 00362 00363 if (!found && (logical_file_prefix != "")) 00364 { 00365 if (search_base != "") 00366 { 00367 file_path = search_base; 00368 file_path += file_separator; 00369 } 00370 else 00371 { 00372 file_path = ""; 00373 } 00374 00375 file_path += logical_file_prefix; 00376 file_path += file_separator; 00377 file_path += logical_file_name; 00378 00379 //PR_indent (level); std::cout << "PR_find> test2 file_path=" << file_path << std::endl; 00380 00381 result = file_path; 00382 if (PR_test_exist (file_path, result, file_type)) 00383 { 00384 found = true; 00385 } 00386 } 00387 00388 //PR_indent (level); std::cout << "PR_find> test3 found=" << found << " search_type=" << search_type << std::endl; 00389 00390 if (!found && (search_type == PathResolver::RecursiveSearch)) 00391 { 00392 std::string dir_name = ""; 00393 std::string file_name = ""; 00394 std::vector<std::string> list; 00395 00396 PR_scan_dir (search_base, list); 00397 00398 std::vector<std::string>::iterator it; 00399 00400 for (it = list.begin (); it != list.end (); ++it) 00401 { 00402 const std::string& d = *it; 00403 00404 if (PR_test_exist (d, file_path, PR_directory)) 00405 { 00406 //PR_indent (level); std::cout << "d=" << d << std::endl; 00407 00408 level++; 00409 bool s = PR_find (d, logical_file_prefix, logical_file_name, file_type, search_type, result); 00410 level--; 00411 00412 if (s) 00413 { 00414 //PR_indent (level); std::cout << "PR_find> result=" << result << std::endl; 00415 found = true; 00416 break; 00417 } 00418 } 00419 } 00420 } 00421 00422 return (found); 00423 }
| static bool System::PR_find_from_list | ( | const std::string & | logical_file_name, | |
| const std::string & | search_list, | |||
| PR_file_type | file_type, | |||
| PathResolver::SearchType | search_type, | |||
| std::string & | result | |||
| ) | [static] |
Definition at line 425 of file PathResolver.cpp.
00430 { 00431 #ifdef _WIN32 00432 static const char path_separator = ';'; 00433 #else 00434 static const char path_separator = ':'; 00435 #endif 00436 00437 std::string::size_type pos = 0; 00438 00439 std::string file_name = ""; 00440 std::string file_prefix = ""; 00441 00442 PR_basename (logical_file_name, file_name); 00443 PR_dirname (logical_file_name, file_prefix); 00444 00445 std::string real_name = ""; 00446 00447 bool found = false; 00448 00449 if (PR_find ("", file_prefix, file_name, file_type, search_type, result)) 00450 { 00451 found = true; 00452 } 00453 00454 if (!found) 00455 { 00456 for (int i = 0;;i++) 00457 { 00458 bool ending = false; 00459 00460 std::string::size_type next = search_list.find (path_separator, pos); 00461 00462 std::string path = search_list.substr (pos, next - pos); 00463 00464 if (next == std::string::npos) 00465 { 00466 path = search_list.substr (pos); 00467 ending = true; 00468 } 00469 else 00470 { 00471 path = search_list.substr (pos, next - pos); 00472 pos = next + 1; 00473 } 00474 00475 //std::cout << "path[" << i << "]=" << path << std::endl; 00476 00477 if (PR_find (path, file_prefix, file_name, file_type, search_type, result)) 00478 { 00479 found = true; 00480 break; 00481 } 00482 00483 if (ending) break; 00484 } 00485 } 00486 00487 return (found); 00488 }
| static void System::PR_scan_dir | ( | const std::string & | dir_name, | |
| std::vector< std::string > & | list | |||
| ) | [static] |
Definition at line 213 of file PathResolver.cpp.
00215 { 00216 #ifdef _WIN32 00217 static const char file_separator = '\\'; 00218 #else 00219 static const char file_separator = '/'; 00220 #endif 00221 00222 static std::string dir_prefix; 00223 static std::string name_prefix; 00224 static std::string real_name; 00225 00226 dir_prefix = dir_name; 00227 if (dir_name == "") dir_prefix = "."; 00228 00229 //std::cout << "PR_scan_dir1> dir_name=" << dir_name << " dir_prefix=" << dir_prefix << std::endl; 00230 00231 if (!PR_test_exist (dir_prefix, real_name, PR_directory)) { 00232 PR_dirname (dir_prefix, dir_prefix); 00233 PR_basename (dir_name, name_prefix); 00234 } 00235 00236 bool need_filter = false; 00237 00238 std::string::size_type wild_card; 00239 00240 wild_card = name_prefix.find ('*'); 00241 if (wild_card != std::string::npos) { 00242 name_prefix.erase (wild_card); 00243 00244 if (name_prefix.size () > 0) { 00245 need_filter = true; 00246 } 00247 } 00248 00249 list.clear(); 00250 00251 #ifdef _WIN32 00252 00253 long dir; 00254 struct _finddata_t entry; 00255 00256 static std::string search; 00257 00258 search = dir_prefix; 00259 search += file_separator; 00260 search += "*"; 00261 00262 dir = _findfirst (search.c_str (), &entry); 00263 if (dir > 0) { 00264 for (;;) { 00265 if ((strcmp ((char*) entry.name, ".") != 0) && 00266 (strcmp ((char*) entry.name, "..") != 0) && 00267 (strncmp ((char*) entry.name, ".nfs", 4) != 0)) { 00268 const char* name = entry.name; 00269 00270 if (need_filter && 00271 (strncmp (name, name_prefix.c_str (), name_prefix.size ()) == 0)) continue; 00272 std::string name_entry; 00273 name_entry = dir_prefix; 00274 name_entry += file_separator; 00275 name_entry += name; 00276 00277 list.push_back (name_entry); 00278 } 00279 00280 int status = _findnext (dir, &entry); 00281 if (status != 0) { 00282 break; 00283 } 00284 } 00285 _findclose (dir); 00286 } 00287 #else 00288 00289 DIR* dir = opendir (dir_prefix.c_str ()); 00290 00291 struct dirent* entry; 00292 00293 if (dir != 0) { 00294 while ((entry = readdir (dir)) != 0) { 00295 //if (entry->d_name[0] == '.') continue; 00296 if (!strcmp ((char*) entry->d_name, ".")) continue; 00297 if (!strcmp ((char*) entry->d_name, "..")) continue; 00298 if (!strncmp ((char*) entry->d_name, ".nfs", 4)) continue; 00299 00300 const char* name = entry->d_name; 00301 00302 //std::cout << "scan_dir4> name=" << name << std::endl; 00303 00304 if (need_filter && 00305 (strncmp (name, name_prefix.c_str (), name_prefix.size ()) != 0)) continue; 00306 00307 std::string name_entry; 00308 00309 name_entry = dir_prefix; 00310 name_entry += file_separator; 00311 name_entry += name; 00312 00313 list.push_back (name_entry); 00314 } 00315 closedir (dir); 00316 } 00317 #endif 00318 }
| static bool System::PR_test_exist | ( | const std::string & | name, | |
| std::string & | real_name, | |||
| PR_file_type | file_type | |||
| ) | [static] |
Definition at line 152 of file PathResolver.cpp.
00153 { 00154 struct stat file_stat; 00155 int status; 00156 00157 char buf[1024]; 00158 strcpy (buf, name.c_str ()); 00159 00160 #ifdef _WIN32 00161 static const char file_separator = '\\'; 00162 #else 00163 static const char file_separator = '/'; 00164 #endif 00165 00166 real_name = name; 00167 #ifndef _WIN32 00168 for (;;) { 00169 status = lstat (buf, &file_stat); 00170 if (status == 0) { 00171 if (S_ISLNK (file_stat.st_mode) != 0) { 00172 //std::cout << "#1 " << buf << " stat=" << std::oct << file_stat.st_mode << std::dec << std::endl; 00173 int n = readlink (buf, buf, sizeof (buf)); 00174 if (n >= 0) buf[n] = 0; 00175 //std::cout << "test_exist> buf=" << buf << std::endl; 00176 if (PR_absolute_path (buf)) { 00177 real_name = buf; 00178 } 00179 else { 00180 PR_dirname (real_name, real_name); 00181 real_name += file_separator; 00182 real_name += buf; 00183 PR_compress_path (real_name); 00184 strcpy (buf, real_name.c_str ()); 00185 } 00186 //std::cout << "#2 " << real_name << std::endl; 00187 //break; 00188 } 00189 else { 00190 break; 00191 } 00192 } 00193 else { 00194 break; 00195 } 00196 } 00197 #endif 00198 status = stat (name.c_str (), &file_stat); 00199 00200 if (status == 0) { 00201 if ((file_stat.st_mode & S_IFDIR) == 0) { 00202 return (file_type == PR_regular_file); 00203 } 00204 else { 00205 return (file_type == PR_directory); 00206 } 00207 } 00208 else { 00209 return (false); 00210 } 00211 }
| long System::priorityBoost | ( | InfoType | fetch = PriorityBoost, |
|
| long | pid = -1 | |||
| ) |
Basic Process Information: priority boost.
Definition at line 90 of file Memory.cpp.
00090 { 00091 long info; 00092 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00093 return info; 00094 return -2; 00095 }
| void * System::processHandle | ( | ) |
Handle to running process.
Retrieve processhandle.
Definition at line 119 of file ModuleInfo.cpp.
00119 { 00120 static long pid = ::getpid(); 00121 #ifdef _WIN32 00122 static HANDLE hP = ::OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,FALSE,pid); 00123 #else 00124 static void* hP = (void*)pid; 00125 #endif 00126 return hP; 00127 }
| long System::procID | ( | ) |
| longlong System::remainingTime | ( | TimeType | typ = milliSec, |
|
| InfoType | fetch = Quota, |
|||
| long | pid = -1 | |||
| ) |
Maximum processing time left for this process.
System Process Limits: Maximum processing time left for this process.
| typ | Indicator or the unit the time will be returned. | |
| fetch | Indicator of the information to be fetched. If Fetch_None, the information will not be updated. | |
| pid | Process ID of which the information will be returned |
Definition at line 126 of file Timing.cpp.
00126 { 00127 longlong left = 0; 00128 QUOTA_LIMITS quota; 00129 if ( fetch != NoFetch && getProcess()->query(pid, fetch, "a) ) { 00130 if ( left == -1 ) { 00131 //left = _I64_MAX; 00132 } 00133 else { 00134 left = adjustTime(typ, quota.TimeLimit); 00135 } 00136 } 00137 return left; 00138 }
| StatusCode System::resolveEnv | ( | const std::string & | var, | |
| std::string & | res, | |||
| int | recusions = 124 | |||
| ) |
Definition at line 49 of file Environment.cpp.
00049 { 00050 std::string source = var; 00051 res = i_resolve(source, recursions); 00052 if ( res.find("${") == std::string::npos ) { 00053 return StatusCode::SUCCESS; 00054 } 00055 return StatusCode::FAILURE; 00056 }
| int System::setEnv | ( | const std::string & | name, | |
| const std::string & | value, | |||
| int | overwrite = 1 | |||
| ) |
Set an environment variables.
set an environment variables.
If value is empty, the variable is removed from the environment. When overwrite is 0, the variable is not set if already present. Returns 0 on success, -1 on failure. See man 3 setenv.
Definition at line 782 of file System.cpp.
00783 { 00784 #ifndef WIN32 00785 // UNIX version 00786 return value.empty() ? 00787 // remove if set to nothing (and return success) 00788 ::unsetenv(name.c_str()) , 0 : 00789 // set the value 00790 ::setenv(name.c_str(),value.c_str(), overwrite); 00791 #else 00792 // Windows version 00793 if ( value.empty() ) { 00794 // equivalent to unsetenv 00795 return ::_putenv((name+"=").c_str()); 00796 } 00797 else { 00798 if ( !getenv(name.c_str()) || overwrite ) { 00799 // set if not yet present or overwrite is set (force) 00800 return ::_putenv((name+"="+value).c_str()); 00801 } 00802 } 00803 return 0; // if we get here, we are trying to set a variable already set, but 00804 // not to overwrite. 00805 // It is considered a success on Linux (man P setenv) 00806 #endif 00807 00808 }
| void System::setModuleHandle | ( | System::ImageHandle | handle | ) |
Attach module handle.
Definition at line 129 of file ModuleInfo.cpp.
00129 { 00130 ModuleHandle = handle; 00131 }
| longlong System::systemStart | ( | TimeType | typ = Sec |
) |
Maximum processing time left for this process.
Units of time since system startup and begin of epoche.
| typ | Indicator or the unit the time will be returned. |
Definition at line 99 of file Timing.cpp.
00099 { 00100 static longlong sys_start = 0; 00101 if ( 0 == sys_start ) { 00102 longlong c = currentTime(microSec); 00103 longlong t = tickCount(); 00104 sys_start = 10*c - t; 00105 } 00106 return adjustTime(typ, sys_start); 00107 }
| std::string System::tempDirectory | ( | ) |
Definition at line 86 of file Environment.cpp.
00086 { 00087 // Return a user configured or systemwide directory to create 00088 // temporary files in. 00089 const char *dir = ::getenv("TEMP"); 00090 if (!dir) dir = ::getenv("TEMPDIR"); 00091 if (!dir) dir = ::getenv("TEMP_DIR"); 00092 if (!dir) dir = ::getenv("TMP"); 00093 if (!dir) dir = ::getenv("TMPDIR"); 00094 if (!dir) dir = ::getenv("TMP_DIR"); 00095 if (!dir) return homeDirectory(); 00096 return dir; 00097 }
| ThreadHandle System::threadSelf | ( | ) | [inline] |
| longlong System::tickCount | ( | ) |
Retrieve the number of ticks since system startup.
Definition at line 67 of file Timing.cpp.
00067 { 00068 longlong count = 10000; 00069 #ifdef _WIN32 00070 count *= ::GetTickCount(); // Number of milliSec since system startup 00071 #else 00072 struct tms buf; 00073 count *= 10*times(&buf); 00074 #endif 00075 return count; 00076 }
| const std::string System::typeinfoName | ( | const char * | class_name | ) |
Definition at line 362 of file System.cpp.
00362 { 00363 std::string result; 00364 #ifdef _WIN32 00365 long off = 0; 00366 if ( ::strncmp(class_name, "class ", 6) == 0 ) { 00367 // The returned name is prefixed with "class " 00368 off = 6; 00369 } 00370 if ( ::strncmp(class_name, "struct ", 7) == 0 ) { 00371 // The returned name is prefixed with "struct " 00372 off = 7; 00373 } 00374 if ( off > 0 ) { 00375 std::string tmp = class_name + off; 00376 long loc = 0; 00377 while( (loc = tmp.find("class ")) > 0 ) { 00378 tmp.erase(loc, 6); 00379 } 00380 loc = 0; 00381 while( (loc = tmp.find("struct ")) > 0 ) { 00382 tmp.erase(loc, 7); 00383 } 00384 result = tmp; 00385 } 00386 else { 00387 result = class_name; 00388 } 00389 // Change any " *" to "*" 00390 while ( (off=result.find(" *")) != std::string::npos ) { 00391 result.replace(off, 2, "*"); 00392 } 00393 // Change any " &" to "&" 00394 while ( (off=result.find(" &")) != std::string::npos ) { 00395 result.replace(off, 2, "&"); 00396 } 00397 00398 #elif defined(__linux) || defined(__APPLE__) 00399 if ( ::strlen(class_name) == 1 ) { 00400 // See http://www.realitydiluted.com/mirrors/reality.sgi.com/dehnert_engr/cxx/abi.pdf 00401 // for details 00402 switch(class_name[0]) { 00403 case 'v': 00404 result = "void"; 00405 break; 00406 case 'w': 00407 result = "wchar_t"; 00408 break; 00409 case 'b': 00410 result = "bool"; 00411 break; 00412 case 'c': 00413 result = "char"; 00414 break; 00415 case 'a': 00416 result = "signed char"; 00417 break; 00418 case 'h': 00419 result = "unsigned char"; 00420 break; 00421 case 's': 00422 result = "short"; 00423 break; 00424 case 't': 00425 result = "unsigned short"; 00426 break; 00427 case 'i': 00428 result = "int"; 00429 break; 00430 case 'j': 00431 result = "unsigned int"; 00432 break; 00433 case 'l': 00434 result = "long"; 00435 break; 00436 case 'm': 00437 result = "unsigned long"; 00438 break; 00439 case 'x': 00440 result = "long long"; 00441 break; 00442 case 'y': 00443 result = "unsigned long long"; 00444 break; 00445 case 'n': 00446 result = "__int128"; 00447 break; 00448 case 'o': 00449 result = "unsigned __int128"; 00450 break; 00451 case 'f': 00452 result = "float"; 00453 break; 00454 case 'd': 00455 result = "double"; 00456 break; 00457 case 'e': 00458 result = "long double"; 00459 break; 00460 case 'g': 00461 result = "__float128"; 00462 break; 00463 case 'z': 00464 result = "ellipsis"; 00465 break; 00466 } 00467 } 00468 else { 00469 int status; 00470 char* realname; 00471 realname = abi::__cxa_demangle(class_name, 0, 0, &status); 00472 if (realname == 0) return class_name; 00473 result = realname; 00474 free(realname); 00476 std::string::size_type pos = result.find(", "); 00477 while( std::string::npos != pos ) { 00478 result.replace( pos , 2 , "," ) ; 00479 pos = result.find(", "); 00480 } 00481 } 00482 #endif 00483 return result; 00484 }
| const std::string System::typeinfoName | ( | const std::type_info & | tinfo | ) |
Get platform independent information about the class type.
Definition at line 359 of file System.cpp.
00359 { 00360 return typeinfoName(tinfo.name()); 00361 }
| unsigned long System::unloadDynamicLib | ( | ImageHandle | handle | ) |
unload dynamic link library
Definition at line 156 of file System.cpp.
00156 { 00157 #ifdef _WIN32 00158 if ( !::FreeLibrary((HINSTANCE)handle) ) { 00159 #elif defined(linux) || defined(__APPLE__) 00160 ::dlclose( handle ); 00161 if ( 0 ) { 00162 #elif __hpux 00163 // On HP we have to run finalization ourselves..... 00164 Creator pFinalize = 0; 00165 if ( getProcedureByName(handle, "_fini", &pFinalize) ) { 00166 pFinalize(); 00167 } 00168 HMODULE* mod = (HMODULE*)handle; 00169 if ( 0 == ::shl_unload( mod->dsc.handle ) ) { 00170 delete mod; 00171 } 00172 else { 00173 #endif 00174 return getLastError(); 00175 }
| longlong System::upTime | ( | TimeType | typ = Hour |
) |
Maximum processing time left for this process.
Units of time since system startup in requested units.
| typ | Indicator or the unit the time will be returned. |
Definition at line 110 of file Timing.cpp.
00110 { 00111 static longlong sys_start = 10*systemStart(microSec); 00112 return adjustTime(typ, 10*currentTime(microSec)-sys_start); 00113 }
| longlong System::userTime | ( | TimeType | typ = milliSec, |
|
| InfoType | fetch = Times, |
|||
| long | pid = -1 | |||
| ) |
CPU user mode time of process in milli seconds.
CPU kernel time of process in milli seconds.
| typ | Indicator or the unit the time will be returned. | |
| fetch | Indicator of the information to be fetched. If Fetch_None, the information will not be updated. | |
| pid | Process ID of which the information will be returned |
Definition at line 160 of file Timing.cpp.
00160 { 00161 longlong usertime = 0; 00162 KERNEL_USER_TIMES info; 00163 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) { 00164 usertime = adjustTime(typ, info.UserTime ); 00165 } 00166 return usertime; 00167 }
| long System::virtualMemory | ( | MemoryUnit | unit = kByte, |
|
| InfoType | fetch = Memory, |
|||
| long | pid = -1 | |||
| ) |
Basic Process Information: priority boost.
Definition at line 213 of file Memory.cpp.
00213 { 00214 VM_COUNTERS info; 00215 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00216 return adjustMemory(unit, info.VirtualSize); 00217 return -2; 00218 }
| long System::virtualMemoryLimit | ( | MemoryUnit | unit = kByte, |
|
| InfoType | fetch = Quota, |
|||
| long | pid = -1 | |||
| ) |
System Process Limits: Maximum amount of the page file this process is allowed to use.
Definition at line 229 of file Memory.cpp.
00229 { 00230 QUOTA_LIMITS quota; 00231 if ( fetch != NoFetch && getProcess()->query(pid, fetch, "a) ) { 00232 if ( long(quota.PagefileLimit) == -1 ) 00233 return -1;//LONG_MAX; 00234 return adjustMemory(unit, quota.PagefileLimit); 00235 } 00236 return 0; 00237 }
| long System::virtualMemoryPeak | ( | MemoryUnit | unit = kByte, |
|
| InfoType | fetch = Memory, |
|||
| long | pid = -1 | |||
| ) |
Basic Process Information: priority boost.
Definition at line 221 of file Memory.cpp.
00221 { 00222 VM_COUNTERS info; 00223 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00224 return adjustMemory(unit, info.PeakVirtualSize); 00225 return -2; 00226 }