The Gaudi Framework  v31r0 (aeb156f0)
System Namespace Reference

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

Namespaces

 Linux
 Namespace holding Linux specific functions.
 
 MacOS
 Namespace holding MacOS specific functions.
 
 Win32
 Namespace holding Windows specific functions.
 

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 *)
 Get the human readable type name from a typeinfo name. More...
 
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 long long adjustTime (TimeType typ, long long 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 long long ellapsedTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
 Elapsed time since start of process in milliseconds. More...
 
GAUDI_API long long kernelTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
 CPU kernel mode time of process in milliseconds. More...
 
GAUDI_API long long userTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
 CPU user mode time of process in milliseconds. More...
 
GAUDI_API long long cpuTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
 Consumed CPU time of process in milliseconds. More...
 
GAUDI_API long long remainingTime (TimeType typ=milliSec, InfoType fetch=Quota, long pid=-1)
 Maximum processing time left for this process. More...
 
GAUDI_API long long creationTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
 Process Creation time. More...
 
GAUDI_API long long systemStart (TimeType typ=Sec)
 Maximum processing time left for this process. More...
 
GAUDI_API long long upTime (TimeType typ=Hour)
 Maximum processing time left for this process. More...
 
template<TimeType T>
GAUDI_API long long currentTime ()
 Retrieve absolute system time. More...
 
GAUDI_API long long currentTime (TimeType typ=milliSec)
 Get current time in specificed units. More...
 
GAUDI_API long long 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>
long long currentTime ()
 Retrieve absolute system time. More...
 
template long long currentTime< Year > ()
 
template long long currentTime< Month > ()
 
template long long currentTime< Day > ()
 
template long long currentTime< Hour > ()
 
template long long currentTime< Min > ()
 
template long long currentTime< Sec > ()
 
template long long currentTime< milliSec > ()
 
template long long currentTime< microSec > ()
 
template long long currentTime< nanoSec > ()
 
template long long 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 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 108 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 18 of file SystemBase.h.

Unit of memory.

Enumerator
Byte 
kByte 
MByte 
GByte 
TByte 
PByte 
EByte 

Definition at line 55 of file Memory.h.

Enumerator
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 37 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 22 of file ProcessDescriptor.cpp.

22  {
36  ProcessIoPortHandlers, // Note: this is kernel mode only
48  };

Time type for conversion.

Enumerator
Year 
Month 
Day 
Hour 
Min 
Sec 
milliSec 
microSec 
nanoSec 
Native 

Definition at line 57 of file Timing.h.

Function Documentation

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

User login name.

User login name.

Definition at line 343 of file System.cpp.

343  {
344  static const std::string account = Platform::accountName();
345  return account;
346 }
GAUDI_API const std::string & accountName()
User login name.
Definition: System.cpp:343
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.

34  {
35  if ( value != -1 ) {
36  switch ( unit ) {
37  case Byte:
38  break;
39  case kByte:
40  value = value / 1024;
41  break;
42  case MByte:
43  value = ( value / 1024 ) / 1024;
44  break;
45  case GByte:
46  value = ( ( value / 1024 ) / 1024 ) / 1024;
47  break;
48  case TByte:
49  value = ( ( ( value / 1024 ) / 1024 ) / 1024 ) / 1024;
50  break;
51  case PByte:
52  value = ( ( ( ( value / 1024 ) / 1024 ) / 1024 ) / 1024 ) / 1024;
53  break;
54  case EByte:
55  value = ( ( ( ( ( value / 1024 ) / 1024 ) / 1024 ) / 1024 ) / 1024 ) / 1024;
56  break;
57  default:
58  value = -1;
59  break;
60  }
61  }
62  return value;
63 }
long long System::adjustTime ( TimeType  typ,
long long  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:
50  return adjustTime<Year>( t );
51  case Month:
52  return adjustTime<Month>( t );
53  case Day:
54  return adjustTime<Day>( t );
55  case Hour:
56  return adjustTime<Hour>( t );
57  case Min:
58  return adjustTime<Min>( t );
59  case Sec:
60  return adjustTime<Sec>( t );
61  case milliSec:
62  return adjustTime<milliSec>( t );
63  case microSec:
64  return adjustTime<microSec>( t );
65  case nanoSec:
66  return adjustTime<nanoSec>( t );
67  case Native:
68  return adjustTime<Native>( t );
69  default:
70  return t;
71  }
72  }
73  return t;
74 }
long long adjustTime< Native >(long long t)
Definition: Timing.h:244
long long adjustTime< Month >(long long t)
Definition: Timing.h:240
long long adjustTime< nanoSec >(long long t)
Definition: Timing.h:236
long long adjustTime< Day >(long long t)
Definition: Timing.h:212
long long adjustTime< milliSec >(long long t)
Definition: Timing.h:228
long long adjustTime< Year >(long long t)
Definition: Timing.h:208
long long adjustTime< microSec >(long long t)
Definition: Timing.h:232
long long adjustTime< Min >(long long t)
Definition: Timing.h:220
long long adjustTime< Hour >(long long t)
Definition: Timing.h:216
long long adjustTime< Sec >(long long t)
Definition: Timing.h:224
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 212 of file Timing.h.

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

