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 37 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 35 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 17 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 110 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 56 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 56 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 513 of file System.cpp.

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

34  {
35  if ( value != -1 ) {
36  switch ( unit ) {
37  case Byte: break;
38  case kByte: value = value/1024; break;
39  case MByte: value = (value/1024)/1024; break;
40  case GByte: value = ((value/1024)/1024)/1024; break;
41  case TByte: value = (((value/1024)/1024)/1024)/1024; break;
42  case PByte: value = ((((value/1024)/1024)/1024)/1024)/1024; break;
43  case EByte: value = (((((value/1024)/1024)/1024)/1024)/1024)/1024; break;
44  default: value = -1; break;
45  }
46  }
47  return value;
48 }
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 37 of file Timing.cpp.

37  {
38  if ( t != -1 ) {
39 #ifndef _WIN32
40  // t /= CLK_TCK ; // needs division by clock tick unit
45 
47 #endif
48  switch( typ ) {
49  case Year : return adjustTime<Year >(t);
50  case Month : return adjustTime<Month >(t);
51  case Day : return adjustTime<Day >(t);
52  case Hour : return adjustTime<Hour >(t);
53  case Min : return adjustTime<Min >(t);
54  case Sec : return adjustTime<Sec >(t);
55  case milliSec: return adjustTime<milliSec>(t);
56  case microSec: return adjustTime<microSec>(t);
57  case nanoSec : return adjustTime<nanoSec >(t);
58  case Native : return adjustTime<Native >(t);
59  }
60  }
61  return t;
62 }
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 73 of file Memory.cpp.

73  {
74  PROCESS_BASIC_INFORMATION info;
75  if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) )
76  return info.AffinityMask;
77  return 0;
78 }
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 537 of file System.cpp.

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

604  {
606  if( s_argvChars.empty() ) { cmdLineArgs(); }
607  // We rely here on the fact that a vector's allocation table is contiguous
609  return (char**)&s_argvChars[0];
610 }
GAUDI_API const std::vector< std::string > cmdLineArgs()
Command line arguments including executable name as arg[0] as vector of strings.
Definition: System.cpp:542
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 683 of file System.cpp.

684 {
685  try {
686  // Always hide the first two levels of the stack trace (that's us)
687  const int totalOffset = offset + 2;
688  const int totalDepth = depth + totalOffset;
689 
690  std::string fnc, lib;
691 
692  std::vector<void*> addresses( totalDepth, nullptr );
693  int count = System::backTrace(addresses.data(),totalDepth);
694  for (int i = totalOffset; i < count; ++i) {
695  void *addr = nullptr;
696 
697  if (System::getStackLevel(addresses[i],addr,fnc,lib)) {
698  std::ostringstream ost;
699  ost << "#" << std::setw(3) << std::setiosflags( std::ios::left ) << i-totalOffset+1;
700  ost << std::hex << addr << std::dec << " " << fnc << " [" << lib << "]" << std::endl;
701  btrace += ost.str();
702  }
703  }
704  return true;
705  } catch ( const std::bad_alloc& e ) {
706  return false;
707  }
708 }
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 51 of file Memory.cpp.

51  {
52  PROCESS_BASIC_INFORMATION info;
53  if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) )
54  return info.BasePriority;
55  return 0;
56 }
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:26
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 542 of file System.cpp.

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

168  {
169  longlong cputime = 0;
170  KERNEL_USER_TIMES info;
171  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) {
172  cputime = adjustTime(typ, info.KernelTime+info.UserTime );
173  }
174  return cputime;
175 }
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:37
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 114 of file Timing.cpp.

114  {
115  longlong created = 0;
116  KERNEL_USER_TIMES info;
117  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) {
118  created = adjustTime(typ, info.CreateTime-UNIX_BASE_TIME);
119  }
120  return created;
121 }
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:37
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 79 of file Timing.cpp.

