The Gaudi Framework  v29r0 (ff2e7097)
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
}
 Unit of memory. More...
 
enum  ModuleType { UNKNOWN, SHAREDLIB, EXECUTABLE }
 
enum  InfoType {
  NoFetch, RemainTime, Times, ProcessBasics,
  PriorityBoost, Memory, Quota, System,
  Modules, IO
}
 Enumeration for fetching information. More...
 
enum  TimeType {
  Year, Month, Day, Hour,
  Min, Sec, milliSec, microSec,
  nanoSec, 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
}
 

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::stringmoduleName ()
 Get the name of the (executable/DLL) file without file-type. More...
 
GAUDI_API const std::stringmoduleNameFull ()
 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::stringexeName ()
 Name of the executable file running. More...
 
GAUDI_API const std::vector< std::stringlinkedModules ()
 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::stringhostName ()
 Host name. More...
 
GAUDI_API const std::stringosName ()
 OS name. More...
 
GAUDI_API const std::stringosVersion ()
 OS version. More...
 
GAUDI_API const std::stringmachineType ()
 Machine type. More...
 
GAUDI_API int instructionsetLevel ()
 Instruction Set "Level". More...
 
GAUDI_API const std::stringaccountName ()
 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::stringcmdLineArgs ()
 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::stringgetEnv ()
 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...
 
template<TimeType T>
GAUDI_API longlong currentTime ()
 Retrieve absolute system time. More...
 
GAUDI_API longlong currentTime (TimeType typ=milliSec)
 Get current time in specificed units. 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)
 
template<TimeType T>
longlong currentTime ()
 Retrieve absolute system time. More...
 
template longlong currentTime< Year > ()
 
template longlong currentTime< Month > ()
 
template longlong currentTime< Day > ()
 
template longlong currentTime< Hour > ()
 
template longlong currentTime< Min > ()
 
template longlong currentTime< Sec > ()
 
template longlong currentTime< milliSec > ()
 
template longlong currentTime< microSec > ()
 
template longlong currentTime< nanoSec > ()
 
template longlong currentTime< Native > ()
 
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 31 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 33 of file ModuleInfo.h.

typedef void* System::ThreadHandle

A Thread handle.

Definition at line 109 of file System.h.

Enumeration Type Documentation

Enumeration for fetching information.

Enumerator
NoFetch 
RemainTime 
Times 
ProcessBasics 
PriorityBoost 
Memory 
Quota 
System 
Modules 
IO 

Definition at line 19 of file SystemBase.h.

Unit of memory.

Enumerator
Byte 
kByte 
MByte 
GByte 
TByte 
PByte 
EByte 

Definition at line 56 of file Memory.h.

Enumerator
UNKNOWN 
SHAREDLIB 
EXECUTABLE 

Definition at line 29 of file ModuleInfo.h.

Enumerator
PR_regular_file 
PR_directory 

Definition at line 36 of file PathResolver.cpp.

Enumerator
PR_local 
PR_recursive 

Definition at line 38 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 23 of file ProcessDescriptor.cpp.

23  {
37  ProcessIoPortHandlers, // Note: this is kernel mode only
49  };

Time type for conversion.

Enumerator
Year 
Month 
Day 
Hour 
Min 
Sec 
milliSec 
microSec 
nanoSec 
Native 

Definition at line 58 of file Timing.h.

Function Documentation

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

User login name.

Definition at line 476 of file System.cpp.

477 {
478  static std::string account = "";
479  if ( account == "" ) {
480 #ifdef _WIN32
481  char buffer[512];
482  unsigned long buflen = sizeof( buffer );
483  ::GetUserName( buffer, &buflen );
484  account = buffer;
485 #else
486  const char* acct = ::getlogin();
487  if ( !acct ) acct = ::getenv( "LOGNAME" );
488  if ( !acct ) acct = ::getenv( "USER" );
489  account = ( acct ) ? acct : "Unknown";
490 #endif
491  }
492  return account;
493 }
STL class.
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.

35 {
36  if ( value != -1 ) {
37  switch ( unit ) {
38  case Byte:
39  break;
40  case kByte:
41  value = value / 1024;
42  break;
43  case MByte:
44  value = ( value / 1024 ) / 1024;
45  break;
46  case GByte:
47  value = ( ( value / 1024 ) / 1024 ) / 1024;
48  break;
49  case TByte:
50  value = ( ( ( value / 1024 ) / 1024 ) / 1024 ) / 1024;
51  break;
52  case PByte:
53  value = ( ( ( ( value / 1024 ) / 1024 ) / 1024 ) / 1024 ) / 1024;
54  break;
55  case EByte:
56  value = ( ( ( ( ( value / 1024 ) / 1024 ) / 1024 ) / 1024 ) / 1024 ) / 1024;
57  break;
58  default:
59  value = -1;
60  break;
61  }
62  }
63  return value;
64 }
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.

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:
51  return adjustTime<Year>( t );
52  case Month:
53  return adjustTime<Month>( t );
54  case Day:
55  return adjustTime<Day>( t );
56  case Hour:
57  return adjustTime<Hour>( t );
58  case Min:
59  return adjustTime<Min>( t );
60  case Sec:
61  return adjustTime<Sec>( t );
62  case milliSec:
63  return adjustTime<milliSec>( t );
64  case microSec:
65  return adjustTime<microSec>( t );
66  case nanoSec:
67  return adjustTime<nanoSec>( t );
68  case Native:
69  return adjustTime<Native>( t );
70  }
71  }
72  return t;
73 }
long long adjustTime< Native >(long long t)
Definition: Timing.h:262
long long adjustTime< Month >(long long t)
Definition: Timing.h:257
long long adjustTime< nanoSec >(long long t)
Definition: Timing.h:252
long long adjustTime< Day >(long long t)
Definition: Timing.h:222
long long adjustTime< milliSec >(long long t)
Definition: Timing.h:242
long long adjustTime< Year >(long long t)
Definition: Timing.h:217
long long adjustTime< microSec >(long long t)
Definition: Timing.h:247
long long adjustTime< Min >(long long t)
Definition: Timing.h:232
long long adjustTime< Hour >(long long t)
Definition: Timing.h:227
long long adjustTime< Sec >(long long t)
Definition: Timing.h:237
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 222 of file Timing.h.

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