Definition at line 216 of file Timing.h.

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

Definition at line 232 of file Timing.h.

232  {
233  return ( t == -1 ) ? t : t /= ( 10LL );
234  }
template<>
long long System::adjustTime< milliSec > ( long long  t)
inline

Definition at line 228 of file Timing.h.

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

Definition at line 220 of file Timing.h.

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

Definition at line 240 of file Timing.h.

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

Definition at line 236 of file Timing.h.

236  {
237  return ( t == -1 ) ? t : t *= 100LL;
238  }
template<>
long long System::adjustTime< Native > ( long long  t)
inline

Definition at line 244 of file Timing.h.

244  {
245  return t;
246  }
template<>
long long System::adjustTime< Sec > ( long long  t)
inline

Definition at line 224 of file Timing.h.

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

Definition at line 208 of file Timing.h.

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

Basic Process Information: Affinity mask.

Definition at line 86 of file Memory.cpp.

86  {
87  PROCESS_BASIC_INFORMATION info;
88  if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.AffinityMask;
89  return 0;
90 }
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 352 of file System.cpp.

352 { 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:355
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].

Definition at line 361 of file System.cpp.

361  {
362  auto helperFunc = []( const std::vector<std::string>& args ) -> std::vector<const char*> {
364  std::transform( args.begin(), args.end(), std::back_inserter( result ),
365  []( const std::string& s ) { return s.c_str(); } );
366  return result;
367  };
368  static const std::vector<const char*> args = helperFunc( cmdLineArgs() );
369  // We rely here on the fact that a vector's allocation table is contiguous
370  return (char**)&( args[0] );
371 }
STL class.
T back_inserter(T...args)
string s
Definition: gaudirun.py:312
GAUDI_API const std::vector< std::string > cmdLineArgs()
Command line arguments including executable name as arg[0] as vector of strings.
Definition: System.cpp:355
T transform(T...args)
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 437 of file System.cpp.

437  {
438  try {
439  // Always hide the first two levels of the stack trace (that's us)
440  const int totalOffset = offset + 2;
441  const int totalDepth = depth + totalOffset;
442 
443  std::string fnc, lib;
444 
445  std::vector<void*> addresses( totalDepth, nullptr );
446  int count = System::backTrace( addresses.data(), totalDepth );
447  for ( int i = totalOffset; i < count; ++i ) {
448  void* addr = nullptr;
449 
450  if ( System::getStackLevel( addresses[i], addr, fnc, lib ) ) {
451  std::ostringstream ost;
452  ost << "#" << std::setw( 3 ) << std::setiosflags( std::ios::left ) << i - totalOffset + 1;
453  ost << std::hex << addr << std::dec << " " << fnc << " [" << lib << "]" << std::endl;
454  btrace += ost.str();
455  }
456  }
457  return true;
458  } catch ( const std::bad_alloc& e ) { return false; }
459 }
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 66 of file Memory.cpp.

66  {
67  PROCESS_BASIC_INFORMATION info;
68  if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.BasePriority;
69  return 0;
70 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
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 return 1;
50 #else
51  // I have no clue how to do this in linux
52  return 0;
53 #endif
54 }
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 57 of file Debugger.cpp.