79  {
80  longlong current = 0;
81 #ifdef _WIN32
82  ::GetSystemTimeAsFileTime((FILETIME*)&current);
83  current -= UNIX_BASE_TIME;
84 #else
85  struct timeval tv;
86  struct timezone tz;
87  ::gettimeofday(&tv, &tz);
88  current = tv.tv_sec;
89  current *= 1000000;
90  current += tv.tv_usec;
91  current *= 10;
92 #endif
93  return adjustTime(typ, current);
94 }
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:37
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 139 of file Timing.cpp.

139  {
140  KERNEL_USER_TIMES info;
142  getProcess()->query(pid, fetch, &info);
143  ellapsed = adjustTime(typ, ellapsed+UNIX_BASE_TIME-info.CreateTime);
144  return ellapsed;
145 }
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:79
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:37
long query(long pid, InfoType info, PROCESS_BASIC_INFORMATION *buffer)
GAUDI_API ImageHandle System::exeHandle ( )

Handle to the executable file running.

Definition at line 171 of file ModuleInfo.cpp.

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

Name of the executable file running.

Definition at line 207 of file ModuleInfo.cpp.

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

81  {
82  PROCESS_BASIC_INFORMATION info;
83  if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) )
84  return info.ExitStatus;
85  return -2;
86 }
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 619 of file System.cpp.

619  {
620  char* env;
621  if ( (env = getenv(var)) != 0 ) {
622  return env;
623  } else {
624  return "UNKNOWN";
625  }
626 }
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 629 of file System.cpp.

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

Definition at line 90 of file System.h.

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

get all environment variables

get all defined environment vars

Definition at line 648 of file System.cpp.

648  {
649 #if defined(_WIN32)
650 # define environ _environ
651 #elif defined(__APPLE__)
652  static char **environ = *_NSGetEnviron();
653 #endif
654  std::vector<std::string> vars;
655  for (int i=0; environ[i] != 0; ++i) {
656  vars.push_back(environ[i]);
657  }
658  return vars;
659 }
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:35
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:35
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 178 of file Timing.cpp.

178  {
179  KERNEL_USER_TIMES info;
180  if (getProcess()->query(pid, Times, &info)) {
181  return ProcessTime(info.KernelTime,
182  info.UserTime,
183  currentTime(Native) - info.CreateTime);
184  }
185  return ProcessTime(); // return 0s in case of problems
186  }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API longlong currentTime(TimeType typ=milliSec)
Retrieve absolute system time.
Definition: Timing.cpp:79
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:619
GAUDI_API const std::string & System::hostName ( )

Host name.

Definition at line 440 of file System.cpp.

440  {
441  static const std::string host = init_hostName();
442  return host;
443 }
GAUDI_API int System::instructionsetLevel ( )

Instruction Set "Level".

Definition at line 503 of file System.cpp.

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

Check if an environment variable is set or not.

Definition at line 639 of file System.cpp.

639  {
640  return getenv(var) != 0;
641 }
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 148 of file Timing.cpp.

148  {
149  KERNEL_USER_TIMES info;
150  longlong kerneltime = 0;
151  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) {
152  kerneltime = adjustTime(typ, info.KernelTime );
153  }
154  return kerneltime;
155 }
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:37
GAUDI_API const std::vector< std::string > System::linkedModules ( )

Vector of names of linked modules.

Definition at line 231 of file ModuleInfo.cpp.

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

Machine type.

Definition at line 484 of file System.cpp.

484  {
485  static std::string mach = "";
486 #ifdef _WIN32
487  SYSTEM_INFO ut;
488  ::GetSystemInfo(&ut);
489  std::ostringstream arch;
490  arch << ut.wProcessorArchitecture;
491  mach = arch.str();
492 #else
493  struct utsname ut;
494  if (uname(&ut) == 0) {
495  mach = ut.machine;
496  } else {
497  mach = "UNKNOWN";
498  }
499 #endif
500  return mach;
501 }
GAUDI_API long System::mappedMemory ( MemoryUnit  unit = kByte,
InfoType  fetch = Memory,
long  pid = -1 
)

Basic Process Information: priority boost.

Definition at line 180 of file Memory.cpp.