Definition at line 227 of file Timing.h.

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

Definition at line 247 of file Timing.h.

248  {
249  return ( t == -1 ) ? t : t /= ( 10LL );
250  }
template<>
long long System::adjustTime< milliSec > ( long long  t)
inline

Definition at line 242 of file Timing.h.

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

Definition at line 232 of file Timing.h.

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

Definition at line 257 of file Timing.h.

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

Definition at line 252 of file Timing.h.

253  {
254  return ( t == -1 ) ? t : t *= 100LL;
255  }
template<>
long long System::adjustTime< Native > ( long long  t)
inline

Definition at line 262 of file Timing.h.

263  {
264  return t;
265  }
template<>
long long System::adjustTime< Sec > ( long long  t)
inline

Definition at line 237 of file Timing.h.

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

Definition at line 217 of file Timing.h.

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

Basic Process Information: Affinity mask.

Definition at line 90 of file Memory.cpp.

91 {
92  PROCESS_BASIC_INFORMATION info;
93  if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.AffinityMask;
94  return 0;
95 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
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 499 of file System.cpp.

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

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

Definition at line 644 of file System.cpp.

645 {
646  try {
647  // Always hide the first two levels of the stack trace (that's us)
648  const int totalOffset = offset + 2;
649  const int totalDepth = depth + totalOffset;
650 
651  std::string fnc, lib;
652 
653  std::vector<void*> addresses( totalDepth, nullptr );
654  int count = System::backTrace( addresses.data(), totalDepth );
655  for ( int i = totalOffset; i < count; ++i ) {
656  void* addr = nullptr;
657 
658  if ( System::getStackLevel( addresses[i], addr, fnc, lib ) ) {
659  std::ostringstream ost;
660  ost << "#" << std::setw( 3 ) << std::setiosflags( std::ios::left ) << i - totalOffset + 1;
661  ost << std::hex << addr << std::dec << " " << fnc << " [" << lib << "]" << std::endl;
662  btrace += ost.str();
663  }
664  }
665  return true;
666  } catch ( const std::bad_alloc& e ) {
667  return false;
668  }
669 }
GAUDI_API bool getStackLevel(void *addresses, void *&addr, std::string &fnc, std::string &lib)
T endl(T...args)
T setiosflags(T...args)
GAUDI_API int backTrace(void **addresses, const int depth)
T setw(T...args)
STL class.
T count(T...args)
STL class.
T hex(T...args)
long System::basePriority ( InfoType  fetch = ProcessBasics,
long  pid = -1 
)

Basic Process Information: Base priority.

Definition at line 67 of file Memory.cpp.

68 {
69  PROCESS_BASIC_INFORMATION info;
70  if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.BasePriority;
71  return 0;
72 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
long System::breakExecution ( )

Break the execution of the application and invoke the debugger.

Definition at line 48 of file Debugger.cpp.

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

60 {
61 #ifdef _WIN32
62  long result = 0;
63  if ( pid == Win::_getpid() ) {
64  _asm int 3 return 1;
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 }
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
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 502 of file System.cpp.

503 {
504  if ( s_argvChars.size() == 0 ) {
505  char exe[1024];
506 #ifdef _WIN32
507 // Disable warning C4996 triggered by C standard library calls
509 #pragma warning( push )
510 #pragma warning( disable : 4996 )
511  // For compatibility with UNIX we CANNOT use strtok!
512  // If we would use strtok, options like -g="My world" at
513  // the command line level would result on NT in TWO options
514  // instead in one as in UNIX.
515  char *next, *tmp1, *tmp2;
516  for ( LPTSTR cmd = ::GetCommandLine(); *cmd; cmd = next ) {
517  memset( exe, 0, sizeof( exe ) );
518  while ( *cmd == ' ' ) cmd++;
519  next = ::strchr( cmd, ' ' );
520  if ( !next ) next = cmd + strlen( cmd );
521  if ( ( tmp1 = ::strchr( cmd, '\"' ) ) > 0 && tmp1 < next ) {
522  tmp2 = ::strchr( ++tmp1, '\"' );
523  if ( tmp2 > 0 ) {
524  next = ++tmp2;
525  if ( cmd < tmp1 ) strncpy( exe, cmd, tmp1 - cmd - 1 );
526  strncpy( &exe[strlen( exe )], tmp1, tmp2 - tmp1 - 1 );
527  } else {
528  std::cout << "Mismatched \" in command line arguments" << std::endl;
529  s_argvChars.erase( s_argvChars.begin(), s_argvChars.end() );
530  s_argvStrings.erase( s_argvStrings.begin(), s_argvStrings.end() );
531  return s_argvStrings;
532  }
533  } else {
534  strncpy( exe, cmd, next - cmd );
535  }
536  s_argvStrings.push_back( exe );
537  s_argvChars.push_back( s_argvStrings.back().c_str() );
538  }
539 #pragma warning( pop )
540 #elif defined( __linux ) || defined( __APPLE__ )
541  sprintf( exe, "/proc/%d/cmdline", ::getpid() );
542  FILE* cmdLine = ::fopen( exe, "r" );
543  char cmd[1024];
544  if ( cmdLine ) {
545  long len = fread( cmd, sizeof( char ), sizeof( cmd ), cmdLine );
546  if ( len > 0 ) {
547  cmd[len] = 0;
548  for ( char* token = cmd; token - cmd < len; token += strlen( token ) + 1 ) {
549  s_argvStrings.push_back( token );
550  s_argvChars.push_back( s_argvStrings.back().c_str() );
551  }
552  s_argvStrings[0] = exeName();
553  s_argvChars[0] = s_argvStrings[0].c_str();
554  }
555  ::fclose( cmdLine );
556  }
557 #endif
558  }
559  return s_argvStrings;
560 }
T endl(T...args)
T fread(T...args)
T memset(T...args)
T end(T...args)
GAUDI_API const std::string & exeName()
Name of the executable file running.
Definition: ModuleInfo.cpp:210
T push_back(T...args)
T strncpy(T...args)
T strlen(T...args)
T next(T...args)
T erase(T...args)
T begin(T...args)
T c_str(T...args)
T back(T...args)
T sprintf(T...args)
T strchr(T...args)
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 196 of file Timing.cpp.

197 {
198  longlong cputime = 0;
199  KERNEL_USER_TIMES info;
200  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) {
201  cputime = adjustTime( typ, info.KernelTime + info.UserTime );
202  }
203  return cputime;
204 }
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:37
ProcessDescriptor * getProcess()
Retrieve Process structure.
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 138 of file Timing.cpp.

139 {
140  longlong created = 0;
141  KERNEL_USER_TIMES info;
142  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) {
143  created = adjustTime( typ, info.CreateTime - UNIX_BASE_TIME );
144  }
145  return created;
146 }
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:37
ProcessDescriptor * getProcess()
Retrieve Process structure.
template<TimeType T>
GAUDI_API longlong System::currentTime ( )
inline

Retrieve absolute system time.

Parameters
typIndicator or the unit the time will be returned.
Returns
Requested value in the indicated units.Get current time in specificed units via template parameter (inlined)

Definition at line 269 of file Timing.h.

270  {
271 #ifdef _WIN32
272  longlong current = 0;
273  ::GetSystemTimeAsFileTime( (FILETIME*)&current );
274  return adjustTime<T>( current - UNIX_BASE_TIME );
275 #else
276  struct timeval tv;
277  ::gettimeofday( &tv, 0 );
278  return adjustTime<T>( ( tv.tv_sec * 1000000 + tv.tv_usec ) * 10 );
279 #endif
280  }
longlong System::currentTime ( TimeType  typ = milliSec)

Get current time in specificed units.

Retrieve current system time.

Definition at line 91 of file Timing.cpp.

92 {
93  switch ( typ ) {
94  case Year:
95  return currentTime<Year>();
96  case Month:
97  return currentTime<Month>();
98  case Day:
99  return currentTime<Day>();
100  case Hour:
101  return currentTime<Hour>();
102  case Min:
103  return currentTime<Min>();
104  case Sec:
105  return currentTime<Sec>();
106  case milliSec:
107  return currentTime<milliSec>();
108  case microSec:
109  return currentTime<microSec>();
110  case nanoSec:
111  return currentTime<nanoSec>();
112  case Native:
113  return currentTime<Native>();
114  }
115  return currentTime<Native>();
116 }
template longlong currentTime< milliSec >()
template longlong currentTime< microSec >()
template longlong currentTime< Min >()
template longlong currentTime< Month >()
template longlong currentTime< Hour >()
template longlong currentTime< Day >()
template longlong currentTime< Native >()
template longlong currentTime< nanoSec >()
template longlong currentTime< Sec >()
template longlong currentTime< Year >()
template<TimeType T>
longlong System::currentTime ( )
inline

Retrieve absolute system time.

Parameters
typIndicator or the unit the time will be returned.
Returns
Requested value in the indicated units.Get current time in specificed units via template parameter (inlined)

Definition at line 269 of file Timing.h.

270  {
271 #ifdef _WIN32
272  longlong current = 0;
273  ::GetSystemTimeAsFileTime( (FILETIME*)&current );
274  return adjustTime<T>( current - UNIX_BASE_TIME );
275 #else
276  struct timeval tv;
277  ::gettimeofday( &tv, 0 );
278  return adjustTime<T>( ( tv.tv_sec * 1000000 + tv.tv_usec ) * 10 );
279 #endif
280  }
template longlong System::currentTime< Day > ( )
template longlong System::currentTime< Min > ( )
template longlong System::currentTime< Sec > ( )
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 164 of file Timing.cpp.

165 {
166  KERNEL_USER_TIMES info;
167  longlong ellapsed = currentTime( microSec ) * 10;
168  getProcess()->query( pid, fetch, &info );
169  ellapsed = adjustTime( typ, ellapsed + UNIX_BASE_TIME - info.CreateTime );
170  return ellapsed;
171 }
GAUDI_API longlong currentTime()
Retrieve absolute system time.
Definition: Timing.h:269
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:37
ProcessDescriptor * getProcess()
Retrieve Process structure.
long query(long pid, InfoType info, PROCESS_BASIC_INFORMATION *buffer)
System::ImageHandle System::exeHandle ( )

Handle to the executable file running.

Definition at line 173 of file ModuleInfo.cpp.

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

Name of the executable file running.

Definition at line 210 of file ModuleInfo.cpp.

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

99 {
100  PROCESS_BASIC_INFORMATION info;
101  if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.ExitStatus;
102  return -2;
103 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
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 581 of file System.cpp.

582 {
583  char* env;
584  if ( ( env = getenv( var ) ) != nullptr ) {
585  return env;
586  } else {
587  return "UNKNOWN";
588  }
589 }
T getenv(T...args)
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 592 of file System.cpp.

593 {
594  char* env;
595  if ( ( env = getenv( var ) ) != nullptr ) {
596  value = env;
597  return true;
598  } else {
599  return false;
600  }
601 }
T getenv(T...args)
bool System::getEnv ( const std::string var,
std::string value 
)
inline

Definition at line 91 of file System.h.

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

get all environment variables

get all defined environment vars

Definition at line 610 of file System.cpp.

611 {
612 #if defined( _WIN32 )
613 #define environ _environ
614 #elif defined( __APPLE__ )
615  static char** environ = *_NSGetEnviron();
616 #endif
618  for ( int i = 0; environ[i] != nullptr; ++i ) {
619  vars.push_back( environ[i] );
620  }
621  return vars;
622 }
T push_back(T...args)
const std::string System::getErrorString ( unsigned long  error)

Retrieve error code as string for a given error.

Definition at line 298 of file System.cpp.

299 {
300  std::string errString = "";
301 #ifdef _WIN32
302  LPVOID lpMessageBuffer;
303  ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, error,
304  MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), // The user default language
305  (LPTSTR)&lpMessageBuffer, 0, NULL );
306  errString = (const char*)lpMessageBuffer;
307  // Free the buffer allocated by the system
308  ::LocalFree( lpMessageBuffer );
309 #else
310  char* cerrString( nullptr );
311  // Remember: for linux dl* routines must be handled differently!
312  if ( error == 0xAFFEDEAD ) {
313  cerrString = (char*)::dlerror();
314  if ( !cerrString ) cerrString = ::strerror( error );
315  if ( !cerrString ) {
316  cerrString = (char*)"Unknown error. No information found in strerror()!";
317  } else {
318  errString = std::string( cerrString );
319  }
320  errno = 0;
321  } else {
322  cerrString = ::strerror( error );
323  errString = std::string( cerrString );
324  }
325 #endif
326  return errString;
327 }
STL class.
unsigned long System::getLastError ( )