57  {
58 #ifdef _WIN32
59  long result = 0;
60  if ( pid == Win::_getpid() ) {
61  _asm int 3 return 1;
62  } else {
63  Win::LPTHREAD_START_ROUTINE fun;
64  Win::HANDLE th, ph;
65  Win::HINSTANCE mh;
66  Win::DWORD id;
67  mh = Win::LoadLibrary( "Kernel32" );
68  if ( 0 != mh ) {
69  fun = (Win::LPTHREAD_START_ROUTINE)Win::GetProcAddress( mh, "DebugBreak" );
70  if ( 0 != fun ) {
71  ph = Win::OpenProcess( PROCESS_ALL_ACCESS, TRUE, pid );
72  if ( 0 != ph ) {
73  th = Win::CreateRemoteThread( ph, NULL, 0, fun, 0, 0, &id );
74  if ( 0 != th ) {
75  Win::CloseHandle( th );
76  result = 1;
77  }
78  Win::CloseHandle( ph );
79  }
80  }
81  Win::FreeLibrary( mh );
82  }
83  }
84  if ( result != 1 ) result = Win::GetLastError();
85  return result;
86 #else
87  // I have no clue how to do this in linux
88  return pid;
89 #endif
90 }
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].

Command line arguments including executable name as arg[0] as vector of strings.

Definition at line 355 of file System.cpp.

355  {
357  return args;
358 }
GAUDI_API const std::vector< std::string > cmdLineArgs()
Command line arguments including executable name as arg[0] as vector of strings.
Definition: System.cpp:355
long long 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 186 of file Timing.cpp.

