System Namespace Reference

Note: OS specific details for environment resolution. More...

Classes

struct  IO_COUNTERS
 Process I/O Counters NtQueryInformationProcess using ProcessIoCounters. More...
 
struct  KERNEL_USER_TIMES
 Process/Thread System and User Time NtQueryInformationProcess using ProcessTimes NtQueryInformationThread using ThreadTimes. More...
 
class  PathResolver
 
struct  POOLED_USAGE_AND_LIMITS
 Process Pooled Quota Usage and Limits NtQueryInformationProcess using ProcessPooledUsageAndLimits. More...
 
struct  PROCESS_BASIC_INFORMATION
 
class  ProcessDescriptor
 Provides access to process information. More...
 
class  ProcessTime
 Simple class to hold the time information of a process. More...
 
struct  QUOTA_LIMITS
 Process Quotas NtQueryInformationProcess using ProcessQuotaLimits NtQueryInformationProcess using ProcessPooledQuotaLimits NtSetInformationProcess using ProcessQuotaLimits. More...
 
struct  VM_COUNTERS
 Process Virtual Memory Counters NtQueryInformationProcess using ProcessVmCounters. More...
 

Typedefs

typedef void * ImageHandle
 Definition of an image handle. More...
 
typedef void * ProcessHandle
 Definition of the process handle. More...
 
typedef unsigned long(* EntryPoint) (const unsigned long iid, void **ppvObject)
 Definition of the "generic" DLL entry point function. More...
 
typedef void *(* Creator) ()
 Definition of the "generic" DLL entry point function. More...
 
typedef void * ThreadHandle
 A Thread handle. More...
 
typedef struct _PEB * PPEB
 Basic Process Information NtQueryInformationProcess using ProcessBasicInfo. More...
 

Enumerations

enum  MemoryUnit {
  Byte, kByte, MByte, GByte,
  TByte, PByte, EByte, Byte,
  kByte, MByte, GByte, TByte,
  PByte, EByte
}
 Unit of memory. More...
 
enum  ModuleType {
  UNKNOWN, SHAREDLIB, EXECUTABLE, UNKNOWN,
  SHAREDLIB, EXECUTABLE
}
 
enum  InfoType {
  NoFetch, RemainTime, Times, ProcessBasics,
  PriorityBoost, Memory, Quota, System,
  Modules, IO, 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, Native, Year, Month,
  Day, Hour, Min, Sec,
  milliSec, microSec, nanoSec, Native
}
 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
}
 
enum  MemoryUnit {
  Byte, kByte, MByte, GByte,
  TByte, PByte, EByte, Byte,
  kByte, MByte, GByte, TByte,
  PByte, EByte
}
 Unit of memory. More...
 
enum  ModuleType {
  UNKNOWN, SHAREDLIB, EXECUTABLE, UNKNOWN,
  SHAREDLIB, EXECUTABLE
}
 
enum  InfoType {
  NoFetch, RemainTime, Times, ProcessBasics,
  PriorityBoost, Memory, Quota, System,
  Modules, IO, 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, Native, Year, Month,
  Day, Hour, Min, Sec,
  milliSec, microSec, nanoSec, Native
}
 Time type for conversion. More...
 

Functions

GAUDI_API long breakExecution ()
 Break the execution of the application and invoke the debugger. More...
 
GAUDI_API long breakExecution (long pid)
 Break the execution of the application and invoke the debugger in a remote process. More...
 
GAUDI_API std::string homeDirectory ()
 
GAUDI_API std::string tempDirectory ()
 
GAUDI_API StatusCode resolveEnv (const std::string &var, std::string &res, int recusions=124)
 
GAUDI_API long adjustMemory (MemoryUnit typ, long value)
 Convert time from kByte to requested representation (Experts only) More...
 
GAUDI_API long procID ()
 Basic Process Information: Process ID. More...
 
GAUDI_API long parentID (InfoType fetch=ProcessBasics, long pid=-1)
 Basic Process Information: Parent's process ID. More...
 
GAUDI_API long affinityMask (InfoType fetch=ProcessBasics, long pid=-1)
 Basic Process Information: Affinity mask. More...
 
GAUDI_API 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!) More...
 
GAUDI_API long basePriority (InfoType fetch=ProcessBasics, long pid=-1)
 Basic Process Information: Base priority. More...
 
GAUDI_API long priorityBoost (InfoType fetch=PriorityBoost, long pid=-1)
 Basic Process Information: priority boost. More...
 
GAUDI_API long numPageFault (InfoType fetch=Memory, long pid=-1)
 Basic Process Information: Number of page faults. More...
 