Get last system known error.

Retrieve last error code.

Definition at line 280 of file System.cpp.

281 {
282 #ifdef _WIN32
283  return ::GetLastError();
284 #else
285  // convert errno (int) to unsigned long
286  return static_cast<unsigned long>( static_cast<unsigned int>( errno ) );
287 #endif
288 }
const std::string System::getLastErrorString ( )

Get last system error as string.

Retrieve last error code as string.

Definition at line 291 of file System.cpp.

292 {
293  const std::string errString = getErrorString( getLastError() );
294  return errString;
295 }
GAUDI_API const std::string getErrorString(unsigned long error)
Retrieve error code as string for a given error.
Definition: System.cpp:298
GAUDI_API unsigned long getLastError()
Get last system known error.
Definition: System.cpp:280
STL class.
unsigned long System::getProcedureByName ( ImageHandle  handle,
const std::string name,
EntryPoint pFunction 
)

Get a specific function defined in the DLL.

Definition at line 223 of file System.cpp.

224 {
225 #ifdef _WIN32
226  *pFunction = ( EntryPoint )::GetProcAddress( (HINSTANCE)handle, name.data() );
227  if ( 0 == *pFunction ) {
228  return System::getLastError();
229  }
230  return 1;
231 #elif defined( __linux )
232 #if __GNUC__ < 4
233  *pFunction = ( EntryPoint )::dlsym( handle, name.c_str() );
234 #else
235  *pFunction = FuncPtrCast<EntryPoint>(::dlsym( handle, name.c_str() ) );
236 #endif
237  if ( !*pFunction ) {
238  errno = 0xAFFEDEAD;
239  // std::cout << "System::getProcedureByName>" << getLastErrorString() << std::endl;
240  return 0;
241  }
242  return 1;
243 #elif defined( __APPLE__ )
244  *pFunction = ( EntryPoint )::dlsym( handle, name.c_str() );
245  if ( !( *pFunction ) ) {
246  // Try with an underscore :
247  std::string sname = "_" + name;
248  *pFunction = ( EntryPoint )::dlsym( handle, sname.c_str() );
249  }
250  if ( 0 == *pFunction ) {
251  errno = 0xAFFEDEAD;
252  std::cout << "System::getProcedureByName>" << getLastErrorString() << std::endl;
253  // std::cout << "System::getProcedureByName> failure" << std::endl;
254  return 0;
255  }
256  return 1;
257 #elif __hpux
258  HMODULE* mod = (HMODULE*)handle;
259  if ( 0 != mod ) {
260  long ll1 = name.length();
261  for ( int i = 0; i < mod->numSym; i++ ) {
262  long ll2 = strlen( mod->sym[i].name );
263  if ( 0 != ::strncmp( mod->sym[i].name, name.c_str(), ( ll1 > ll2 ) ? ll1 : ll2 ) == 0 ) {
264  *pFunction = (EntryPoint)mod->sym[i].value;
265  return 1;
266  }
267  }
268  }
269  return 0;
270 #endif
271 }
GAUDI_API unsigned long getLastError()
Get last system known error.
Definition: System.cpp:280
T endl(T...args)
STL class.
T data(T...args)
T strlen(T...args)
T length(T...args)
T strncmp(T...args)
T c_str(T...args)
GAUDI_API const std::string getLastErrorString()
Get last system error as string.
Definition: System.cpp:291
unsigned long(* EntryPoint)(const unsigned long iid, void **ppvObject)
Definition of the "generic" DLL entry point function.
Definition: System.h:36
unsigned long System::getProcedureByName ( ImageHandle  handle,
const std::string name,
Creator pFunction 
)