186  {
187  long long cputime = 0;
188  KERNEL_USER_TIMES info;
189  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) {
190  cputime = adjustTime( typ, info.KernelTime + info.UserTime );
191  }
192  return cputime;
193 }
GAUDI_API long long adjustTime(TimeType typ, long long timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:37
ProcessDescriptor * getProcess()
Retrieve Process structure.
long long 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 135 of file Timing.cpp.

135  {
136  long long created = 0;
137  KERNEL_USER_TIMES info;
138  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) {
139  created = adjustTime( typ, info.CreateTime - UNIX_BASE_TIME );
140  }
141  return created;
142 }
GAUDI_API long long adjustTime(TimeType typ, long long 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 long long 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 250 of file Timing.h.

250  {
251 #ifdef _WIN32
252  long long current = 0;
253  ::GetSystemTimeAsFileTime( (FILETIME*)&current );
254  return adjustTime<T>( current - UNIX_BASE_TIME );
255 #else
256  struct timeval tv;
257  ::gettimeofday( &tv, 0 );
258  return adjustTime<T>( ( tv.tv_sec * 1000000 + tv.tv_usec ) * 10 );
259 #endif
260  }
long long System::currentTime ( TimeType  typ = milliSec)

Get current time in specificed units.

Retrieve current system time.

Definition at line 91 of file Timing.cpp.

91  {
92  switch ( typ ) {
93  case Year:
94  return currentTime<Year>();
95  case Month:
96  return currentTime<Month>();
97  case Day:
98  return currentTime<Day>();
99  case Hour:
100  return currentTime<Hour>();
101  case Min:
102  return currentTime<Min>();
103  case Sec:
104  return currentTime<Sec>();
105  case milliSec:
106  return currentTime<milliSec>();
107  case microSec:
108  return currentTime<microSec>();
109  case nanoSec:
110  return currentTime<nanoSec>();
111  case Native:
112  return currentTime<Native>();
113  }
114  return currentTime<Native>();
115 }
template long long currentTime< Month >()
template long long currentTime< Year >()
template long long currentTime< Hour >()
template long long currentTime< Sec >()
template long long currentTime< Min >()
template long long currentTime< Native >()
template long long currentTime< milliSec >()
template long long currentTime< Day >()
template long long currentTime< nanoSec >()
template long long currentTime< microSec >()
template<TimeType T>
long long 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 250 of file Timing.h.

250  {
251 #ifdef _WIN32
252  long long current = 0;
253  ::GetSystemTimeAsFileTime( (FILETIME*)&current );
254  return adjustTime<T>( current - UNIX_BASE_TIME );
255 #else
256  struct timeval tv;
257  ::gettimeofday( &tv, 0 );
258  return adjustTime<T>( ( tv.tv_sec * 1000000 + tv.tv_usec ) * 10 );
259 #endif
260  }
template long long System::currentTime< Day > ( )
template long long System::currentTime< Hour > ( )
template long long System::currentTime< microSec > ( )
template long long System::currentTime< milliSec > ( )
template long long System::currentTime< Min > ( )
template long long System::currentTime< Month > ( )
template long long System::currentTime< nanoSec > ( )
template long long System::currentTime< Native > ( )
template long long System::currentTime< Sec > ( )
template long long System::currentTime< Year > ( )
long long 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 159 of file Timing.cpp.

159  {
160  KERNEL_USER_TIMES info;
161  long long ellapsed = currentTime( microSec ) * 10;
162  getProcess()->query( pid, fetch, &info );
163  ellapsed = adjustTime( typ, ellapsed + UNIX_BASE_TIME - info.CreateTime );
164  return ellapsed;
165 }
GAUDI_API long long currentTime()
Retrieve absolute system time.
Definition: Timing.h:250
GAUDI_API long long adjustTime(TimeType typ, long long 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 158 of file ModuleInfo.cpp.

158  {
159 #ifdef _WIN32
160  if ( processHandle() ) {
161  static HINSTANCE handle = 0;
162  DWORD cbNeeded;
163  if ( 0 == handle && _psApi ) {
164  if ( _psApi.EnumProcessModules( processHandle(), &handle, sizeof( ModuleHandle ), &cbNeeded ) ) {}
165  }
166  return handle;
167  }
168  return 0;
169 #elif defined( __linux ) || defined( __APPLE__ )
170  // This does NOT work!
171  static Dl_info infoBuf, *info = &infoBuf;
172  if ( !info ) {
173  void* handle = ::dlopen( nullptr, RTLD_LAZY );
174  // printf("Exe handle:%X\n", handle);
175  if ( handle ) {
176  void* func = ::dlsym( handle, "main" );
177  // printf("Exe:Func handle:%X\n", func);
178  if ( func ) {
179  if ( 0 != ::dladdr( func, &infoBuf ) ) {
180  // std::cout << "All OK" << std::endl;
181  info = &infoBuf;
182  }
183  }
184  }
185  }
186  return info;
187 #elif __hpux
188  // Don't know how to solve this .....
189  return 0;
190 #endif
191 }
GAUDI_API ProcessHandle processHandle()
Handle to running process.
Definition: ModuleInfo.cpp:125
const std::string & System::exeName ( )

Name of the executable file running.

Definition at line 193 of file ModuleInfo.cpp.

193  {
194  static std::string module( "" );
195  if ( module.length() == 0 ) {
196  char name[PATH_MAX] = {"Unknown.module"};
197  name[0] = 0;
198 #ifdef _WIN32
199  if ( _psApi && processHandle() ) {
200  _psApi.GetModuleFileNameExA( processHandle(), (HINSTANCE)exeHandle(), name, sizeof( name ) );
201  module = name;
202  }
203 #elif defined( __linux ) || defined( __APPLE__ )
204  char cmd[512];
205  ::sprintf( cmd, "/proc/%d/exe", ::getpid() );
206  module = "Unknown";
207  if ( ::readlink( cmd, name, sizeof( name ) ) >= 0 ) module = name;
208 #elif __hpux
209  if ( ::realpath( ( (HMODULE*)exeHandle() )->dsc.filename, name ) ) module = name;
210 #endif
211  }
212  return module;
213 }
GAUDI_API ProcessHandle processHandle()
Handle to running process.
Definition: ModuleInfo.cpp:125
STL class.
GAUDI_API ImageHandle exeHandle()
Handle to the executable file running.
Definition: ModuleInfo.cpp:158
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 93 of file Memory.cpp.

93  {
94  PROCESS_BASIC_INFORMATION info;
95  if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.ExitStatus;
96  return -2;
97 }
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 380 of file System.cpp.

380  {
381  char* env;
382  if ( ( env = getenv( var ) ) != nullptr ) {
383  return env;
384  } else {
385  return "UNKNOWN";
386  }
387 }
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 390 of file System.cpp.

390  {
391  char* env;
392  if ( ( env = getenv( var ) ) != nullptr ) {
393  value = env;
394  return true;
395  } else {
396  return false;
397  }
398 }
T getenv(T...args)
bool System::getEnv ( const std::string var,
std::string value 
)
inline

Definition at line 90 of file System.h.

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

get all environment variables

get all defined environment vars

Definition at line 407 of file System.cpp.

407  {
408 #if defined( _WIN32 )
409 # define environ _environ
410 #elif defined( __APPLE__ )
411  static char** environ = *_NSGetEnviron();
412 #endif
414  for ( int i = 0; environ[i] != nullptr; ++i ) { vars.push_back( environ[i] ); }
415  return vars;
416 }
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 279 of file System.cpp.

279  {
280  std::string errString = "";
281 #ifdef _WIN32
282  LPVOID lpMessageBuffer;
283  ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, error,
284  MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), // The user default language
285  (LPTSTR)&lpMessageBuffer, 0, NULL );
286  errString = (const char*)lpMessageBuffer;
287  // Free the buffer allocated by the system
288  ::LocalFree( lpMessageBuffer );
289 #else
290  char* cerrString( nullptr );
291  // Remember: for linux dl* routines must be handled differently!
292  if ( error == 0xAFFEDEAD ) {
293  cerrString = ::dlerror();
294  if ( !cerrString ) cerrString = ::strerror( error );
295  if ( !cerrString ) {
296  cerrString = (char*)"Unknown error. No information found in strerror()!";
297  } else {
298  errString = std::string( cerrString );
299  }
300  errno = 0;
301  } else {
302  cerrString = ::strerror( error );
303  errString = std::string( cerrString );
304  }
305 #endif
306  return errString;
307 }
STL class.
unsigned long System::getLastError ( )