180  {
181  VM_COUNTERS info;
182  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
183  return adjustMemory(unit, info.WorkingSetSize);
184  return -2;
185 }
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:34
GAUDI_API long System::mappedMemoryPeak ( MemoryUnit  unit = kByte,
InfoType  fetch = Memory,
long  pid = -1 
)

Basic Process Information: priority boost.

Definition at line 188 of file Memory.cpp.

188  {
189  VM_COUNTERS info;
190  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
191  return adjustMemory(unit, info.PeakWorkingSetSize);
192  return -2;
193 }
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:34
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 204 of file Memory.cpp.

204  {
205  QUOTA_LIMITS quota;
206  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )
207  return adjustMemory(unit, quota.MaximumWorkingSetSize);
208  return 0;
209 }
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:34
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 196 of file Memory.cpp.

196  {
197  QUOTA_LIMITS quota;
198  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )
199  return adjustMemory(unit, quota.MinimumWorkingSetSize);
200  return 0;
201 }
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:34
GAUDI_API ImageHandle System::moduleHandle ( )

Handle to currently executed module.

Definition at line 140 of file ModuleInfo.cpp.

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

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

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

Get type of the module.

Definition at line 104 of file ModuleInfo.cpp.

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

105  {
106  VM_COUNTERS info;
107  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
108  return adjustMemory(unit, info.QuotaNonPagedPoolUsage);
109  return -2;
110 }
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:34
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 113 of file Memory.cpp.

113  {
114  POOLED_USAGE_AND_LIMITS quota;
115  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )
116  return adjustMemory(unit, quota.NonPagedPoolLimit);
117  return 0;
118 }
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:34
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 97 of file Memory.cpp.

97  {
98  VM_COUNTERS info;
99  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
100  return adjustMemory(unit, info.QuotaPeakNonPagedPoolUsage);
101  return -2;
102 }
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:34
GAUDI_API long System::numCmdLineArgs ( )

Number of arguments passed to the commandline.

Definition at line 532 of file System.cpp.

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

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

OS name.

Definition at line 446 of file System.cpp.

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

OS version.

Definition at line 463 of file System.cpp.

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

121  {
122  VM_COUNTERS info;
123  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
124  return adjustMemory(unit, info.QuotaPagedPoolUsage);
125  return -2;
126 }
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:34
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 137 of file Memory.cpp.

137  {
138  POOLED_USAGE_AND_LIMITS quota;
139  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )
140  return adjustMemory(unit, quota.PagedPoolLimit);
141  return 0;
142 }
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:34
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 129 of file Memory.cpp.

129  {
130  VM_COUNTERS info;
131  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
132  return adjustMemory(unit, info.QuotaPeakPagedPoolUsage);
133  return -2;
134 }
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:34
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 153 of file Memory.cpp.

153  {
154  VM_COUNTERS info;
155  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
156  return adjustMemory(unit, info.PagefileUsage);
157  return -2;
158 }
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:34
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 169 of file Memory.cpp.

169  {
170  POOLED_USAGE_AND_LIMITS quota;
171  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) ) {
172  if ( long(quota.PagefileLimit) < 0 )
173  return -1;//LONG_MAX;
174  return adjustMemory(unit, quota.PagefileLimit);
175  }
176  return -2;
177 }
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:34
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 161 of file Memory.cpp.

161  {
162  VM_COUNTERS info;
163  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
164  return adjustMemory(unit, info.PeakPagefileUsage);
165  return -2;
166 }
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:34
GAUDI_API long System::parentID ( InfoType  fetch = ProcessBasics,
long  pid = -1 
)

Basic Process Information: Parent's process ID.

Definition at line 65 of file Memory.cpp.

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

Definition at line 226 of file PathResolver.cpp.

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

Definition at line 221 of file PathResolver.cpp.

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

Basic Process Information: priority boost.

Definition at line 89 of file Memory.cpp.

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

Handle to running process.

Retrieve processhandle.

Definition at line 126 of file ModuleInfo.cpp.

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