Get a specific function defined in the DLL.

Definition at line 274 of file System.cpp.

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

Retrieve Process structure.

Definition at line 135 of file ProcessDescriptor.h.

136  {
137  static ProcessDescriptor p;
138  return &p;
139  }
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 208 of file Timing.cpp.

209  {
210  KERNEL_USER_TIMES info;
211  if ( getProcess()->query( pid, Times, &info ) ) {
212  return ProcessTime( info.KernelTime, info.UserTime, currentTime<Native>() - info.CreateTime );
213  }
214  return ProcessTime(); // return 0s in case of problems
215  }
template longlong currentTime< Native >()
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API bool System::getStackLevel ( void *  addresses,
void *&  addr,
std::string fnc,
std::string lib 
)
std::string System::homeDirectory ( )

Definition at line 61 of file Environment.cpp.

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

Host name.

Definition at line 403 of file System.cpp.

404 {
405  static const std::string host = init_hostName();
406  return host;
407 }
STL class.
int System::instructionsetLevel ( )

Instruction Set "Level".

Definition at line 469 of file System.cpp.

470 {
471  using namespace Gaudi;
472  return instrset_detect();
473 }
int instrset_detect(void)
Helper functions to set/get the application return code.
Definition: __init__.py:1
bool System::isEnvSet ( const char *  var)