Get last system known error.

Retrieve last error code.

Definition at line 263 of file System.cpp.

263  {
264 #ifdef _WIN32
265  return ::GetLastError();
266 #else
267  // convert errno (int) to unsigned long
268  return static_cast<unsigned long>( static_cast<unsigned int>( errno ) );
269 #endif
270 }
const std::string System::getLastErrorString ( )

Get last system error as string.

Retrieve last error code as string.

Definition at line 273 of file System.cpp.

273  {
274  const std::string errString = getErrorString( getLastError() );
275  return errString;
276 }
GAUDI_API const std::string getErrorString(unsigned long error)
Retrieve error code as string for a given error.
Definition: System.cpp:279
GAUDI_API unsigned long getLastError()
Get last system known error.
Definition: System.cpp:263
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 214 of file System.cpp.

214  {
215 #ifdef _WIN32
216  *pFunction = ( EntryPoint )::GetProcAddress( (HINSTANCE)handle, name.data() );
217  if ( 0 == *pFunction ) { return System::getLastError(); }
218  return 1;
219 #elif defined( __linux )
220  *pFunction = reinterpret_cast<EntryPoint>( ::dlsym( handle, name.c_str() ) );
221  if ( !*pFunction ) {
222  errno = 0xAFFEDEAD;
223  // std::cout << "System::getProcedureByName>" << getLastErrorString() << std::endl;
224  return 0;
225  }
226  return 1;
227 #elif defined( __APPLE__ )
228  *pFunction = ( EntryPoint )::dlsym( handle, name.c_str() );
229  if ( !( *pFunction ) ) {
230  // Try with an underscore :
231  std::string sname = "_" + name;
232  *pFunction = ( EntryPoint )::dlsym( handle, sname.c_str() );
233  }
234  if ( 0 == *pFunction ) {
235  errno = 0xAFFEDEAD;
236  std::cout << "System::getProcedureByName>" << getLastErrorString() << std::endl;
237  // std::cout << "System::getProcedureByName> failure" << std::endl;
238  return 0;
239  }
240  return 1;
241 #elif __hpux
242  HMODULE* mod = (HMODULE*)handle;
243  if ( 0 != mod ) {
244  long ll1 = name.length();
245  for ( int i = 0; i < mod->numSym; i++ ) {
246  long ll2 = strlen( mod->sym[i].name );
247  if ( 0 != ::strncmp( mod->sym[i].name, name.c_str(), ( ll1 > ll2 ) ? ll1 : ll2 ) == 0 ) {
248  *pFunction = (EntryPoint)mod->sym[i].value;
249  return 1;
250  }
251  }
252  }
253  return 0;
254 #endif
255 }
GAUDI_API unsigned long getLastError()
Get last system known error.
Definition: System.cpp:263
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:273
unsigned long(* EntryPoint)(const unsigned long iid, void **ppvObject)
Definition of the "generic" DLL entry point function.
Definition: System.h:35
unsigned long System::getProcedureByName ( ImageHandle  handle,
const std::string name,
Creator pFunction 
)

Get a specific function defined in the DLL.

Definition at line 258 of file System.cpp.

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

Retrieve Process structure.

Definition at line 132 of file ProcessDescriptor.h.

132  {
133  static ProcessDescriptor p;
134  return &p;
135  }
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 196 of file Timing.cpp.

196  {
197  KERNEL_USER_TIMES info;
198  if ( getProcess()->query( pid, Times, &info ) ) {
199  return ProcessTime( info.KernelTime, info.UserTime, currentTime<Native>() - info.CreateTime );
200  }
201  return ProcessTime(); // return 0s in case of problems
202  }
template long long 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 54 of file Environment.cpp.

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