GAUDI_API long pagefileUsage (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
 Basic Process Information: Current page file usage. More...
 
GAUDI_API long pagefileUsagePeak (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
 Basic Process Information: Peak usage of page file. More...
 
GAUDI_API long pagefileUsageLimit (MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1)
 Basic Process Information: Peak usage of page file. More...
 
GAUDI_API long nonPagedMemory (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
 Basic Process Information: Current usage of non paged memory. More...
 
GAUDI_API long nonPagedMemoryPeak (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
 Basic Process Information: Peak usage of non paged memory. More...
 
GAUDI_API 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. More...
 
GAUDI_API long pagedMemory (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
 Basic Process Information: Amount of paged memory currently occupied by the process 'pid'. More...
 
GAUDI_API long pagedMemoryPeak (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
 Basic Process Information: Maximum of paged memory occupied by the process 'pid'. More...
 
GAUDI_API 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'. More...
 
GAUDI_API long minMemoryLimit (MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1)
 System Process Limits: Minimum amount of virtual memory this process may use. More...
 
GAUDI_API 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. More...
 
GAUDI_API long mappedMemory (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
 Basic Process Information: priority boost. More...
 
GAUDI_API long mappedMemoryPeak (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
 Basic Process Information: priority boost. More...
 
GAUDI_API long virtualMemory (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
 Basic Process Information: priority boost. More...
 
GAUDI_API long virtualMemoryPeak (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
 Basic Process Information: priority boost. More...
 
GAUDI_API 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. More...
 
GAUDI_API const std::string & moduleName ()
 Get the name of the (executable/DLL) file without file-type. More...
 
GAUDI_API const std::string & moduleNameFull ()
 Get the full name of the (executable/DLL) file. More...
 
GAUDI_API ModuleType moduleType ()
 Get type of the module. More...
 
GAUDI_API ProcessHandle processHandle ()
 Handle to running process. More...
 
GAUDI_API ImageHandle moduleHandle ()
 Handle to currently executed module. More...
 
GAUDI_API ImageHandle exeHandle ()
 Handle to the executable file running. More...
 
GAUDI_API const std::string & exeName ()
 Name of the executable file running. More...
 
GAUDI_API const std::vector< std::string > linkedModules ()
 Vector of names of linked modules. More...
 
GAUDI_API void setModuleHandle (ImageHandle handle)
 Attach module handle. More...
 
GAUDI_API std::string PathResolverFindXMLFile (const std::string &logical_file_name)
 
GAUDI_API std::string PathResolverFindDataFile (const std::string &logical_file_name)
 
GAUDI_API unsigned long loadDynamicLib (const std::string &name, ImageHandle *handle)
 Load dynamic link library. More...
 
GAUDI_API unsigned long unloadDynamicLib (ImageHandle handle)
 unload dynamic link library More...
 
GAUDI_API unsigned long getProcedureByName (ImageHandle handle, const std::string &name, EntryPoint *pFunction)
 Get a specific function defined in the DLL. More...
 
GAUDI_API unsigned long getProcedureByName (ImageHandle handle, const std::string &name, Creator *pFunction)
 Get a specific function defined in the DLL. More...
 
GAUDI_API unsigned long getLastError ()
 Get last system known error. More...
 
GAUDI_API const std::string getLastErrorString ()
 Get last system error as string. More...
 
GAUDI_API const std::string getErrorString (unsigned long error)
 Retrieve error code as string for a given error. More...
 
GAUDI_API const std::string typeinfoName (const std::type_info &)
 Get platform independent information about the class type. More...
 
GAUDI_API const std::string typeinfoName (const char *)
 
GAUDI_API const std::string & hostName ()
 Host name. More...
 
GAUDI_API const std::string & osName ()
 OS name. More...
 
GAUDI_API const std::string & osVersion ()
 OS version. More...
 
GAUDI_API const std::string & machineType ()
 Machine type. More...
 
GAUDI_API int instructionsetLevel ()
 Instruction Set "Level". More...
 
GAUDI_API const std::string & accountName ()
 User login name. More...
 
GAUDI_API long numCmdLineArgs ()
 Number of arguments passed to the commandline. More...
 
GAUDI_API long argc ()
 Number of arguments passed to the commandline (==numCmdLineArgs()); just to match argv call... More...
 
GAUDI_API const std::vector< std::string > cmdLineArgs ()
 Command line arguments including executable name as arg[0] as vector of strings. More...
 
GAUDI_API char ** argv ()
 char** command line arguments including executable name as arg[0]; You may not modify them! More...
 
GAUDI_API std::string getEnv (const char *var)
 get a particular environment variable (returning "UNKNOWN" if not set) More...
 
GAUDI_API bool getEnv (const char *var, std::string &value)
 get a particular environment variable, storing the value in the passed string if the variable is set. More...
 
bool getEnv (const std::string &var, std::string &value)
 
GAUDI_API std::vector< std::string > getEnv ()
 get all environment variables More...
 
GAUDI_API int setEnv (const std::string &name, const std::string &value, int overwrite=1)
 Set an environment variables. More...
 
GAUDI_API bool isEnvSet (const char *var)
 Check if an environment variable is set or not. More...
 
ThreadHandle threadSelf ()
 thread handle "accessor" More...
 
GAUDI_API int backTrace (void **addresses, const int depth)
 
GAUDI_API bool backTrace (std::string &btrace, const int depth, const int offset=0)
 
GAUDI_API bool getStackLevel (void *addresses, void *&addr, std::string &fnc, std::string &lib)
 
GAUDI_API longlong adjustTime (TimeType typ, longlong timevalue)
 Convert time from OS native time to requested representation (Experts only) More...
 
template<TimeType T>
long long adjustTime (long long timevalue)
 Convert the time from OS native time to requested representation (Experts only) More...
 
GAUDI_API longlong ellapsedTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
 Elapsed time since start of process in milliseconds. More...
 
GAUDI_API longlong kernelTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
 CPU kernel mode time of process in milliseconds. More...
 
GAUDI_API longlong userTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
 CPU user mode time of process in milliseconds. More...
 
GAUDI_API longlong cpuTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
 Consumed CPU time of process in milliseconds. More...
 
GAUDI_API longlong remainingTime (TimeType typ=milliSec, InfoType fetch=Quota, long pid=-1)
 Maximum processing time left for this process. More...
 
GAUDI_API longlong creationTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
 Process Creation time. More...
 
GAUDI_API longlong systemStart (TimeType typ=Sec)
 Maximum processing time left for this process. More...
 
GAUDI_API longlong upTime (TimeType typ=Hour)
 Maximum processing time left for this process. More...
 
GAUDI_API longlong currentTime (TimeType typ=milliSec)
 Retrieve absolute system time. More...
 
GAUDI_API longlong tickCount ()
 Retrieve the number of ticks since system startup. More...
 
GAUDI_API ProcessTime getProcessTime (long pid=-1)
 Retrieve the process time data for a process. More...
 
template<>
long long adjustTime< Year > (long long t)
 
template<>
long long adjustTime< Day > (long long t)
 
template<>
long long adjustTime< Hour > (long long t)
 
template<>
long long adjustTime< Min > (long long t)
 
template<>
long long adjustTime< Sec > (long long t)
 
template<>
long long adjustTime< milliSec > (long long t)
 
template<>
long long adjustTime< microSec > (long long t)
 
template<>
long long adjustTime< nanoSec > (long long t)
 
template<>
long long adjustTime< Month > (long long t)
 
template<>
long long adjustTime< Native > (long long t)
 
ProcessDescriptorgetProcess ()
 Retrieve Process structure. More...
 

Detailed Description

Note: OS specific details for environment resolution.

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:

Author
: M.Frank
Version
: 1.0

Entrypoints:

  • basePriority Base priority
  • procID Process ID
  • parentID Parent's process ID
  • affinityMask Affinity mask
  • exitStatus Exit status
  • priorityBoost Priority boost
  • numPageFault Number of page faults
  • pagefileUsage Current page file usage
  • pagefileUsagePeak Peak usage of page file
  • nonPagedMemory Current usage of non paged memory
  • nonPagedMemoryPeak Peak usage of non paged memory
  • nonPagedMemoryLimit Maximum amount of non-paged memory this process is allowed to use
  • pagedMemory Amount of paged memory currently occupied
  • pagedMemoryPeak Maximum of paged memory occupied by the process
  • pagedMemoryLimit paged memory that can be occupied by the process
  • memorySize Size of currently occupied memory
  • memorySizePeak Maximum memory occupied by the process
  • memoryLimit Amount of memory that can be occupied by the process
  • virtualMemorySize Virtual memory size currenly occupied
  • peakVirtualMemorySize Maximum amount of virtual memory occupied
  • virtualMemoryLimit Amount of virtual memory that can be occupied by the process
  • minMemoryLimit Minimum amount of virtual memory this process may use
  • maxMemoryLimit Maximum amount of virtual memory this process is allowed to use
  • mappedMemorySize Currenly mapped virtual memory size
  • mappedMemorySizePeak Peak mapped virtual memory size
Author
: M.Frank
Version
: 1.0

M.Frank

Since e.g. IID is defined in both, this would lead automatically to complete comilation failures.....

Author
M.Frank

Entrypoints:

  • remainingTime returns the time the process could still execute
  • ellapsedTime: returns elapsed time since program start
  • kernelTime: returns the amount of time the process has spent in kernel mode
  • userTime: returns the amount of time the process has spent in user mode
  • cpuTime: returns kernel+user time

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     |
+---------+----------------------------------------------+--------+
Author
: M.Frank
Version
: 1.0

Typedef Documentation

typedef void *(* System::Creator)()

Definition of the "generic" DLL entry point function.

Definition at line 38 of file System.h.

typedef unsigned long(* System::EntryPoint)(const unsigned long iid, void **ppvObject)

Definition of the "generic" DLL entry point function.

Definition at line 36 of file System.h.

typedef void * System::ImageHandle

Definition of an image handle.

Definition at line 30 of file ModuleInfo.h.

typedef struct _PEB* System::PPEB

Basic Process Information NtQueryInformationProcess using ProcessBasicInfo.

Definition at line 18 of file ProcessDescriptor.h.

typedef void * System::ProcessHandle

Definition of the process handle.

Definition at line 32 of file ModuleInfo.h.

typedef void * System::ThreadHandle

A Thread handle.

Definition at line 111 of file System.h.

Enumeration Type Documentation

Enumeration for fetching information.

Enumerator
NoFetch 
RemainTime 
Times 
ProcessBasics 
PriorityBoost 
Memory 
Quota 
System 
Modules 
IO 
NoFetch 
RemainTime 
Times 
ProcessBasics 
PriorityBoost 
Memory 
Quota 
System 
Modules 
IO 

Definition at line 18 of file SystemBase.h.

Enumeration for fetching information.

Enumerator
NoFetch 
RemainTime 
Times 
ProcessBasics 
PriorityBoost 
Memory 
Quota 
System 
Modules 
IO 
NoFetch 
RemainTime 
Times 
ProcessBasics 
PriorityBoost 
Memory 
Quota 
System 
Modules 
IO 

Definition at line 18 of file SystemBase.h.

Unit of memory.

Enumerator
Byte 
kByte 
MByte 
GByte 
TByte 
PByte 
EByte 
Byte 
kByte 
MByte 
GByte 
TByte 
PByte 
EByte 

Definition at line 57 of file Memory.h.

Unit of memory.

Enumerator
Byte 
kByte 
MByte 
GByte 
TByte 
PByte 
EByte 
Byte 
kByte 
MByte 
GByte 
TByte 
PByte 
EByte 

Definition at line 57 of file Memory.h.

Enumerator
UNKNOWN 
SHAREDLIB 
EXECUTABLE 
UNKNOWN 
SHAREDLIB 
EXECUTABLE 

Definition at line 28 of file ModuleInfo.h.

Enumerator
UNKNOWN 
SHAREDLIB 
EXECUTABLE 
UNKNOWN 
SHAREDLIB 
EXECUTABLE 

Definition at line 28 of file ModuleInfo.h.

Enumerator
PR_regular_file 
PR_directory 

Definition at line 35 of file PathResolver.cpp.

Enumerator
PR_local 
PR_recursive 

Definition at line 40 of file PathResolver.cpp.

Enumerator
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 

Definition at line 20 of file ProcessDescriptor.cpp.

20  {
34  ProcessIoPortHandlers, // Note: this is kernel mode only
46  };

Time type for conversion.

Enumerator
Year 
Month 
Day 
Hour 
Min 
Sec 
milliSec 
microSec 
nanoSec 
Native 
Year 
Month 
Day 
Hour 
Min 
Sec 
milliSec 
microSec 
nanoSec 
Native 

Definition at line 51 of file Timing.h.

Time type for conversion.

Enumerator
Year 
Month 
Day 
Hour 
Min 
Sec 
milliSec 
microSec 
nanoSec 
Native 
Year 
Month 
Day 
Hour 
Min 
Sec 
milliSec 
microSec 
nanoSec 
Native 

Definition at line 51 of file Timing.h.

Function Documentation

GAUDI_API const std::string & System::accountName ( )

User login name.

Definition at line 512 of file System.cpp.

512  {
513  static std::string account = "";
514  if ( account == "" ) {
515 #ifdef _WIN32
516  char buffer[512];
517  unsigned long buflen = sizeof(buffer);
518  ::GetUserName(buffer, &buflen);
519  account = buffer;
520 #else
521  const char* acct = ::getlogin();
522  if ( 0 == acct ) acct = ::getenv("LOGNAME");
523  if ( 0 == acct ) acct = ::getenv("USER");
524  account = (acct) ? acct : "Unknown";
525 #endif
526  }
527  return account;
528 }
GAUDI_API 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.

35  {
36  if ( value != -1 ) {
37  switch ( unit ) {
38  case Byte: break;
39  case kByte: value = value/1024; break;
40  case MByte: value = (value/1024)/1024; break;
41  case GByte: value = ((value/1024)/1024)/1024; break;
42  case TByte: value = (((value/1024)/1024)/1024)/1024; break;
43  case PByte: value = ((((value/1024)/1024)/1024)/1024)/1024; break;
44  case EByte: value = (((((value/1024)/1024)/1024)/1024)/1024)/1024; break;
45  default: value = -1; break;
46  }
47  }
48  return value;
49 }
GAUDI_API longlong System::adjustTime ( TimeType  typ,
longlong  timevalue 
)

Convert time from OS native time to requested representation (Experts only)

unfortunately "-ansi" flag turn off the 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.

38  {
39  if ( t != -1 ) {
40 #ifndef _WIN32
41  // t /= CLK_TCK ; // needs division by clock tick unit
46 
48 #endif
49  switch( typ ) {
50  case Year : return adjustTime<Year >(t);
51  case Month : return adjustTime<Month >(t);
52  case Day : return adjustTime<Day >(t);
53  case Hour : return adjustTime<Hour >(t);
54  case Min : return adjustTime<Min >(t);
55  case Sec : return adjustTime<Sec >(t);
56  case milliSec: return adjustTime<milliSec>(t);
57  case microSec: return adjustTime<microSec>(t);
58  case nanoSec : return adjustTime<nanoSec >(t);
59  case Native : return adjustTime<Native >(t);
60  }
61  }
62  return t;
63 }
long long adjustTime< Native >(long long t)
Definition: Timing.h:219
long long adjustTime< Month >(long long t)
Definition: Timing.h:215
long long adjustTime< nanoSec >(long long t)
Definition: Timing.h:211
long long adjustTime< Day >(long long t)
Definition: Timing.h:187
long long adjustTime< milliSec >(long long t)
Definition: Timing.h:203
long long adjustTime< Year >(long long t)
Definition: Timing.h:183
long long adjustTime< microSec >(long long t)
Definition: Timing.h:207
long long adjustTime< Min >(long long t)
Definition: Timing.h:195
long long adjustTime< Hour >(long long t)
Definition: Timing.h:191
long long adjustTime< Sec >(long long t)
Definition: Timing.h:199
template<TimeType T>
long long System::adjustTime ( long long  timevalue)
inline

Convert the time from OS native time to requested representation (Experts only)

template<>
long long System::adjustTime< Day > ( long long  t)
inline

Definition at line 187 of file Timing.h.

187  {
188  return (t==-1) ? t : t /= (1LL * 24 * 60 * 60 * 1000 * 1000 * 10);
189  }
template<>
long long System::adjustTime< Hour > ( long long  t)
inline

Definition at line 191 of file Timing.h.

191  {
192  return (t==-1) ? t : t /= (1LL * 60 * 60 * 1000 * 1000 * 10);
193  }
template<>
long long System::adjustTime< microSec > ( long long  t)
inline

Definition at line 207 of file Timing.h.

207  {
208  return (t==-1) ? t : t /= (10LL);
209  }
template<>
long long System::adjustTime< milliSec > ( long long  t)
inline

Definition at line 203 of file Timing.h.

203  {
204  return (t==-1) ? t : t /= (1000 * 10);
205  }
template<>
long long System::adjustTime< Min > ( long long  t)
inline

Definition at line 195 of file Timing.h.

195  {
196  return (t==-1) ? t : t /= (60 * 1000 * 1000 * 10);
197  }
template<>
long long System::adjustTime< Month > ( long long  t)
inline

Definition at line 215 of file Timing.h.

215  {
216  return (t==-1) ? t : t /= (1LL * 30 * 24 * 60 * 60 * 1000 * 1000 * 10);
217  }
template<>
long long System::adjustTime< nanoSec > ( long long  t)
inline

Definition at line 211 of file Timing.h.

211  {
212  return (t==-1) ? t : t *= 100LL;
213  }
template<>
long long System::adjustTime< Native > ( long long  t)
inline

Definition at line 219 of file Timing.h.

219  {
220  return t;
221  }
template<>
long long System::adjustTime< Sec > ( long long  t)
inline

Definition at line 199 of file Timing.h.

199  {
200  return (t==-1) ? t : t /= (1000 * 1000 * 10);
201  }
template<>
long long System::adjustTime< Year > ( long long  t)
inline

Definition at line 183 of file Timing.h.

183  {
184  return (t==-1) ? t : t /= (1LL * 365 * 24 * 60 * 60 * 1000 * 1000 * 10);
185  }
GAUDI_API long System::affinityMask ( InfoType  fetch = ProcessBasics,
long  pid = -1 
)

Basic Process Information: Affinity mask.

Definition at line 74 of file Memory.cpp.

74  {
75  PROCESS_BASIC_INFORMATION info;
76  if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) )
77  return info.AffinityMask;
78  return 0;
79 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API 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 536 of file System.cpp.

536  {
537  return cmdLineArgs().size();
538 }
GAUDI_API const std::vector< std::string > cmdLineArgs()
Command line arguments including executable name as arg[0] as vector of strings.
Definition: System.cpp:541
GAUDI_API 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 603 of file System.cpp.

603  {
605  if( s_argvChars.empty() ) { cmdLineArgs(); }
606  // We rely here on the fact that a vector's allocation table is contiguous
608  return (char**)&s_argvChars[0];
609 }
GAUDI_API const std::vector< std::string > cmdLineArgs()
Command line arguments including executable name as arg[0] as vector of strings.
Definition: System.cpp:541
GAUDI_API int System::backTrace ( void **  addresses,
const int  depth 
)
GAUDI_API bool System::backTrace ( std::string &  btrace,
const int  depth,
const int  offset = 0 
)

Definition at line 686 of file System.cpp.

687 {
688  // Always hide the first two levels of the stack trace (that's us)
689  const int totalOffset = offset + 2;
690  const int totalDepth = depth + totalOffset;
691 
692  std::string fnc, lib;
693 
694  void** addresses = (void**) malloc(totalDepth*sizeof(void *));
695  if ( addresses != 0 ){
696  int count = System::backTrace(addresses,totalDepth);
697  for (int i = totalOffset; i < count; ++i) {
698  void *addr = 0;
699 
700  if (System::getStackLevel(addresses[i],addr,fnc,lib)) {
701  std::ostringstream ost;
702  ost << "#" << std::setw(3) << std::setiosflags( std::ios::left ) << i-totalOffset+1;
703  ost << std::hex << addr << std::dec << " " << fnc << " [" << lib << "]" << std::endl;
704  btrace += ost.str();
705  }
706  }
707  free(addresses);
708  }
709  else {
710  free(addresses);
711  return false;
712  }
713 
714  return true;
715 }
GAUDI_API bool getStackLevel(void *addresses, void *&addr, std::string &fnc, std::string &lib)
GAUDI_API int backTrace(void **addresses, const int depth)
list i
Definition: ana.py:128
GAUDI_API long System::basePriority ( InfoType  fetch = ProcessBasics,
long  pid = -1 
)

Basic Process Information: Base priority.

Definition at line 52 of file Memory.cpp.

52  {
53  PROCESS_BASIC_INFORMATION info;
54  if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) )
55  return info.BasePriority;
56  return 0;
57 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API long System::breakExecution ( )

Break the execution of the application and invoke the debugger.

Definition at line 47 of file Debugger.cpp.

47  {
48 #ifdef _WIN32
49  _asm int 3
50  return 1;
51 #else
52  // I have no clue how to do this in linux
53  return 0;
54 #endif
55 }
GAUDI_API 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 58 of file Debugger.cpp.

58  {
59 #ifdef _WIN32
60  long result = 0;
61  if ( pid == Win::_getpid() ) {
62  _asm int 3
63  return 1;
64  }
65  else {
66  Win::LPTHREAD_START_ROUTINE fun;
67  Win::HANDLE th, ph;
68  Win::HINSTANCE mh;
69  Win::DWORD id;
70  mh = Win::LoadLibrary( "Kernel32" );
71  if ( 0 != mh ) {
72  fun = (Win::LPTHREAD_START_ROUTINE)Win::GetProcAddress(mh, "DebugBreak");
73  if ( 0 != fun ) {
74  ph = Win::OpenProcess (PROCESS_ALL_ACCESS, TRUE, pid);
75  if ( 0 != ph ) {
76  th = Win::CreateRemoteThread(ph,NULL,0,fun,0,0,&id);
77  if ( 0 != th ) {
78  Win::CloseHandle(th);
79  result = 1;
80  }
81  Win::CloseHandle(ph);
82  }
83  }
84  Win::FreeLibrary(mh);
85  }
86  }
87  if ( result != 1 ) result = Win::GetLastError();
88  return result;
89 #else
90  // I have no clue how to do this in linux
91  return pid;
92 #endif
93 }
TRUE
for job options legacy (TODO: get rid of these!) ----------------------—
Definition: Constants.py:20
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:27
GAUDI_API 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 541 of file System.cpp.

541  {
542  if ( s_argvChars.size() == 0 ) {
543  char exe[1024];
544 #ifdef _WIN32
545  // Disable warning C4996 triggered by C standard library calls
547 #pragma warning(push)
548 #pragma warning(disable:4996)
549  // For compatibility with UNIX we CANNOT use strtok!
550  // If we would use strtok, options like -g="My world" at
551  // the command line level would result on NT in TWO options
552  // instead in one as in UNIX.
553  char *next, *tmp1, *tmp2;
554  for(LPTSTR cmd = ::GetCommandLine(); *cmd; cmd=next) {
555  memset(exe,0,sizeof(exe));
556  while ( *cmd == ' ' ) cmd++;
557  next=::strchr(cmd,' ');
558  if ( !next ) next = cmd + strlen(cmd);
559  if ( (tmp1=::strchr(cmd,'\"')) > 0 && tmp1 < next ) {
560  tmp2 = ::strchr(++tmp1,'\"');
561  if ( tmp2 > 0 ) {
562  next = ++tmp2;
563  if ( cmd < tmp1 ) strncpy(exe, cmd, tmp1-cmd-1);
564  strncpy(&exe[strlen(exe)], tmp1, tmp2-tmp1-1);
565  }
566  else {
567  std::cout << "Mismatched \" in command line arguments" << std::endl;
568  s_argvChars.erase(s_argvChars.begin(), s_argvChars.end());
569  s_argvStrings.erase(s_argvStrings.begin(), s_argvStrings.end());
570  return s_argvStrings;
571  }
572  }
573  else {
574  strncpy(exe, cmd, next-cmd);
575  }
576  s_argvStrings.push_back(exe);
577  s_argvChars.push_back( s_argvStrings.back().c_str());
578  }
579 #pragma warning(pop)
580 #elif defined(__linux) || defined(__APPLE__)
581  sprintf(exe, "/proc/%d/cmdline", ::getpid());
582  FILE *cmdLine = ::fopen(exe,"r");
583  char cmd[1024];
584  if ( cmdLine ) {
585  long len = fread(cmd, sizeof(char), sizeof(cmd), cmdLine);
586  if ( len > 0 ) {
587  cmd[len] = 0;
588  for ( char* token = cmd; token-cmd < len; token += strlen(token)+1 ) {
589  s_argvStrings.push_back(token);
590  s_argvChars.push_back( s_argvStrings.back().c_str());
591  }
592  s_argvStrings[0] = exeName();
593  s_argvChars[0] = s_argvStrings[0].c_str();
594  }
595  ::fclose(cmdLine);
596  }
597 #endif
598  }
599  return s_argvStrings;
600 }
GAUDI_API const std::string & exeName()
Name of the executable file running.
Definition: ModuleInfo.cpp:208
GAUDI_API longlong System::cpuTime ( TimeType  typ = milliSec,
InfoType  fetch = Times,
long  pid = -1 
)

Consumed CPU time of process in milliseconds.

CPU kernel time of process in milliseconds.

Parameters
typIndicator or the unit the time will be returned.
fetchIndicator of the information to be fetched. If Fetch_None, the information will not be updated.
pidProcess ID of which the information will be returned
Returns
Requested value in the indicated units.

Definition at line 169 of file Timing.cpp.

169  {
170  longlong cputime = 0;
171  KERNEL_USER_TIMES info;
172  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) {
173  cputime = adjustTime(typ, info.KernelTime+info.UserTime );
174  }
175  return cputime;
176 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:38
GAUDI_API 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.

Parameters
typIndicator or the unit the time will be returned.
fetchIndicator of the information to be fetched. If Fetch_None, the information will not be updated.
pidProcess ID of which the information will be returned
Returns
Requested value in the indicated units.

Definition at line 115 of file Timing.cpp.

115  {
116  longlong created = 0;
117  KERNEL_USER_TIMES info;
118  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) {
119  created = adjustTime(typ, info.CreateTime-UNIX_BASE_TIME);
120  }
121  return created;
122 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:38
GAUDI_API longlong System::currentTime ( TimeType  typ = milliSec)

Retrieve absolute system time.

Retrieve current system time.

Parameters
typIndicator or the unit the time will be returned.
Returns
Requested value in the indicated units.

Definition at line 80 of file Timing.cpp.

80  {
81  longlong current = 0;
82 #ifdef _WIN32
83  ::GetSystemTimeAsFileTime((FILETIME*)&current);
84  current -= UNIX_BASE_TIME;
85 #else
86  struct timeval tv;
87  struct timezone tz;
88  ::gettimeofday(&tv, &tz);
89  current = tv.tv_sec;
90  current *= 1000000;
91  current += tv.tv_usec;
92  current *= 10;
93 #endif
94  return adjustTime(typ, current);
95 }
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:38
GAUDI_API longlong System::ellapsedTime ( TimeType  typ = milliSec,
InfoType  fetch = Times,
long  pid = -1 
)

Elapsed time since start of process in milliseconds.

Ellapsed time since start of process in milliseconds.

Parameters
typIndicator or the unit the time will be returned.
timevalueTime value to be converted.
Returns
Requested value in the indicated units.

Definition at line 140 of file Timing.cpp.

140  {
141  KERNEL_USER_TIMES info;
143  getProcess()->query(pid, fetch, &info);
144  ellapsed = adjustTime(typ, ellapsed+UNIX_BASE_TIME-info.CreateTime);
145  return ellapsed;
146 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
tuple ellapsed
Definition: ana.py:140
GAUDI_API longlong currentTime(TimeType typ=milliSec)
Retrieve absolute system time.
Definition: Timing.cpp:80
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:38
long query(long pid, InfoType info, PROCESS_BASIC_INFORMATION *buffer)
GAUDI_API ImageHandle System::exeHandle ( )

Handle to the executable file running.

Definition at line 172 of file ModuleInfo.cpp.

172  {
173 #ifdef _WIN32
174  if ( processHandle() ) {
175  static HINSTANCE handle = 0;
176  DWORD cbNeeded;
177  if ( 0 == handle && _psApi.isValid() ) {
178  if ( _psApi.EnumProcessModules( processHandle(), &handle, sizeof(ModuleHandle), &cbNeeded) ) {
179  }
180  }
181  return handle;
182  }
183  return 0;
184 #elif defined(__linux) || defined(__APPLE__)
185  // This does NOT work!
186  static Dl_info infoBuf, *info = &infoBuf;
187  if ( 0 == info ) {
188  void* handle = ::dlopen(0, RTLD_LAZY);
189  //printf("Exe handle:%X\n", handle);
190  if ( 0 != handle ) {
191  void* func = ::dlsym(handle, "main");
192  //printf("Exe:Func handle:%X\n", func);
193  if ( 0 != func ) {
194  if ( 0 != ::dladdr(func, &infoBuf) ) {
195  //std::cout << "All OK" << std::endl;
196  info = &infoBuf;
197  }
198  }
199  }
200  }
201  return info;
202 #elif __hpux
203  // Don't know how to solve this .....
204  return 0;
205 #endif
206 }
GAUDI_API ProcessHandle processHandle()
Handle to running process.
Definition: ModuleInfo.cpp:127
GAUDI_API const std::string & System::exeName ( )

Name of the executable file running.

Definition at line 208 of file ModuleInfo.cpp.

208  {
209  static std::string module("");
210  if ( module.length() == 0 ) {
211  char name[PATH_MAX] = {"Unknown.module"};
212  name[0] = 0;
213 #ifdef _WIN32
214  if ( _psApi.isValid() && processHandle() ) {
215  _psApi.GetModuleFileNameExA( processHandle(), (HINSTANCE)exeHandle(), name,sizeof(name) );
216  module = name;
217  }
218 #elif defined(__linux) || defined(__APPLE__)
219  char cmd[512];
220  ::sprintf(cmd, "/proc/%d/exe", ::getpid());
221  module = "Unknown";
222  if (::readlink(cmd, name, sizeof(name)) >= 0)
223  module = name;
224 #elif __hpux
225  if (::realpath(((HMODULE*)exeHandle())->dsc.filename, name))
226  module = name;
227 #endif
228  }
229  return module;
230 }
GAUDI_API ProcessHandle processHandle()
Handle to running process.
Definition: ModuleInfo.cpp:127
GAUDI_API ImageHandle exeHandle()
Handle to the executable file running.
Definition: ModuleInfo.cpp:172
GAUDI_API 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.

82  {
83  PROCESS_BASIC_INFORMATION info;
84  if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) )
85  return info.ExitStatus;
86  return -2;
87 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API std::string System::getEnv ( const char *  var)

get a particular environment variable (returning "UNKNOWN" if not set)

get a particular env var, return "UNKNOWN" if not defined

Definition at line 618 of file System.cpp.

618  {
619  char* env;
620  if ( (env = getenv(var)) != 0 ) {
621  return env;
622  } else {
623  return "UNKNOWN";
624  }
625 }
GAUDI_API bool System::getEnv ( const char *  var,
std::string &  value 
)

get a particular environment variable, storing the value in the passed string if the variable is set.

get a particular env var, storing the value in the passed string (if set)

Returns true if the variable is set, false otherwise.

Definition at line 628 of file System.cpp.

628  {
629  char* env;
630  if ( (env = getenv(var)) != 0 ) {
631  value = env;
632  return true;
633  } else {
634  return false;
635  }
636 }
bool System::getEnv ( const std::string &  var,
std::string &  value 
)
inline

Definition at line 91 of file System.h.

91  {
92  return getEnv(var.c_str(), value);
93  }
GAUDI_API std::vector< std::string > getEnv()
get all environment variables
Definition: System.cpp:647
GAUDI_API std::vector< std::string > System::getEnv ( )

get all environment variables

get all defined environment vars

Definition at line 647 of file System.cpp.

647  {
648 #if defined(_WIN32)
649 # define environ _environ
650 #elif defined(__APPLE__)
651  static char **environ = *_NSGetEnviron();
652 #endif
653  std::vector<std::string> vars;
654  for (int i=0; environ[i] != 0; ++i) {
655  vars.push_back(environ[i]);
656  }
657  return vars;
658 }
list i
Definition: ana.py:128
GAUDI_API const std::string System::getErrorString ( unsigned long  error)

Retrieve error code as string for a given error.

Definition at line 260 of file System.cpp.

260  {
261  std::string errString = "";
262 #ifdef _WIN32
263  LPVOID lpMessageBuffer;
264  ::FormatMessage(
265  FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
266  NULL,
267  error,
268  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), //The user default language
269  (LPTSTR) &lpMessageBuffer,
270  0,
271  NULL );
272  errString = (const char*)lpMessageBuffer;
273  // Free the buffer allocated by the system
274  ::LocalFree( lpMessageBuffer );
275 #else
276  char *cerrString(0);
277  // Remember: for linux dl* routines must be handled differently!
278  if ( error == 0xAFFEDEAD ) {
279  cerrString = (char*)::dlerror();
280  if ( 0 == cerrString ) {
281  cerrString = ::strerror(error);
282  }
283  if ( 0 == cerrString ) {
284  cerrString = (char *)"Unknown error. No information found in strerror()!";
285  }
286  else {
287  errString = std::string(cerrString);
288  }
289  errno = 0;
290  }
291  else {
292  cerrString = ::strerror(error);
293  errString = std::string(cerrString);
294  }
295 #endif
296  return errString;
297 }
GAUDI_API unsigned long System::getLastError ( )

Get last system known error.

Retrieve last error code.

Definition at line 244 of file System.cpp.

244  {
245 #ifdef _WIN32
246  return ::GetLastError();
247 #else
248  // convert errno (int) to unsigned long
249  return static_cast<unsigned long>(static_cast<unsigned int>(errno));
250 #endif
251 }
GAUDI_API const std::string System::getLastErrorString ( )

Get last system error as string.

Retrieve last error code as string.

Definition at line 254 of file System.cpp.

254  {
255  const std::string errString = getErrorString(getLastError());
256  return errString;
257 }
GAUDI_API unsigned long getLastError()
Get last system known error.
Definition: System.cpp:244
GAUDI_API const std::string getErrorString(unsigned long error)
Retrieve error code as string for a given error.
Definition: System.cpp:260
GAUDI_API unsigned long System::getProcedureByName ( ImageHandle  handle,
const std::string &  name,
EntryPoint pFunction 
)

Get a specific function defined in the DLL.

Definition at line 189 of file System.cpp.

189  {
190 #ifdef _WIN32
191  *pFunction = (EntryPoint)::GetProcAddress((HINSTANCE)handle, name.data());
192  if ( 0 == *pFunction ) {
193  return System::getLastError();
194  }
195  return 1;
196 #elif defined(__linux)
197 #if __GNUC__ < 4
198  *pFunction = (EntryPoint)::dlsym(handle, name.c_str());
199 #else
200  *pFunction = FuncPtrCast<EntryPoint>(::dlsym(handle, name.c_str()));
201 #endif
202  if ( 0 == *pFunction ) {
203  errno = 0xAFFEDEAD;
204  // std::cout << "System::getProcedureByName>" << getLastErrorString() << std::endl;
205  return 0;
206  }
207  return 1;
208 #elif defined(__APPLE__)
209  *pFunction = (EntryPoint)::dlsym(handle, name.c_str());
210  if(!(*pFunction)) {
211  // Try with an underscore :
212  std::string sname = "_" + name;
213  *pFunction = (EntryPoint)::dlsym(handle, sname.c_str());
214  }
215  if ( 0 == *pFunction ) {
216  errno = 0xAFFEDEAD;
217  std::cout << "System::getProcedureByName>" << getLastErrorString() << std::endl;
218  //std::cout << "System::getProcedureByName> failure" << std::endl;
219  return 0;
220  }
221  return 1;
222 #elif __hpux
223  HMODULE* mod = (HMODULE*)handle;
224  if ( 0 != mod ) {
225  long ll1 = name.length();
226  for ( int i = 0; i < mod->numSym; i++ ) {
227  long ll2 = strlen(mod->sym[i].name);
228  if ( 0 != ::strncmp(mod->sym[i].name, name.c_str(), (ll1>ll2) ? ll1 : ll2)==0 ) {
229  *pFunction = (EntryPoint) mod->sym[i].value;
230  return 1;
231  }
232  }
233  }
234  return 0;
235 #endif
236 }
GAUDI_API unsigned long getLastError()
Get last system known error.
Definition: System.cpp:244
GAUDI_API const std::string getLastErrorString()
Get last system error as string.
Definition: System.cpp:254
unsigned long(* EntryPoint)(const unsigned long iid, void **ppvObject)
Definition of the "generic" DLL entry point function.
Definition: System.h:36
list i
Definition: ana.py:128
GAUDI_API unsigned long System::getProcedureByName ( ImageHandle  handle,
const std::string &  name,
Creator pFunction 
)

Get a specific function defined in the DLL.

Definition at line 239 of file System.cpp.

239  {
240  return getProcedureByName(handle, name, (EntryPoint*)pFunction);
241 }
GAUDI_API unsigned long getProcedureByName(ImageHandle handle, const std::string &name, EntryPoint *pFunction)
Get a specific function defined in the DLL.
Definition: System.cpp:189
unsigned long(* EntryPoint)(const unsigned long iid, void **ppvObject)
Definition of the "generic" DLL entry point function.
Definition: System.h:36
System::ProcessDescriptor * System::getProcess ( )

Retrieve Process structure.

Definition at line 384 of file ProcessDescriptor.cpp.

384  {
385  static ProcessDescriptor p;
386 #ifdef _WIN32
387  static bool first = true;
388  if ( first ) {
389  first = false;
390  void* mh = ::LoadLibrary("NTDll.dll");
391  if ( mh ) {
392  NtApi::NtQueryInformationProcess = (NtApi::__NtQueryInformationProcess)
393  ::GetProcAddress((HINSTANCE)mh, "NtQueryInformationProcess");
394  }
395  }
396 #endif
397  return &p;
398 }
GAUDI_API ProcessTime System::getProcessTime ( long  pid = -1)

Retrieve the process time data for a process.

Get the process time data for a process (by default the current) as a ProcessTime object.

Definition at line 179 of file Timing.cpp.

179  {
180  KERNEL_USER_TIMES info;
181  if (getProcess()->query(pid, Times, &info)) {
182  return ProcessTime(info.KernelTime,
183  info.UserTime,
184  currentTime(Native) - info.CreateTime);
185  }
186  return ProcessTime(); // return 0s in case of problems
187  }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API longlong currentTime(TimeType typ=milliSec)
Retrieve absolute system time.
Definition: Timing.cpp:80
GAUDI_API bool System::getStackLevel ( void *  addresses,
void *&  addr,
std::string &  fnc,
std::string &  lib 
)
GAUDI_API std::string System::homeDirectory ( )

Definition at line 60 of file Environment.cpp.

60  {
61  // Return the user's home directory.
62  std::string home_dir = "./";
63  // Try to replace the current value with the content of several
64  // environment variables
65  if ( ! (System::getEnv("home", home_dir) ||
66  System::getEnv("HOME", home_dir)) ) {
67  // for Windows NT HOME might be defined as either $(HOMESHARE)/$(HOMEPATH)
68  // or $(HOMEDRIVE)/$(HOMEPATH)
69  if ( System::getEnv("HOMESHARE", home_dir) ||
70  System::getEnv("HOMEDRIVE", home_dir) ) {
71  std::string path;
72  if (System::getEnv("HOMEPATH", path))
73  home_dir += path;
74  }
75  }
76  return home_dir;
77 }
list path
Definition: __init__.py:15
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:618
GAUDI_API const std::string & System::hostName ( )

Host name.

Definition at line 428 of file System.cpp.

428  {
429  static std::string host = "";
430  if ( host == "" ) {
431  char buffer[512];
432  memset(buffer,0,sizeof(buffer));
433 #ifdef _WIN32
434  unsigned long len = sizeof(buffer);
435  ::GetComputerName(buffer, &len);
436 #else
437  ::gethostname(buffer, sizeof(buffer));
438 #endif
439  host = buffer;
440  }
441  return host;
442 }
GAUDI_API int System::instructionsetLevel ( )

Instruction Set "Level".

Definition at line 502 of file System.cpp.

502  {
503  return instrset_detect();
504 }
int instrset_detect(void)
GAUDI_API bool System::isEnvSet ( const char *  var)

Check if an environment variable is set or not.

Definition at line 638 of file System.cpp.

638  {
639  return getenv(var) != 0;
640 }
GAUDI_API longlong System::kernelTime ( TimeType  typ = milliSec,
InfoType  fetch = Times,
long  pid = -1 
)

CPU kernel mode time of process in milliseconds.

CPU kernel time of process in milliseconds.

Parameters
typIndicator or the unit the time will be returned.
fetchIndicator of the information to be fetched. If Fetch_None, the information will not be updated.
pidProcess ID of which the information will be returned
Returns
Requested value in the indicated units.

Definition at line 149 of file Timing.cpp.

149  {
150  KERNEL_USER_TIMES info;
151  longlong kerneltime = 0;
152  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) {
153  kerneltime = adjustTime(typ, info.KernelTime );
154  }
155  return kerneltime;
156 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:38
GAUDI_API const std::vector< std::string > System::linkedModules ( )

Vector of names of linked modules.

Definition at line 232 of file ModuleInfo.cpp.

232  {
233  if ( s_linkedModules.size() == 0 ) {
234 #ifdef _WIN32
235  char name[255]; // Maximum file name length on NT 4.0
236  DWORD cbNeeded;
237  HINSTANCE handle[1024];
238  if ( _psApi.isValid() ) {
239  if ( _psApi.EnumProcessModules(processHandle(),handle,sizeof(handle),&cbNeeded) ) {
240  for (size_t i = 0; i < cbNeeded/sizeof(HANDLE); i++ ) {
241  if ( 0 < _psApi.GetModuleFileNameExA( processHandle(), handle[i], name, sizeof(name)) ) {
242  s_linkedModules.push_back(name);
243  }
244  }
245  }
246  }
247 #elif defined(__linux) || defined(__APPLE__)
248  char ff[512], cmd[1024], fname[1024], buf1[64], buf2[64], buf3[64], buf4[64];
249  ::sprintf(ff, "/proc/%d/maps", ::getpid());
250  FILE* maps = ::fopen(ff, "r");
251  while( ::fgets(cmd, sizeof(cmd), maps) ) {
252  int len;
253  sscanf(cmd, "%s %s %s %s %d %s", buf1, buf2, buf3, buf4, &len, fname);
254  if ( len > 0 && strncmp(buf2,"r-xp",strlen("r-xp")) == 0 ) {
255  s_linkedModules.push_back(fname);
256  }
257  }
258  ::fclose(maps);
259 #endif
260  }
261  return s_linkedModules;
262 }
GAUDI_API ProcessHandle processHandle()
Handle to running process.
Definition: ModuleInfo.cpp:127
list i
Definition: ana.py:128
GAUDI_API unsigned long System::loadDynamicLib ( const std::string &  name,
ImageHandle handle 
)

Load dynamic link library.

Definition at line 124 of file System.cpp.

124  {
125  unsigned long res;
126  // if name is empty, just load it
127  if (name.length() == 0) {
128  res = loadWithoutEnvironment(name, handle);
129  } else {
130  // If the name is a logical name (environment variable), the try
131  // to load the corresponding library from there.
132  std::string imgName;
133  if ( getEnv(name, imgName) ) {
134  res = loadWithoutEnvironment(imgName, handle);
135  } else {
136  // build the dll name
137  std::string dllName = name;
138  // if the lib name contains '/' we can assume is the path to a file
139  // (relative or absolute), otherwise it might be a logical library name
140  // (i.e. without 'lib' and '.so')
141  if (dllName.find('/') == std::string::npos) {
142 #if defined(__linux) || defined(__APPLE__)
143  if (dllName.substr(0, 3) != "lib")
144  dllName = "lib" + dllName;
145 #endif
146  if (dllName.find(SHLIB_SUFFIX) == std::string::npos)
147  dllName += SHLIB_SUFFIX;
148  }
149  // try to locate the dll using the standard PATH
150  res = loadWithoutEnvironment(dllName, handle);
151  }
152  if ( res != 1 ) {
153 #if defined(__linux) || defined(__APPLE__)
154  errno = 0xAFFEDEAD;
155 #endif
156  // std::cout << "System::loadDynamicLib>" << getLastErrorString() << std::endl;
157  }
158  }
159  return res;
160 }
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:618
GAUDI_API const std::string & System::machineType ( )

Machine type.

Definition at line 483 of file System.cpp.

483  {
484  static std::string mach = "";
485 #ifdef _WIN32
486  SYSTEM_INFO ut;
487  ::GetSystemInfo(&ut);
488  std::ostringstream arch;
489  arch << ut.wProcessorArchitecture;
490  mach = arch.str();
491 #else
492  struct utsname ut;
493  if (uname(&ut) == 0) {
494  mach = ut.machine;
495  } else {
496  mach = "UNKNOWN";
497  }
498 #endif
499  return mach;
500 }
GAUDI_API 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.

181  {
182  VM_COUNTERS info;
183  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
184  return adjustMemory(unit, info.WorkingSetSize);
185  return -2;
186 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:35
GAUDI_API 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.

189  {
190  VM_COUNTERS info;
191  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
192  return adjustMemory(unit, info.PeakWorkingSetSize);
193  return -2;
194 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:35
GAUDI_API 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.

205  {
206  QUOTA_LIMITS quota;
207  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )
208  return adjustMemory(unit, quota.MaximumWorkingSetSize);
209  return 0;
210 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:35
GAUDI_API 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.

197  {
198  QUOTA_LIMITS quota;
199  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )
200  return adjustMemory(unit, quota.MinimumWorkingSetSize);
201  return 0;
202 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:35
GAUDI_API ImageHandle System::moduleHandle ( )

Handle to currently executed module.

Definition at line 141 of file ModuleInfo.cpp.

141  {
142  if ( 0 == ModuleHandle ) {
143  if ( processHandle() ) {
144 #ifdef _WIN32
145  static HINSTANCE handle = 0;
146  DWORD cbNeeded;
147  if ( 0 == handle && _psApi.isValid() ) {
148  if ( _psApi.EnumProcessModules( processHandle(), &handle, sizeof(ModuleHandle), &cbNeeded) ) {
149  }
150  }
151  return handle;
152 #elif defined(__linux) || defined(__APPLE__)
153  static Dl_info info;
154  if ( 0 !=
155  ::dladdr(
156 #if __GNUC__ < 4
157  (void*)System::moduleHandle
158 #else
159  FuncPtrCast<void*>(System::moduleHandle)
160 #endif
161  , &info) ) {
162  return &info;
163  }
164 #elif __hpux
165  return 0; // Don't know how to solve this .....
166 #endif
167  }
168  }
169  return ModuleHandle;
170 }
GAUDI_API ImageHandle moduleHandle()
Handle to currently executed module.
Definition: ModuleInfo.cpp:141
GAUDI_API ProcessHandle processHandle()
Handle to running process.
Definition: ModuleInfo.cpp:127
GAUDI_API const std::string & System::moduleName ( )

Get the name of the (executable/DLL) file without file-type.

Retrieve base name of module.

Definition at line 55 of file ModuleInfo.cpp.

55  {
56  static std::string module("");
57  if ( module == "" ) {
58  if ( processHandle() && moduleHandle() ) {
59 #ifdef _WIN32
60  char moduleName[256] = {"Unknown.module"};
61  moduleName[0] = 0;
62  if ( _psApi.isValid() ) {
63  _psApi.GetModuleBaseNameA( processHandle(), (HINSTANCE)moduleHandle(), moduleName, sizeof(moduleName) );
64  }
65  std::string mod = moduleName;
66 #elif defined(__linux) || defined(__APPLE__)
67  std::string mod = ::basename((char*)((Dl_info*)moduleHandle())->dli_fname);
68 #elif __hpux
69  std::string mod = ::basename(((HMODULE*)moduleHandle())->dsc.filename);
70 #endif
71  module = mod.substr(0, mod.rfind('.'));
72  }
73  }
74  return module;
75 }
GAUDI_API ImageHandle moduleHandle()
Handle to currently executed module.
Definition: ModuleInfo.cpp:141
GAUDI_API const std::string & moduleName()
Get the name of the (executable/DLL) file without file-type.
Definition: ModuleInfo.cpp:55
GAUDI_API ProcessHandle processHandle()
Handle to running process.
Definition: ModuleInfo.cpp:127
def basename(url)
GAUDI_API const std::string & System::moduleNameFull ( )

Get the full name of the (executable/DLL) file.

Retrieve full name of module.

Definition at line 78 of file ModuleInfo.cpp.

78  {
79  static std::string module("");
80  if ( module == "" ) {
81  if ( processHandle() && moduleHandle() ) {
82  char name[PATH_MAX] = {"Unknown.module"};
83  name[0] = 0;
84 #ifdef _WIN32
85  if ( _psApi.isValid() ) {
86  _psApi.GetModuleFileNameExA( processHandle(), (HINSTANCE)moduleHandle(), name,sizeof(name) );
87  module = name;
88  }
89 #else
90  const char *path =
91 # if defined(__linux) || defined(__APPLE__)
92  ((Dl_info*)moduleHandle())->dli_fname;
93 # elif __hpux
94  ((HMODULE*)moduleHandle())->dsc.filename;
95 # endif
96  if (::realpath(path, name))
97  module = name;
98 #endif
99  }
100  }
101  return module;
102 }
GAUDI_API ImageHandle moduleHandle()
Handle to currently executed module.
Definition: ModuleInfo.cpp:141
if(ep)
Definition: Bootstrap.cpp:337
list path
Definition: __init__.py:15
GAUDI_API ProcessHandle processHandle()
Handle to running process.
Definition: ModuleInfo.cpp:127
GAUDI_API ModuleType System::moduleType ( )

Get type of the module.

Definition at line 105 of file ModuleInfo.cpp.

105  {
106  static ModuleType type = UNKNOWN;
107  if ( type == UNKNOWN ) {
108  const std::string& module = moduleNameFull();
109  int loc = module.rfind('.')+1;
110  if ( loc == 0 )
111  type = EXECUTABLE;
112  else if ( module[loc] == 'e' || module[loc] == 'E' )
113  type = EXECUTABLE;
114 #ifdef _WIN32
115  else if ( module[loc] == 'd' || module[loc] == 'D' )
116 #else
117  else if ( module[loc] == 's' && module[loc+1] == 'o' )
118 #endif
119  type = SHAREDLIB;
120  else
121  type = UNKNOWN;
122  }
123  return type;
124 }
GAUDI_API const std::string & moduleNameFull()
Get the full name of the (executable/DLL) file.
Definition: ModuleInfo.cpp:78
ModuleType
Definition: ModuleInfo.h:28
string type
Definition: gaudirun.py:151
GAUDI_API 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.

106  {
107  VM_COUNTERS info;
108  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
109  return adjustMemory(unit, info.QuotaNonPagedPoolUsage);
110  return -2;
111 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:35
GAUDI_API 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.

114  {
115  POOLED_USAGE_AND_LIMITS quota;
116  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )
117  return adjustMemory(unit, quota.NonPagedPoolLimit);
118  return 0;
119 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:35
GAUDI_API 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.

98  {
99  VM_COUNTERS info;
100  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
101  return adjustMemory(unit, info.QuotaPeakNonPagedPoolUsage);
102  return -2;
103 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:35
GAUDI_API long System::numCmdLineArgs ( )

Number of arguments passed to the commandline.

Definition at line 531 of file System.cpp.

531  {
532  return cmdLineArgs().size();
533 }
GAUDI_API const std::vector< std::string > cmdLineArgs()
Command line arguments including executable name as arg[0] as vector of strings.
Definition: System.cpp:541
GAUDI_API 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.

146  {
147  VM_COUNTERS info;
148  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
149  return info.PageFaultCount;
150  return -2;
151 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API const std::string & System::osName ( )

OS name.

Definition at line 445 of file System.cpp.

445  {
446  static std::string osname = "";
447 #ifdef _WIN32
448  osname = "Windows";
449 #else
450  struct utsname ut;
451  if (uname(&ut) == 0) {
452  osname = ut.sysname;
453  } else {
454  osname = "UNKNOWN";
455  }
456 #endif
457  return osname;
458 }
GAUDI_API const std::string & System::osVersion ( )

OS version.

Definition at line 462 of file System.cpp.

462  {
463  static std::string osver = "";
464 #ifdef _WIN32
465  OSVERSIONINFO ut;
466  ut.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
467  ::GetVersionEx(&ut);
468  std::ostringstream ver;
469  ver << ut.dwMajorVersion << '.' << ut.dwMinorVersion;
470  osver = ver.str();
471 #else
472  struct utsname ut;
473  if (uname(&ut) == 0) {
474  osver = ut.release;
475  } else {
476  osver = "UNKNOWN";
477  }
478 #endif
479  return osver;
480 }
GAUDI_API 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.

122  {
123  VM_COUNTERS info;
124  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
125  return adjustMemory(unit, info.QuotaPagedPoolUsage);
126  return -2;
127 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:35
GAUDI_API 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.

138  {
139  POOLED_USAGE_AND_LIMITS quota;
140  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )
141  return adjustMemory(unit, quota.PagedPoolLimit);
142  return 0;
143 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:35
GAUDI_API 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.

130  {
131  VM_COUNTERS info;
132  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
133  return adjustMemory(unit, info.QuotaPeakPagedPoolUsage);
134  return -2;
135 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:35
GAUDI_API 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.

154  {
155  VM_COUNTERS info;
156  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
157  return adjustMemory(unit, info.PagefileUsage);
158  return -2;
159 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:35
GAUDI_API 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.

170  {
171  POOLED_USAGE_AND_LIMITS quota;
172  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) ) {
173  if ( long(quota.PagefileLimit) < 0 )
174  return -1;//LONG_MAX;
175  return adjustMemory(unit, quota.PagefileLimit);
176  }
177  return -2;
178 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:35
GAUDI_API 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.

162  {
163  VM_COUNTERS info;
164  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
165  return adjustMemory(unit, info.PeakPagefileUsage);
166  return -2;
167 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:35
GAUDI_API long System::parentID ( InfoType  fetch = ProcessBasics,
long  pid = -1 
)

Basic Process Information: Parent's process ID.

Definition at line 66 of file Memory.cpp.

66  {
67  PROCESS_BASIC_INFORMATION info;
68  if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) )
69  return info.InheritedFromUniqueProcessId;
70  return 0;
71 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API std::string System::PathResolverFindDataFile ( const std::string &  logical_file_name)

Definition at line 228 of file PathResolver.cpp.

229 {
230  return PathResolver::find_file (logical_file_name, "DATAPATH");
231 }
GAUDI_API std::string System::PathResolverFindXMLFile ( const std::string &  logical_file_name)

Definition at line 223 of file PathResolver.cpp.

224 {
225  return PathResolver::find_file (logical_file_name, "XMLPATH");
226 }
GAUDI_API long System::priorityBoost ( InfoType  fetch = PriorityBoost,
long  pid = -1 
)

Basic Process Information: priority boost.

Definition at line 90 of file Memory.cpp.

90  {
91  long info;
92  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
93  return info;
94  return -2;
95 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API ProcessHandle System::processHandle ( )

Handle to running process.

Retrieve processhandle.

Definition at line 127 of file ModuleInfo.cpp.

127  {
128  static long pid = ::getpid();
129 #ifdef _WIN32
130  static HANDLE hP = ::OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,FALSE,pid);
131 #else
132  static void* hP = (void*)pid;
133 #endif
134  return hP;
135 }
GAUDI_API long System::procID ( )

Basic Process Information: Process ID.

Definition at line 60 of file Memory.cpp.

60  {
61  static long s_pid = ::getpid();
62  return s_pid;
63 }
GAUDI_API 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.

Parameters
typIndicator or the unit the time will be returned.
fetchIndicator of the information to be fetched. If Fetch_None, the information will not be updated.
pidProcess ID of which the information will be returned
Returns
Requested value in the indicated units.

Definition at line 125 of file Timing.cpp.

125  {
126  longlong left = 0;
127  QUOTA_LIMITS quota;
128  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) ) {
129  if ( left == -1 ) {
130  //left = _I64_MAX;
131  }
132  else {
133  left = adjustTime(typ, quota.TimeLimit);
134  }
135  }
136  return left;
137 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:38
GAUDI_API StatusCode System::resolveEnv ( const std::string &  var,
std::string &  res,
int  recusions = 124 
)

Definition at line 51 of file Environment.cpp.

51  {
52  std::string source = var;
53  res = i_resolve(source, recursions);
54  if ( res.find("${") == std::string::npos ) {
55  return StatusCode::SUCCESS;
56  }
57  return StatusCode::FAILURE;
58 }
GAUDI_API 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.

Returns
0 if successful, -1 if not

Definition at line 756 of file System.cpp.

757 {
758 #ifndef WIN32
759  // UNIX version
760  return value.empty() ?
761  // remove if set to nothing (and return success)
762  ::unsetenv(name.c_str()) , 0 :
763  // set the value
764  ::setenv(name.c_str(),value.c_str(), overwrite);
765 #else
766  // Windows version
767  if ( value.empty() ) {
768  // equivalent to unsetenv
769  return ::_putenv((name+"=").c_str());
770  }
771  else {
772  if ( !getenv(name.c_str()) || overwrite ) {
773  // set if not yet present or overwrite is set (force)
774  return ::_putenv((name+"="+value).c_str());
775  }
776  }
777  return 0; // if we get here, we are trying to set a variable already set, but
778  // not to overwrite.
779  // It is considered a success on Linux (man P setenv)
780 #endif
781 
782 }
GAUDI_API void System::setModuleHandle ( ImageHandle  handle)

Attach module handle.

Definition at line 137 of file ModuleInfo.cpp.

137  {
138  ModuleHandle = handle;
139 }
GAUDI_API longlong System::systemStart ( TimeType  typ = Sec)

Maximum processing time left for this process.

Units of time since system startup and begin of epoche.

Parameters
typIndicator or the unit the time will be returned.
Returns
Requested value in the indicated units.

Definition at line 98 of file Timing.cpp.

98  {
99  static longlong sys_start = 0;
100  if ( 0 == sys_start ) {
102  longlong t = tickCount();
103  sys_start = 10*c - t;
104  }
105  return adjustTime(typ, sys_start);
106 }
tuple c
Definition: gaudirun.py:390
GAUDI_API longlong currentTime(TimeType typ=milliSec)
Retrieve absolute system time.
Definition: Timing.cpp:80
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:38
GAUDI_API longlong tickCount()
Retrieve the number of ticks since system startup.
Definition: Timing.cpp:66
GAUDI_API std::string System::tempDirectory ( )

Definition at line 79 of file Environment.cpp.

79  {
80  // Return a user configured or systemwide directory to create
81  // temporary files in.
82  std::string dir;
83  if ( System::getEnv("TEMP", dir) ||
84  System::getEnv("TEMPDIR", dir) ||
85  System::getEnv("TEMP_DIR", dir) ||
86  System::getEnv("TMP", dir) ||
87  System::getEnv("TMPDIR", dir) ||
88  System::getEnv("TMP_DIR", dir)
89  )
90  return dir;
91  else
92  return homeDirectory();
93 }
GAUDI_API std::string homeDirectory()
Definition: Environment.cpp:60
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:618
ThreadHandle System::threadSelf ( )
inline

thread handle "accessor"

Definition at line 113 of file System.h.

113 { return (void*)0; }
GAUDI_API longlong System::tickCount ( )

Retrieve the number of ticks since system startup.

Returns
Requested value in the indicated units.

Definition at line 66 of file Timing.cpp.

66  {
67  longlong count = 10000;
68 #ifdef _WIN32
69  count *= ::GetTickCount(); // Number of milliSec since system startup
70 #else
71  struct tms buf;
72  count *= 10*times(&buf);
73 #endif
74  return count;
75 }
GAUDI_API const std::string System::typeinfoName ( const std::type_info &  )

Get platform independent information about the class type.

Definition at line 299 of file System.cpp.

299  {
300  return typeinfoName(tinfo.name());
301 }
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:299
GAUDI_API const std::string System::typeinfoName ( const char *  )

Definition at line 303 of file System.cpp.

303  {
304  std::string result;
305 #ifdef _WIN32
306  long off = 0;
307  if ( ::strncmp(class_name, "class ", 6) == 0 ) {
308  // The returned name is prefixed with "class "
309  off = 6;
310  }
311  if ( ::strncmp(class_name, "struct ", 7) == 0 ) {
312  // The returned name is prefixed with "struct "
313  off = 7;
314  }
315  if ( off > 0 ) {
316  std::string tmp = class_name + off;
317  long loc = 0;
318  while( (loc = tmp.find("class ")) > 0 ) {
319  tmp.erase(loc, 6);
320  }
321  loc = 0;
322  while( (loc = tmp.find("struct ")) > 0 ) {
323  tmp.erase(loc, 7);
324  }
325  result = tmp;
326  }
327  else {
328  result = class_name;
329  }
330  // Change any " *" to "*"
331  while ( (off=result.find(" *")) != std::string::npos ) {
332  result.replace(off, 2, "*");
333  }
334  // Change any " &" to "&"
335  while ( (off=result.find(" &")) != std::string::npos ) {
336  result.replace(off, 2, "&");
337  }
338 
339 #elif defined(__linux) || defined(__APPLE__)
340  if ( ::strlen(class_name) == 1 ) {
341  // See http://www.realitydiluted.com/mirrors/reality.sgi.com/dehnert_engr/cxx/abi.pdf
342  // for details
343  switch(class_name[0]) {
344  case 'v':
345  result = "void";
346  break;
347  case 'w':
348  result = "wchar_t";
349  break;
350  case 'b':
351  result = "bool";
352  break;
353  case 'c':
354  result = "char";
355  break;
356  case 'a':
357  result = "signed char";
358  break;
359  case 'h':
360  result = "unsigned char";
361  break;
362  case 's':
363  result = "short";
364  break;
365  case 't':
366  result = "unsigned short";
367  break;
368  case 'i':
369  result = "int";
370  break;
371  case 'j':
372  result = "unsigned int";
373  break;
374  case 'l':
375  result = "long";
376  break;
377  case 'm':
378  result = "unsigned long";
379  break;
380  case 'x':
381  result = "long long";
382  break;
383  case 'y':
384  result = "unsigned long long";
385  break;
386  case 'n':
387  result = "__int128";
388  break;
389  case 'o':
390  result = "unsigned __int128";
391  break;
392  case 'f':
393  result = "float";
394  break;
395  case 'd':
396  result = "double";
397  break;
398  case 'e':
399  result = "long double";
400  break;
401  case 'g':
402  result = "__float128";
403  break;
404  case 'z':
405  result = "ellipsis";
406  break;
407  }
408  }
409  else {
410  int status;
411  char* realname;
412  realname = abi::__cxa_demangle(class_name, 0, 0, &status);
413  if (realname == 0) return class_name;
414  result = realname;
415  free(realname);
417  std::string::size_type pos = result.find(", ");
418  while( std::string::npos != pos ) {
419  result.replace( pos , 2 , "," ) ;
420  pos = result.find(", ");
421  }
422  }
423 #endif
424  return result;
425 }
GAUDI_API unsigned long System::unloadDynamicLib ( ImageHandle  handle)

unload dynamic link library

Definition at line 163 of file System.cpp.

163  {
164 #ifdef _WIN32
165  if ( !::FreeLibrary((HINSTANCE)handle) ) {
166 #elif defined(__linux) || defined(__APPLE__)
167  ::dlclose( handle );
168  if ( 0 ) {
169 #elif __hpux
170  // On HP we have to run finalization ourselves.....
171  Creator pFinalize = 0;
172  if ( getProcedureByName(handle, "_fini", &pFinalize) ) {
173  pFinalize();
174  }
175  HMODULE* mod = (HMODULE*)handle;
176  if ( 0 == ::shl_unload( mod->dsc.handle ) ) {
177  delete mod;
178  }
179  else {
180 #else
181  if (false){
182 #endif
183  return getLastError();
184  }
185  return 1;
186 }
GAUDI_API unsigned long getProcedureByName(ImageHandle handle, const std::string &name, EntryPoint *pFunction)
Get a specific function defined in the DLL.
Definition: System.cpp:189
GAUDI_API unsigned long getLastError()
Get last system known error.
Definition: System.cpp:244
void *(* Creator)()
Definition of the "generic" DLL entry point function.
Definition: System.h:38
GAUDI_API longlong System::upTime ( TimeType  typ = Hour)

Maximum processing time left for this process.

Units of time since system startup in requested units.

Parameters
typIndicator or the unit the time will be returned.
Returns
Requested value in the indicated units.

Definition at line 109 of file Timing.cpp.

109  {
110  static longlong sys_start = 10*systemStart(microSec);
111  return adjustTime(typ, 10*currentTime(microSec)-sys_start);
112 }
GAUDI_API longlong currentTime(TimeType typ=milliSec)
Retrieve absolute system time.
Definition: Timing.cpp:80
GAUDI_API longlong systemStart(TimeType typ=Sec)
Maximum processing time left for this process.
Definition: Timing.cpp:98
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:38
GAUDI_API longlong System::userTime ( TimeType  typ = milliSec,
InfoType  fetch = Times,
long  pid = -1 
)

CPU user mode time of process in milliseconds.

CPU kernel time of process in milliseconds.

Parameters
typIndicator or the unit the time will be returned.
fetchIndicator of the information to be fetched. If Fetch_None, the information will not be updated.
pidProcess ID of which the information will be returned
Returns
Requested value in the indicated units.

Definition at line 159 of file Timing.cpp.

159  {
160  longlong usertime = 0;
161  KERNEL_USER_TIMES info;
162  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) {
163  usertime = adjustTime(typ, info.UserTime );
164  }
165  return usertime;
166 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:38
GAUDI_API 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.

213  {
214  VM_COUNTERS info;
215  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
216  return adjustMemory(unit, info.VirtualSize);
217  return -2;
218 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:35
GAUDI_API 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.

229  {
230  QUOTA_LIMITS quota;
231  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) ) {
232  if ( long(quota.PagefileLimit) == -1 )
233  return -1;//LONG_MAX;
234  return adjustMemory(unit, quota.PagefileLimit);
235  }
236  return 0;
237 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:35
GAUDI_API 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.

221  {
222  VM_COUNTERS info;
223  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
224  return adjustMemory(unit, info.PeakVirtualSize);
225  return -2;
226 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:35