Check if an environment variable is set or not.

Definition at line 603 of file System.cpp.

603 { return getenv( var ) != nullptr; }
T getenv(T...args)
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 174 of file Timing.cpp.

175 {
176  KERNEL_USER_TIMES info;
177  longlong kerneltime = 0;
178  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) {
179  kerneltime = adjustTime( typ, info.KernelTime );
180  }
181  return kerneltime;
182 }
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:37
ProcessDescriptor * getProcess()
Retrieve Process structure.
const std::vector< std::string > System::linkedModules ( )

Vector of names of linked modules.

Definition at line 233 of file ModuleInfo.cpp.

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

Load dynamic link library.

Definition at line 147 of file System.cpp.

148 {
149  unsigned long res;
150  // if name is empty, just load it
151  if ( name.length() == 0 ) {
152  res = loadWithoutEnvironment( name, handle );
153  } else {
154  // If the name is a logical name (environment variable), the try
155  // to load the corresponding library from there.
156  std::string imgName;
157  if ( getEnv( name, imgName ) ) {
158  res = loadWithoutEnvironment( imgName, handle );
159  } else {
160  // build the dll name
161  std::string dllName = name;
162 // Add a possible "lib" prefix to the name on unix platforms. But only if
163 // it's not an absolute path name.
164 #if defined( __linux ) || defined( __APPLE__ )
165  if ( ( dllName.find( '/' ) == std::string::npos ) && ( dllName.compare( 0, 3, "lib" ) != 0 ) ) {
166  dllName = "lib" + dllName;
167  }
168 #endif // unix
169  // Now try loading the library with all possible suffixes supported by the
170  // platform.
171  for ( const char* suffix : SHLIB_SUFFIXES ) {
172  // Add the suffix if necessary.
173  std::string libName = dllName;
174  const size_t len = strlen( suffix );
175  if ( dllName.compare( dllName.length() - len, len, suffix ) != 0 ) {
176  libName += suffix;
177  }
178  // Try to load the library.
179  res = loadWithoutEnvironment( libName, handle );
180  // If the load succeeded, stop here.
181  if ( res == 1 ) {
182  break;
183  }
184  }
185  }
186  if ( res != 1 ) {
187 #if defined( __linux ) || defined( __APPLE__ )
188  errno = 0xAFFEDEAD;
189 #endif
190  // std::cout << "System::loadDynamicLib>" << getLastErrorString() << std::endl;
191  }
192  }
193  return res;
194 }
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:581
STL class.
T strlen(T...args)
T find(T...args)
T length(T...args)
T compare(T...args)
const std::string & System::machineType ( )

Machine type.

Definition at line 449 of file System.cpp.