Host name.

Host name.

Definition at line 314 of file System.cpp.

314  {
315  static const std::string host = Platform::hostName();
316  return host;
317 }
STL class.
GAUDI_API const std::string & hostName()
Host name.
Definition: System.cpp:314
int System::instructionsetLevel ( )

Instruction Set "Level".

Definition at line 337 of file System.cpp.

337  {
338  using namespace Gaudi;
339  return instrset_detect();
340 }
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 400 of file System.cpp.

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

168  {
169  KERNEL_USER_TIMES info;
170  long long kerneltime = 0;
171  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) {
172  kerneltime = adjustTime( typ, info.KernelTime );
173  }
174  return kerneltime;
175 }
GAUDI_API long long adjustTime(TimeType typ, long long 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 215 of file ModuleInfo.cpp.

215  {
216  if ( s_linkedModules.size() == 0 ) {
217 #ifdef _WIN32
218  char name[255]; // Maximum file name length on NT 4.0
219  DWORD cbNeeded;
220  HINSTANCE handle[1024];
221  if ( _psApi ) {
222  if ( _psApi.EnumProcessModules( processHandle(), handle, sizeof( handle ), &cbNeeded ) ) {
223  for ( size_t i = 0; i < cbNeeded / sizeof( HANDLE ); i++ ) {
224  if ( 0 < _psApi.GetModuleFileNameExA( processHandle(), handle[i], name, sizeof( name ) ) ) {
225  s_linkedModules.push_back( name );
226  }
227  }
228  }
229  }
230 #elif defined( __linux ) || defined( __APPLE__ )
231  char ff[512], cmd[1024], fname[1024], buf1[64], buf2[64], buf3[64], buf4[64];
232  ::sprintf( ff, "/proc/%d/maps", ::getpid() );
233  FILE* maps = ::fopen( ff, "r" );
234  while ( ::fgets( cmd, sizeof( cmd ), maps ) ) {
235  int len;
236  sscanf( cmd, "%s %s %s %s %d %s", buf1, buf2, buf3, buf4, &len, fname );
237  if ( len > 0 && strncmp( buf2, "r-xp", strlen( "r-xp" ) ) == 0 ) { s_linkedModules.push_back( fname ); }
238  }
239  ::fclose( maps );
240 #endif
241  }
242  return s_linkedModules;
243 }
T sscanf(T...args)
T fgets(T...args)
GAUDI_API ProcessHandle processHandle()
Handle to running process.
Definition: ModuleInfo.cpp:125
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 146 of file System.cpp.

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

Machine type.

Definition at line 332 of file System.cpp.

332  {
333  static const std::string mach = Platform::machineType();
334  return mach;
335 }
STL class.
GAUDI_API const std::string & machineType()
Machine type.
Definition: System.cpp:332
long System::mappedMemory ( MemoryUnit  unit = kByte,
InfoType  fetch = Memory,
long  pid = -1 
)

Basic Process Information: priority boost.

Definition at line 187 of file Memory.cpp.

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

194  {
195  VM_COUNTERS info;
196  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
197  return adjustMemory( unit, info.PeakWorkingSetSize );
198  return -2;
199 }
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 210 of file Memory.cpp.

210  {
211  QUOTA_LIMITS quota;
212  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
213  return adjustMemory( unit, quota.MaximumWorkingSetSize );
214  return 0;
215 }
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 202 of file Memory.cpp.

202  {
203  QUOTA_LIMITS quota;
204  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
205  return adjustMemory( unit, quota.MinimumWorkingSetSize );
206  return 0;
207 }
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 137 of file ModuleInfo.cpp.

137  {
138  if ( !ModuleHandle ) {
139  if ( processHandle() ) {
140 #ifdef _WIN32
141  static HINSTANCE handle = 0;
142  DWORD cbNeeded;
143  if ( 0 == handle && _psApi ) {
144  if ( _psApi.EnumProcessModules( processHandle(), &handle, sizeof( ModuleHandle ), &cbNeeded ) ) {}
145  }
146  return handle;
147 #elif defined( __linux ) || defined( __APPLE__ )
148  static Dl_info info;
149  if ( ::dladdr( reinterpret_cast<void*>( System::moduleHandle ), &info ) ) return &info;
150 #elif __hpux
151  return 0; // Don't know how to solve this .....
152 #endif
153  }
154  }
155  return ModuleHandle;
156 }
GAUDI_API ProcessHandle processHandle()
Handle to running process.
Definition: ModuleInfo.cpp:125
GAUDI_API ImageHandle moduleHandle()
Handle to currently executed module.
Definition: ModuleInfo.cpp:137
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  }
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 }
T rfind(T...args)
GAUDI_API ProcessHandle processHandle()
Handle to running process.
Definition: ModuleInfo.cpp:125
STL class.
GAUDI_API ImageHandle moduleHandle()
Handle to currently executed module.
Definition: ModuleInfo.cpp:137
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 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 ) ) module = name;
96 #endif
97  }
98  }
99  return module;
100 }
GAUDI_API ProcessHandle processHandle()
Handle to running process.
Definition: ModuleInfo.cpp:125
STL class.
GAUDI_API ImageHandle moduleHandle()
Handle to currently executed module.
Definition: ModuleInfo.cpp:137
System::ModuleType System::moduleType ( )