Basic Process Information: Process ID.

Definition at line 59 of file Memory.cpp.

59  {
60  static const long s_pid = ::getpid();
61  return s_pid;
62 }
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 124 of file Timing.cpp.

124  {
125  longlong left = 0;
126  QUOTA_LIMITS quota;
127  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) ) {
128  if ( left == -1 ) {
129  //left = _I64_MAX;
130  }
131  else {
132  left = adjustTime(typ, quota.TimeLimit);
133  }
134  }
135  return left;
136 }
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:37
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 747 of file System.cpp.

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

Attach module handle.

Definition at line 136 of file ModuleInfo.cpp.

136  {
137  ModuleHandle = handle;
138 }
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 97 of file Timing.cpp.

97  {
98  static longlong sys_start = 0;
99  if ( 0 == sys_start ) {
101  longlong t = tickCount();
102  sys_start = 10*c - t;
103  }
104  return adjustTime(typ, sys_start);
105 }
tuple c
Definition: gaudirun.py:392
GAUDI_API longlong currentTime(TimeType typ=milliSec)
Retrieve absolute system time.
Definition: Timing.cpp:79
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:37
GAUDI_API longlong tickCount()
Retrieve the number of ticks since system startup.
Definition: Timing.cpp:65
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:619
ThreadHandle System::threadSelf ( )
inline

thread handle "accessor"

Definition at line 112 of file System.h.

112 { 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 65 of file Timing.cpp.

65  {
66  longlong count = 10000;
67 #ifdef _WIN32
68  count *= ::GetTickCount(); // Number of milliSec since system startup
69 #else
70  struct tms buf;
71  count *= 10*times(&buf);
72 #endif
73  return count;
74 }
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  auto realname = std::unique_ptr<char,decltype(free)*>( abi::__cxa_demangle(class_name, 0, 0, &status), std::free );
412  if (!realname) return class_name;
413  result = std::string{realname.get()};
415  std::string::size_type pos = result.find(", ");
416  while( std::string::npos != pos ) {
417  result.replace( pos , 2 , "," ) ;
418  pos = result.find(", ");
419  }
420  }
421 #endif
422  return result;
423 }
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:37
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 108 of file Timing.cpp.

108  {
109  static longlong sys_start = 10*systemStart(microSec);
110  return adjustTime(typ, 10*currentTime(microSec)-sys_start);
111 }
GAUDI_API longlong currentTime(TimeType typ=milliSec)
Retrieve absolute system time.
Definition: Timing.cpp:79
GAUDI_API longlong systemStart(TimeType typ=Sec)
Maximum processing time left for this process.
Definition: Timing.cpp:97
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:37
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 158 of file Timing.cpp.

158  {
159  longlong usertime = 0;
160  KERNEL_USER_TIMES info;
161  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) {
162  usertime = adjustTime(typ, info.UserTime );
163  }
164  return usertime;
165 }
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:37
GAUDI_API long System::virtualMemory ( MemoryUnit  unit = kByte,
InfoType  fetch = Memory,
long  pid = -1 
)

Basic Process Information: priority boost.

Definition at line 212 of file Memory.cpp.

212  {
213  VM_COUNTERS info;
214  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
215  return adjustMemory(unit, info.VirtualSize);
216  return -2;
217 }
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:34
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 228 of file Memory.cpp.

228  {
229  QUOTA_LIMITS quota;
230  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) ) {
231  if ( long(quota.PagefileLimit) == -1 )
232  return -1;//LONG_MAX;
233  return adjustMemory(unit, quota.PagefileLimit);
234  }
235  return 0;
236 }
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:34
GAUDI_API long System::virtualMemoryPeak ( MemoryUnit  unit = kByte,
InfoType  fetch = Memory,
long  pid = -1 
)

Basic Process Information: priority boost.

Definition at line 220 of file Memory.cpp.

220  {
221  VM_COUNTERS info;
222  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
223  return adjustMemory(unit, info.PeakVirtualSize);
224  return -2;
225 }
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:34