450 {
451  static std::string mach = "";
452 #ifdef _WIN32
453  SYSTEM_INFO ut;
454  ::GetSystemInfo( &ut );
455  std::ostringstream arch;
456  arch << ut.wProcessorArchitecture;
457  mach = arch.str();
458 #else
459  struct utsname ut;
460  if ( uname( &ut ) == 0 ) {
461  mach = ut.machine;
462  } else {
463  mach = "UNKNOWN";
464  }
465 #endif
466  return mach;
467 }
STL class.
long System::mappedMemory ( MemoryUnit  unit = kByte,
InfoType  fetch = Memory,
long  pid = -1 
)

Basic Process Information: priority boost.

Definition at line 204 of file Memory.cpp.

205 {
206  VM_COUNTERS info;
207  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.WorkingSetSize );
208  return -2;
209 }
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:34
ProcessDescriptor * getProcess()
Retrieve Process structure.
long System::mappedMemoryPeak ( MemoryUnit  unit = kByte,
InfoType  fetch = Memory,
long  pid = -1 
)

Basic Process Information: priority boost.

Definition at line 212 of file Memory.cpp.

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

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

222 {
223  QUOTA_LIMITS quota;
224  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
225  return adjustMemory( unit, quota.MinimumWorkingSetSize );
226  return 0;
227 }
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:34
ProcessDescriptor * getProcess()
Retrieve Process structure.
System::ImageHandle System::moduleHandle ( )

Handle to currently executed module.

Definition at line 141 of file ModuleInfo.cpp.

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

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 ) {
63  _psApi.GetModuleBaseNameA( processHandle(), (HINSTANCE)moduleHandle(), moduleName, sizeof( moduleName ) );
64  }
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 }
T rfind(T...args)
GAUDI_API ProcessHandle processHandle()
Handle to running process.
Definition: ModuleInfo.cpp:128
STL class.
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:54
T substr(T...args)
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.

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

Get type of the module.

Definition at line 105 of file ModuleInfo.cpp.

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

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

133 {
134  POOLED_USAGE_AND_LIMITS quota;
135  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
136  return adjustMemory( unit, quota.NonPagedPoolLimit );
137  return 0;
138 }
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:34
ProcessDescriptor * getProcess()
Retrieve Process structure.
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 114 of file Memory.cpp.

115 {
116  VM_COUNTERS info;
117  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
118  return adjustMemory( unit, info.QuotaPeakNonPagedPoolUsage );
119  return -2;
120 }
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:34
ProcessDescriptor * getProcess()
Retrieve Process structure.
long System::numCmdLineArgs ( )

Number of arguments passed to the commandline.

Definition at line 496 of file System.cpp.

496 { return cmdLineArgs().size(); }
T size(T...args)
GAUDI_API const std::vector< std::string > cmdLineArgs()
Command line arguments including executable name as arg[0] as vector of strings.
Definition: System.cpp:502
long System::numPageFault ( InfoType  fetch = Memory,
long  pid = -1 
)

Basic Process Information: Number of page faults.

Basic Process Information: priority boost.

Definition at line 168 of file Memory.cpp.

169 {
170  VM_COUNTERS info;
171  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return info.PageFaultCount;
172  return -2;
173 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
const std::string & System::osName ( )

OS name.

Definition at line 410 of file System.cpp.

411 {
412  static std::string osname = "";
413 #ifdef _WIN32
414  osname = "Windows";
415 #else
416  struct utsname ut;
417  if ( uname( &ut ) == 0 ) {
418  osname = ut.sysname;
419  } else {
420  osname = "UNKNOWN";
421  }
422 #endif
423  return osname;
424 }
STL class.
const std::string & System::osVersion ( )

OS version.

Definition at line 427 of file System.cpp.

428 {
429  static std::string osver = "";
430 #ifdef _WIN32
431  OSVERSIONINFO ut;
432  ut.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
433  ::GetVersionEx( &ut );
434  std::ostringstream ver;
435  ver << ut.dwMajorVersion << '.' << ut.dwMinorVersion;
436  osver = ver.str();
437 #else
438  struct utsname ut;
439  if ( uname( &ut ) == 0 ) {
440  osver = ut.release;
441  } else {
442  osver = "UNKNOWN";
443  }
444 #endif
445  return osver;
446 }
STL class.
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 141 of file Memory.cpp.

142 {
143  VM_COUNTERS info;
144  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
145  return adjustMemory( unit, info.QuotaPagedPoolUsage );
146  return -2;
147 }
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:34
ProcessDescriptor * getProcess()
Retrieve Process structure.
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 159 of file Memory.cpp.

160 {
161  POOLED_USAGE_AND_LIMITS quota;
162  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
163  return adjustMemory( unit, quota.PagedPoolLimit );
164  return 0;
165 }
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:34
ProcessDescriptor * getProcess()
Retrieve Process structure.
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 150 of file Memory.cpp.

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

177 {
178  VM_COUNTERS info;
179  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.PagefileUsage );
180  return -2;
181 }
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:34
ProcessDescriptor * getProcess()
Retrieve Process structure.
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 193 of file Memory.cpp.

194 {
195  POOLED_USAGE_AND_LIMITS quota;
196  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) ) {
197  if ( long( quota.PagefileLimit ) < 0 ) return -1; // LONG_MAX;
198  return adjustMemory( unit, quota.PagefileLimit );
199  }
200  return -2;
201 }
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:34
ProcessDescriptor * getProcess()
Retrieve Process structure.
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 184 of file Memory.cpp.