Get type of the module.

Definition at line 103 of file ModuleInfo.cpp.

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

115  {
116  VM_COUNTERS info;
117  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
118  return adjustMemory( unit, info.QuotaNonPagedPoolUsage );
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::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 123 of file Memory.cpp.

123  {
124  POOLED_USAGE_AND_LIMITS quota;
125  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
126  return adjustMemory( unit, quota.NonPagedPoolLimit );
127  return 0;
128 }
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 107 of file Memory.cpp.

107  {
108  VM_COUNTERS info;
109  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
110  return adjustMemory( unit, info.QuotaPeakNonPagedPoolUsage );
111  return -2;
112 }
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 349 of file System.cpp.

349 { 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:355
long System::numPageFault ( InfoType  fetch = Memory,
long  pid = -1 
)

Basic Process Information: Number of page faults.

Basic Process Information: priority boost.

Definition at line 155 of file Memory.cpp.

155  {
156  VM_COUNTERS info;
157  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return info.PageFaultCount;
158  return -2;
159 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
const std::string & System::osName ( )

OS name.

OS name.

Definition at line 320 of file System.cpp.

320  {
321  static const std::string osname = Platform::osName();
322  return osname;
323 }
STL class.
GAUDI_API const std::string & osName()
OS name.
Definition: System.cpp:320
const std::string & System::osVersion ( )

OS version.

OS version.

Definition at line 326 of file System.cpp.

326  {
327  static const std::string osver = Platform::osVersion();
328  return osver;
329 }
STL class.
GAUDI_API const std::string & osVersion()
OS version.
Definition: System.cpp:326
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 131 of file Memory.cpp.

131  {
132  VM_COUNTERS info;
133  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
134  return adjustMemory( unit, info.QuotaPagedPoolUsage );
135  return -2;
136 }
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 147 of file Memory.cpp.

147  {
148  POOLED_USAGE_AND_LIMITS quota;
149  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
150  return adjustMemory( unit, quota.PagedPoolLimit );
151  return 0;
152 }
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 139 of file Memory.cpp.

139  {
140  VM_COUNTERS info;
141  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
142  return adjustMemory( unit, info.QuotaPeakPagedPoolUsage );
143  return -2;
144 }
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 162 of file Memory.cpp.

162  {
163  VM_COUNTERS info;
164  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.PagefileUsage );
165  return -2;
166 }
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 177 of file Memory.cpp.

177  {
178  POOLED_USAGE_AND_LIMITS quota;
179  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) ) {
180  if ( long( quota.PagefileLimit ) < 0 ) return -1; // LONG_MAX;
181  return adjustMemory( unit, quota.PagefileLimit );
182  }
183  return -2;
184 }
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 169 of file Memory.cpp.

169  {
170  VM_COUNTERS info;
171  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
172  return adjustMemory( unit, info.PeakPagefileUsage );
173  return -2;
174 }
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 79 of file Memory.cpp.

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

Definition at line 187 of file PathResolver.cpp.

187  {
188  return PathResolver::find_file( logical_file_name, "DATAPATH" );
189  }
std::string System::PathResolverFindXMLFile ( const std::string logical_file_name)

Definition at line 183 of file PathResolver.cpp.

183  {
184  return PathResolver::find_file( logical_file_name, "XMLPATH" );
185  }
long System::priorityBoost ( InfoType  fetch = PriorityBoost,
long  pid = -1 
)

Basic Process Information: priority boost.

Definition at line 100 of file Memory.cpp.