185 {
186  VM_COUNTERS info;
187  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
188  return adjustMemory( unit, info.PeakPagefileUsage );
189  return -2;
190 }
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:34
ProcessDescriptor * getProcess()
Retrieve Process structure.
long System::parentID ( InfoType  fetch = ProcessBasics,
long  pid = -1 
)

Basic Process Information: Parent's process ID.

Definition at line 82 of file Memory.cpp.

83 {
84  PROCESS_BASIC_INFORMATION info;
85  if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.InheritedFromUniqueProcessId;
86  return 0;
87 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
std::string System::PathResolverFindDataFile ( const std::string logical_file_name)

Definition at line 207 of file PathResolver.cpp.

208  {
209  return PathResolver::find_file( logical_file_name, "DATAPATH" );
210  }
std::string System::PathResolverFindXMLFile ( const std::string logical_file_name)

Definition at line 202 of file PathResolver.cpp.

203  {
204  return PathResolver::find_file( logical_file_name, "XMLPATH" );
205  }
long System::priorityBoost ( InfoType  fetch = PriorityBoost,
long  pid = -1 
)

Basic Process Information: priority boost.

Definition at line 106 of file Memory.cpp.

107 {
108  long info;
109  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return info;
110  return -2;
111 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
void * System::processHandle ( )

Handle to running process.

Retrieve processhandle.

Definition at line 128 of file ModuleInfo.cpp.

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

Basic Process Information: Process ID.

Definition at line 75 of file Memory.cpp.

76 {
77  static const long s_pid = ::getpid();
78  return s_pid;
79 }
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 149 of file Timing.cpp.

150 {
151  longlong left = 0;
152  QUOTA_LIMITS quota;
153  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) ) {
154  if ( left == -1 ) {
155  // left = _I64_MAX;
156  } else {
157  left = adjustTime( typ, quota.TimeLimit );
158  }
159  }
160  return left;
161 }
T left(T...args)
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:37
ProcessDescriptor * getProcess()
Retrieve Process structure.
StatusCode System::resolveEnv ( const std::string var,
std::string res,
int  recusions = 124 
)

Definition at line 51 of file Environment.cpp.

52 {
53  std::string source = var;
54  res = i_resolve( source, recursions );
55  if ( res.find( "${" ) == std::string::npos ) {
56  return StatusCode::SUCCESS;
57  }
58  return StatusCode::FAILURE;
59 }
STL class.
T find(T...args)
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 704 of file System.cpp.

705 {
706 #ifndef WIN32
707  // UNIX version
708  return value.empty() ?
709  // remove if set to nothing (and return success)
710  ::unsetenv( name.c_str() ),
711  0 :
712  // set the value
713  ::setenv( name.c_str(), value.c_str(), overwrite );
714 #else
715  // Windows version
716  if ( value.empty() ) {
717  // equivalent to unsetenv
718  return ::_putenv( ( name + "=" ).c_str() );
719  } else {
720  if ( !getenv( name.c_str() ) || overwrite ) {
721  // set if not yet present or overwrite is set (force)
722  return ::_putenv( ( name + "=" + value ).c_str() );
723  }
724  }
725  return 0; // if we get here, we are trying to set a variable already set, but
726  // not to overwrite.
727  // It is considered a success on Linux (man P setenv)
728 #endif
729 }
T empty(T...args)
T getenv(T...args)
T c_str(T...args)
void System::setModuleHandle ( System::ImageHandle  handle)

Attach module handle.

Definition at line 139 of file ModuleInfo.cpp.

139 { ModuleHandle = handle; }
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 119 of file Timing.cpp.

120 {
121  static longlong sys_start = 0;
122  if ( 0 == sys_start ) {
124  longlong t = tickCount();
125  sys_start = 10 * c - t;
126  }
127  return adjustTime( typ, sys_start );
128 }
GAUDI_API longlong tickCount()
Retrieve the number of ticks since system startup.
Definition: Timing.cpp:76
GAUDI_API longlong currentTime()
Retrieve absolute system time.
Definition: Timing.h:269
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:37
std::string System::tempDirectory ( )

Definition at line 78 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 ) || System::getEnv( "TEMPDIR", dir ) || System::getEnv( "TEMP_DIR", dir ) ||
84  System::getEnv( "TMP", dir ) || System::getEnv( "TMPDIR", dir ) || System::getEnv( "TMP_DIR", dir ) )
85  return dir;
86  else
87  return homeDirectory();
88 }
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:581
GAUDI_API std::string homeDirectory()
Definition: Environment.cpp:61
STL class.
ThreadHandle System::threadSelf ( )
inline

thread handle "accessor"

Definition at line 111 of file System.h.

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

Retrieve the number of ticks since system startup.

Returns
Requested value in the indicated units.

Definition at line 76 of file Timing.cpp.

77 {
78  longlong count = 10000;
79 #ifdef _WIN32
80  count *= ::GetTickCount(); // Number of milliSec since system startup
81 #else
82  struct tms buf;
83  count *= 10 * times( &buf );
84 #endif
85  return count;
86 }
T count(T...args)
const std::string System::typeinfoName ( const std::type_info tinfo)

Get platform independent information about the class type.

Definition at line 329 of file System.cpp.

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

Definition at line 331 of file System.cpp.

332 {
333  std::string result;
334 #ifdef _WIN32
335  long off = 0;
336  if (::strncmp( class_name, "class ", 6 ) == 0 ) {
337  // The returned name is prefixed with "class "
338  off = 6;
339  }
340  if (::strncmp( class_name, "struct ", 7 ) == 0 ) {
341  // The returned name is prefixed with "struct "
342  off = 7;
343  }
344  if ( off > 0 ) {
345  std::string tmp = class_name + off;
346  long loc = 0;
347  while ( ( loc = tmp.find( "class " ) ) > 0 ) {
348  tmp.erase( loc, 6 );
349  }
350  loc = 0;
351  while ( ( loc = tmp.find( "struct " ) ) > 0 ) {
352  tmp.erase( loc, 7 );
353  }
354  result = tmp;
355  } else {
356  result = class_name;
357  }
358  // Change any " *" to "*"
359  while ( ( off = result.find( " *" ) ) != std::string::npos ) {
360  result.replace( off, 2, "*" );
361  }
362  // Change any " &" to "&"
363  while ( ( off = result.find( " &" ) ) != std::string::npos ) {
364  result.replace( off, 2, "&" );
365  }
366 
367 #elif defined( __linux ) || defined( __APPLE__ )
368  int status;
370  abi::__cxa_demangle( class_name, nullptr, nullptr, &status ), std::free );
371  if ( !realname ) return class_name;
372 #if _GLIBCXX_USE_CXX11_ABI
373  static const std::regex cxx11_string{
374  "std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >( (?=>))?"};
375  result = std::regex_replace( realname.get(), cxx11_string, "std::string" );
376 #else
377  result = std::string{realname.get()};
378 #endif
379  // substitute ', ' with ','
380  static const std::regex comma_space{", "};
381  result = std::regex_replace( result, comma_space, "," );
382 #endif
383  return result;
384 }
T free(T...args)
STL class.
T replace(T...args)
T regex_replace(T...args)
T erase(T...args)
T find(T...args)
STL class.
T strncmp(T...args)
unsigned long System::unloadDynamicLib ( ImageHandle  handle)

unload dynamic link library

Definition at line 197 of file System.cpp.

198 {
199 #ifdef _WIN32
200  if ( !::FreeLibrary( (HINSTANCE)handle ) ) {
201 #elif defined( __linux ) || defined( __APPLE__ )
202  ::dlclose( handle );
203  if ( 0 ) {
204 #elif __hpux
205  // On HP we have to run finalization ourselves.....
206  Creator pFinalize = 0;
207  if ( getProcedureByName( handle, "_fini", &pFinalize ) ) {
208  pFinalize();
209  }
210  HMODULE* mod = (HMODULE*)handle;
211  if ( 0 == ::shl_unload( mod->dsc.handle ) ) {
212  delete mod;
213  } else {
214 #else
215  if ( false ) {
216 #endif
217  return getLastError();
218  }
219  return 1;
220 }
GAUDI_API unsigned long getLastError()
Get last system known error.
Definition: System.cpp:280
GAUDI_API unsigned long getProcedureByName(ImageHandle handle, const std::string &name, EntryPoint *pFunction)
Get a specific function defined in the DLL.
Definition: System.cpp:223
void *(* Creator)()
Definition of the "generic" DLL entry point function.
Definition: System.h:38
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 131 of file Timing.cpp.

132 {
133  static longlong sys_start = 10 * systemStart( microSec );
134  return adjustTime( typ, 10 * currentTime( microSec ) - sys_start );
135 }
GAUDI_API longlong systemStart(TimeType typ=Sec)
Maximum processing time left for this process.
Definition: Timing.cpp:119
GAUDI_API longlong currentTime()
Retrieve absolute system time.
Definition: Timing.h:269
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:37
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 185 of file Timing.cpp.

186 {
187  longlong usertime = 0;
188  KERNEL_USER_TIMES info;
189  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) {
190  usertime = adjustTime( typ, info.UserTime );
191  }
192  return usertime;
193 }
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:37
ProcessDescriptor * getProcess()
Retrieve Process structure.
long System::virtualMemory ( MemoryUnit  unit = kByte,
InfoType  fetch = Memory,
long  pid = -1 
)

Basic Process Information: priority boost.

Definition at line 239 of file Memory.cpp.

240 {
241  VM_COUNTERS info;
242  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.VirtualSize );
243  return -2;
244 }
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:34
ProcessDescriptor * getProcess()
Retrieve Process structure.
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 255 of file Memory.cpp.

256 {
257  QUOTA_LIMITS quota;
258  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) ) {
259  if ( long( quota.PagefileLimit ) == -1 ) return -1; // LONG_MAX;
260  return adjustMemory( unit, quota.PagefileLimit );
261  }
262  return 0;
263 }
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:34
ProcessDescriptor * getProcess()
Retrieve Process structure.
long System::virtualMemoryPeak ( MemoryUnit  unit = kByte,
InfoType  fetch = Memory,
long  pid = -1 
)

Basic Process Information: priority boost.

Definition at line 247 of file Memory.cpp.

248 {
249  VM_COUNTERS info;
250  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.PeakVirtualSize );
251  return -2;
252 }
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:34
ProcessDescriptor * getProcess()
Retrieve Process structure.