100  {
101  long info;
102  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return info;
103  return -2;
104 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
void * System::processHandle ( )

Handle to running process.

Retrieve processhandle.

Definition at line 125 of file ModuleInfo.cpp.

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

Basic Process Information: Process ID.

Definition at line 73 of file Memory.cpp.

73  {
74  static const long s_pid = ::getpid();
75  return s_pid;
76 }
long long 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 145 of file Timing.cpp.

145  {
146  long long left = 0;
147  QUOTA_LIMITS quota;
148  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) ) {
149  if ( left == -1 ) {
150  // left = _I64_MAX;
151  } else {
152  left = adjustTime( typ, quota.TimeLimit );
153  }
154  }
155  return left;
156 }
T left(T...args)
GAUDI_API long long adjustTime(TimeType typ, long long 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 47 of file Environment.cpp.

47  {
48  std::string source = var;
49  res = i_resolve( source, recursions );
50  if ( res.find( "${" ) == std::string::npos ) { return StatusCode::SUCCESS; }
51  return StatusCode::FAILURE;
52 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
STL class.
T find(T...args)
constexpr static const auto FAILURE
Definition: StatusCode.h:86
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 494 of file System.cpp.

494  {
495 #ifndef WIN32
496  // UNIX version
497  return value.empty() ?
498  // remove if set to nothing (and return success)
499  ::unsetenv( name.c_str() ),
500  0 :
501  // set the value
502  ::setenv( name.c_str(), value.c_str(), overwrite );
503 #else
504  // Windows version
505  if ( value.empty() ) {
506  // equivalent to unsetenv
507  return ::_putenv( ( name + "=" ).c_str() );
508  } else {
509  if ( !getenv( name.c_str() ) || overwrite ) {
510  // set if not yet present or overwrite is set (force)
511  return ::_putenv( ( name + "=" + value ).c_str() );
512  }
513  }
514  return 0; // if we get here, we are trying to set a variable already set, but
515  // not to overwrite.
516  // It is considered a success on Linux (man P setenv)
517 #endif
518 }
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 135 of file ModuleInfo.cpp.

135 { ModuleHandle = handle; }
long long 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 118 of file Timing.cpp.

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

Definition at line 70 of file Environment.cpp.

70  {
71  // Return a user configured or systemwide directory to create
72  // temporary files in.
73  std::string dir;
74  if ( System::getEnv( "TEMP", dir ) || System::getEnv( "TEMPDIR", dir ) || System::getEnv( "TEMP_DIR", dir ) ||
75  System::getEnv( "TMP", dir ) || System::getEnv( "TMPDIR", dir ) || System::getEnv( "TMP_DIR", dir ) )
76  return dir;
77  else
78  return homeDirectory();
79 }
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:380
GAUDI_API std::string homeDirectory()
Definition: Environment.cpp:54
STL class.
ThreadHandle System::threadSelf ( )
inline

thread handle "accessor"

Definition at line 110 of file System.h.

110 { return (void*)0; }
long long System::tickCount ( )

Retrieve the number of ticks since system startup.

Returns
Requested value in the indicated units.

Definition at line 77 of file Timing.cpp.

77  {
78  long long 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 309 of file System.cpp.

309 { 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:309
T name(T...args)
const std::string System::typeinfoName ( const char *  class_name)

Get the human readable type name from a typeinfo name.

Definition at line 311 of file System.cpp.

311 { return Platform::typeinfoName( class_name ); }
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:309
unsigned long System::unloadDynamicLib ( ImageHandle  handle)

unload dynamic link library

Definition at line 191 of file System.cpp.

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

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

178  {
179  long long usertime = 0;
180  KERNEL_USER_TIMES info;
181  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) { usertime = adjustTime( typ, info.UserTime ); }
182  return usertime;
183 }
GAUDI_API long long adjustTime(TimeType typ, long long 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 218 of file Memory.cpp.

218  {
219  VM_COUNTERS info;
220  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.VirtualSize );
221  return -2;
222 }
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 232 of file Memory.cpp.

232  {
233  QUOTA_LIMITS quota;
234  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) ) {
235  if ( long( quota.PagefileLimit ) == -1 ) return -1; // LONG_MAX;
236  return adjustMemory( unit, quota.PagefileLimit );
237  }
238  return 0;
239 }
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 225 of file Memory.cpp.

225  {
226  VM_COUNTERS info;
227  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.PeakVirtualSize );
228  return -2;
229 }
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.