All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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::string & moduleName ()
 Get the name of the (executable/DLL) file without file-type. More...
 
GAUDI_API const std::string & moduleNameFull ()
 Get the full name of the (executable/DLL) file. More...
 
GAUDI_API ModuleType moduleType ()
 Get type of the module. More...
 
GAUDI_API ProcessHandle processHandle ()
 Handle to running process. More...
 
GAUDI_API ImageHandle moduleHandle ()
 Handle to currently executed module. More...
 
GAUDI_API ImageHandle exeHandle ()
 Handle to the executable file running. More...
 
GAUDI_API const std::string & exeName ()
 Name of the executable file running. More...
 
GAUDI_API const std::vector
< std::string > 
linkedModules ()
 Vector of names of linked modules. More...
 
GAUDI_API void setModuleHandle (ImageHandle handle)
 Attach module handle. More...
 
GAUDI_API std::string PathResolverFindXMLFile (const std::string &logical_file_name)
 
GAUDI_API std::string PathResolverFindDataFile (const std::string &logical_file_name)
 
GAUDI_API unsigned long loadDynamicLib (const std::string &name, ImageHandle *handle)
 Load dynamic link library. More...
 
GAUDI_API unsigned long unloadDynamicLib (ImageHandle handle)
 unload dynamic link library More...
 
GAUDI_API unsigned long getProcedureByName (ImageHandle handle, const std::string &name, EntryPoint *pFunction)
 Get a specific function defined in the DLL. More...
 
GAUDI_API unsigned long getProcedureByName (ImageHandle handle, const std::string &name, Creator *pFunction)
 Get a specific function defined in the DLL. More...
 
GAUDI_API unsigned long getLastError ()
 Get last system known error. More...
 
GAUDI_API const std::string getLastErrorString ()
 Get last system error as string. More...
 
GAUDI_API const std::string getErrorString (unsigned long error)
 Retrieve error code as string for a given error. More...
 
GAUDI_API const std::string typeinfoName (const std::type_info &)
 Get platform independent information about the class type. More...
 
GAUDI_API const std::string typeinfoName (const char *)
 
GAUDI_API const std::string & hostName ()
 Host name. More...
 
GAUDI_API const std::string & osName ()
 OS name. More...
 
GAUDI_API const std::string & osVersion ()
 OS version. More...
 
GAUDI_API const std::string & machineType ()
 Machine type. More...
 
GAUDI_API const std::string & accountName ()
 User login name. More...
 
GAUDI_API long numCmdLineArgs ()
 Number of arguments passed to the commandline. More...
 
GAUDI_API long argc ()
 Number of arguments passed to the commandline (==numCmdLineArgs()); just to match argv call... More...
 
GAUDI_API const std::vector
< std::string > 
cmdLineArgs ()
 Command line arguments including executable name as arg[0] as vector of strings. More...
 
GAUDI_API char ** argv ()
 char** command line arguments including executable name as arg[0]; You may not modify them! More...
 
GAUDI_API std::string getEnv (const char *var)
 get a particular environment variable (returning "UNKNOWN" if not set) More...
 
GAUDI_API bool getEnv (const char *var, std::string &value)
 get a particular environment variable, storing the value in the passed string if the variable is set. More...
 
bool getEnv (const std::string &var, std::string &value)
 
GAUDI_API std::vector
< std::string > 
getEnv ()
 get all environment variables More...
 
GAUDI_API int setEnv (const std::string &name, const std::string &value, int overwrite=1)
 Set an environment variables. More...
 
GAUDI_API bool isEnvSet (const char *var)
 Check if an environment variable is set or not. More...
 
ThreadHandle threadSelf ()
 thread handle "accessor" More...
 
GAUDI_API int backTrace (void **addresses, const int depth)
 
GAUDI_API bool backTrace (std::string &btrace, const int depth, const int offset=0)
 
GAUDI_API bool getStackLevel (void *addresses, void *&addr, std::string &fnc, std::string &lib)
 
GAUDI_API longlong adjustTime (TimeType typ, longlong timevalue)
 Convert time from OS native time to requested representation (Experts only) More...
 
template<TimeType T>
long long adjustTime (long long timevalue)
 Convert the time from OS native time to requested representation (Experts only) More...
 
GAUDI_API longlong ellapsedTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
 Elapsed time since start of process in milliseconds. More...
 
GAUDI_API longlong kernelTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
 CPU kernel mode time of process in milliseconds. More...
 
GAUDI_API longlong userTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
 CPU user mode time of process in milliseconds. More...
 
GAUDI_API longlong cpuTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
 Consumed CPU time of process in milliseconds. More...
 
GAUDI_API longlong remainingTime (TimeType typ=milliSec, InfoType fetch=Quota, long pid=-1)
 Maximum processing time left for this process. More...
 
GAUDI_API longlong creationTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
 Process Creation time. More...
 
GAUDI_API longlong systemStart (TimeType typ=Sec)
 Maximum processing time left for this process. More...
 
GAUDI_API longlong upTime (TimeType typ=Hour)
 Maximum processing time left for this process. More...
 
GAUDI_API longlong currentTime (TimeType typ=milliSec)
 Retrieve absolute system time. More...
 
GAUDI_API longlong tickCount ()
 Retrieve the number of ticks since system startup. More...
 
GAUDI_API ProcessTime getProcessTime (long pid=-1)
 Retrieve the process time data for a process. More...
 
template<>
long long adjustTime< Year > (long long t)
 
template<>
long long adjustTime< Day > (long long t)
 
template<>
long long adjustTime< Hour > (long long t)
 
template<>
long long adjustTime< Min > (long long t)
 
template<>
long long adjustTime< Sec > (long long t)
 
template<>
long long adjustTime< milliSec > (long long t)
 
template<>
long long adjustTime< microSec > (long long t)
 
template<>
long long adjustTime< nanoSec > (long long t)
 
template<>
long long adjustTime< Month > (long long t)
 
template<>
long long adjustTime< Native > (long long t)
 
ProcessDescriptorgetProcess ()
 Retrieve Process structure. More...
 

Detailed Description

Note: OS specific details for environment resolution.

Note: OS specific details for process timing.

Note: OS specific details as well as Gaudi details may not occur in this definition file, because this header is the used by both, the OS specific implementations and the gaudi specific implementation.

ModuleInfo: OS specific details to access at run-time the module configuration of the process.

Note: OS specific details for memory usage.

Entrypoints:

Author
: M.Frank
Version
: 1.0

Entrypoints:

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

M.Frank

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

Author
M.Frank

Entrypoints:

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

On Windows NT Time is expressed as the amount of time that has elapsed since midnight on January 1, 1601 at Greenwich, England.

On Unix time is expressed as the amount of time that has elapsed since midnight on January 1, 1970 at Greenwich, England.

History :

+---------+----------------------------------------------+--------+
|    Date |                 Comment                      | Who    |
+---------+----------------------------------------------+--------+
| 11/11/00| Initial version.                             | MF     |
+---------+----------------------------------------------+--------+
Author
: M.Frank
Version
: 1.0

Typedef Documentation

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

Definition of the "generic" DLL entry point function.

Definition at line 38 of file System.h.

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

Definition of the "generic" DLL entry point function.

Definition at line 36 of file System.h.

typedef void * System::ImageHandle

Definition of an image handle.

Definition at line 30 of file ModuleInfo.h.

typedef struct _PEB* System::PPEB

Basic Process Information NtQueryInformationProcess using ProcessBasicInfo.

Definition at line 18 of file ProcessDescriptor.h.

typedef void * System::ProcessHandle

Definition of the process handle.

Definition at line 32 of file ModuleInfo.h.

typedef void* System::ThreadHandle

A Thread handle.

Definition at line 99 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 57 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 40 of file PathResolver.cpp.

Enumerator
ProcessBasicInformation 
ProcessQuotaLimits 
ProcessIoCounters 
ProcessVmCounters 
ProcessTimes 
ProcessBasePriority 
ProcessRaisePriority 
ProcessDebugPort 
ProcessExceptionPort 
ProcessAccessToken 
ProcessLdtInformation 
ProcessLdtSize 
ProcessDefaultHardErrorMode 
ProcessIoPortHandlers 
ProcessPooledUsageAndLimits 
ProcessWorkingSetWatch 
ProcessUserModeIOPL 
ProcessEnableAlignmentFaultFixup 
ProcessPriorityClass 
ProcessWx86Information 
ProcessHandleCount 
ProcessAffinityMask 
ProcessPriorityBoost 
MaxProcessInfoClass 
ProcessEllapsedTime 

Definition at line 20 of file ProcessDescriptor.cpp.

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

Time type for conversion.

Enumerator
Year 
Month 
Day 
Hour 
Min 
Sec 
milliSec 
microSec 
nanoSec 
Native 

Definition at line 51 of file Timing.h.

Function Documentation

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

User login name.

Definition at line 502 of file System.cpp.

502  {
503  static std::string account = "";
504  if ( account == "" ) {
505 #ifdef _WIN32
506  char buffer[512];
507  unsigned long buflen = sizeof(buffer);
508  ::GetUserName(buffer, &buflen);
509  account = buffer;
510 #else
511  const char* acct = ::getlogin();
512  if ( 0 == acct ) acct = ::getenv("LOGNAME");
513  if ( 0 == acct ) acct = ::getenv("USER");
514  account = (acct) ? acct : "Unknown";
515 #endif
516  }
517  return account;
518 }
long System::adjustMemory ( MemoryUnit  typ,
long  value 
)

Convert time from kByte to requested representation (Experts only)

Convert requested memory value from kByte to requested value.

Definition at line 35 of file Memory.cpp.

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

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

unfortunately "-ansi" flag turn off the correct definition of CLK_TCK and forces it to be equal CLOCKS_PER_SEC, it is wrong!

t /= CLOCKS_PER_SEC; // needs division by clock tick unit

Definition at line 38 of file Timing.cpp.

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

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

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

Definition at line 187 of file Timing.h.

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

Definition at line 191 of file Timing.h.

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

Definition at line 207 of file Timing.h.

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

Definition at line 203 of file Timing.h.

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

Definition at line 195 of file Timing.h.

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

Definition at line 215 of file Timing.h.

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

Definition at line 211 of file Timing.h.

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

Definition at line 219 of file Timing.h.

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

Definition at line 199 of file Timing.h.

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

Definition at line 183 of file Timing.h.

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

Basic Process Information: Affinity mask.

Definition at line 74 of file Memory.cpp.

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

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

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

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

Basic Process Information: Base priority.

Definition at line 52 of file Memory.cpp.

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

Break the execution of the application and invoke the debugger.

Definition at line 47 of file Debugger.cpp.

47  {
48 #ifdef _WIN32
49  _asm int 3
50  return 1;
51 #else
52  // I have no clue how to do this in linux
53  return 0;
54 #endif
55 }
long System::breakExecution ( long  pid)

Break the execution of the application and invoke the debugger in a remote process.

Break the execution of the application and invoke the debugger on a possibly remote process.

Definition at line 58 of file Debugger.cpp.

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

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

Consumed CPU time of process in milliseconds.

CPU kernel time of process in milliseconds.

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

Definition at line 169 of file Timing.cpp.

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

Process Creation time.

Units of time between process creation and begin of epoche.

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

Definition at line 115 of file Timing.cpp.

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

Retrieve absolute system time.

Retrieve current system time.

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

Definition at line 80 of file Timing.cpp.

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

Elapsed time since start of process in milliseconds.

Ellapsed time since start of process in milliseconds.

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

Definition at line 140 of file Timing.cpp.

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

Handle to the executable file running.

Definition at line 172 of file ModuleInfo.cpp.

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

Name of the executable file running.

Definition at line 208 of file ModuleInfo.cpp.

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

Basic Process Information: Exit status (does not really make sense for the running process, but for others!)

Definition at line 82 of file Memory.cpp.

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

608  {
609  char* env;
610  if ( (env = getenv(var)) != 0 ) {
611  return env;
612  } else {
613  return "UNKNOWN";
614  }
615 }
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 618 of file System.cpp.

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

Definition at line 79 of file System.h.

79  {
80  return getEnv(var.c_str(), value);
81  }
GAUDI_API std::vector< std::string > getEnv()
get all environment variables
Definition: System.cpp:637
std::vector< std::string > System::getEnv ( )

get all environment variables

get all defined environment vars

Definition at line 637 of file System.cpp.

637  {
638 #if defined(_WIN32)
639 # define environ _environ
640 #elif defined(__APPLE__)
641  static char **environ = *_NSGetEnviron();
642 #endif
643  std::vector<std::string> vars;
644  for (int i=0; environ[i] != 0; ++i) {
645  vars.push_back(environ[i]);
646  }
647  return vars;
648 }
list i
Definition: ana.py:128
const std::string System::getErrorString ( unsigned long  error)

Retrieve error code as string for a given error.

Definition at line 259 of file System.cpp.

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

Get last system known error.

Retrieve last error code.

Definition at line 243 of file System.cpp.

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

Get last system error as string.

Retrieve last error code as string.

Definition at line 253 of file System.cpp.

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

Get a specific function defined in the DLL.

Definition at line 188 of file System.cpp.

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

Get a specific function defined in the DLL.

Definition at line 238 of file System.cpp.

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

Retrieve Process structure.

Definition at line 384 of file ProcessDescriptor.cpp.

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

Retrieve the process time data for a process.

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

Definition at line 179 of file Timing.cpp.

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

Definition at line 60 of file Environment.cpp.

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

Host name.

Definition at line 427 of file System.cpp.

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

Check if an environment variable is set or not.

Definition at line 628 of file System.cpp.

628  {
629  return getenv(var) != 0;
630 }
longlong System::kernelTime ( TimeType  typ = milliSec,
InfoType  fetch = Times,
long  pid = -1 
)

CPU kernel mode time of process in milliseconds.

CPU kernel time of process in milliseconds.

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

Definition at line 149 of file Timing.cpp.

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

Vector of names of linked modules.

Definition at line 232 of file ModuleInfo.cpp.

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

Load dynamic link library.

Definition at line 123 of file System.cpp.

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

Machine type.

Definition at line 482 of file System.cpp.

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

Basic Process Information: priority boost.

Definition at line 181 of file Memory.cpp.

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

Basic Process Information: priority boost.

Definition at line 189 of file Memory.cpp.

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

System Process Limits: Maximum amount of virtual memory this process is allowed to use.

Definition at line 205 of file Memory.cpp.

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

System Process Limits: Minimum amount of virtual memory this process may use.

Definition at line 197 of file Memory.cpp.

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

Handle to currently executed module.

Definition at line 141 of file ModuleInfo.cpp.

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

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

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

Retrieve full name of module.

Definition at line 78 of file ModuleInfo.cpp.

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

Get type of the module.

Definition at line 105 of file ModuleInfo.cpp.

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

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

System Process Limits: Maximum amount of non-paged memory this process is allowed to use.

Definition at line 114 of file Memory.cpp.

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

Basic Process Information: Peak usage of non paged memory.

Basic Process Information: priority boost.

Definition at line 98 of file Memory.cpp.

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

Number of arguments passed to the commandline.

Definition at line 521 of file System.cpp.

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

Basic Process Information: Number of page faults.

Basic Process Information: priority boost.

Definition at line 146 of file Memory.cpp.

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

OS name.

Definition at line 444 of file System.cpp.

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

OS version.

Definition at line 461 of file System.cpp.

461  {
462  static std::string osver = "";
463 #ifdef _WIN32
464  OSVERSIONINFO ut;
465  ut.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
466  ::GetVersionEx(&ut);
467  std::ostringstream ver;
468  ver << ut.dwMajorVersion << '.' << ut.dwMinorVersion;
469  osver = ver.str();
470 #else
471  struct utsname ut;
472  if (uname(&ut) == 0) {
473  osver = ut.release;
474  } else {
475  osver = "UNKNOWN";
476  }
477 #endif
478  return osver;
479 }
long System::pagedMemory ( MemoryUnit  unit = kByte,
InfoType  fetch = Memory,
long  pid = -1 
)

Basic Process Information: Amount of paged memory currently occupied by the process 'pid'.

Definition at line 122 of file Memory.cpp.

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

Basic Process Information: Amount of paged memory that can be occupied by the process 'pid'.

Definition at line 138 of file Memory.cpp.

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

Basic Process Information: Maximum of paged memory occupied by the process 'pid'.

Definition at line 130 of file Memory.cpp.

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

Basic Process Information: Current page file usage.

Basic Process Information: priority boost.

Definition at line 154 of file Memory.cpp.

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

Basic Process Information: Peak usage of page file.

Basic Process Information: priority boost.

Definition at line 170 of file Memory.cpp.

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

Basic Process Information: Peak usage of page file.

Basic Process Information: priority boost.

Definition at line 162 of file Memory.cpp.

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

Basic Process Information: Parent's process ID.

Definition at line 66 of file Memory.cpp.

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

Definition at line 228 of file PathResolver.cpp.

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

Definition at line 223 of file PathResolver.cpp.

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

Basic Process Information: priority boost.

Definition at line 90 of file Memory.cpp.

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

Handle to running process.

Retrieve processhandle.

Definition at line 127 of file ModuleInfo.cpp.

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

Basic Process Information: Process ID.

Definition at line 60 of file Memory.cpp.

60  {
61  static long s_pid = ::getpid();
62  return s_pid;
63 }
longlong System::remainingTime ( TimeType  typ = milliSec,
InfoType  fetch = Quota,
long  pid = -1 
)

Maximum processing time left for this process.

System Process Limits: Maximum processing time left for this process.

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

Definition at line 125 of file Timing.cpp.

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

Definition at line 51 of file Environment.cpp.

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

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

Attach module handle.

Definition at line 137 of file ModuleInfo.cpp.

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

Maximum processing time left for this process.

Units of time since system startup and begin of epoche.

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

Definition at line 98 of file Timing.cpp.

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

Definition at line 79 of file Environment.cpp.

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

thread handle "accessor"

Definition at line 101 of file System.h.

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

Retrieve the number of ticks since system startup.

Returns
Requested value in the indicated units.

Definition at line 66 of file Timing.cpp.

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

Get platform independent information about the class type.

Definition at line 298 of file System.cpp.

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

Definition at line 302 of file System.cpp.

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

unload dynamic link library

Definition at line 162 of file System.cpp.

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

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

CPU user mode time of process in milliseconds.

CPU kernel time of process in milliseconds.

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

Definition at line 159 of file Timing.cpp.

159  {
160  longlong usertime = 0;
161  KERNEL_USER_TIMES info;
162  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) {
163  usertime = adjustTime(typ, info.UserTime );
164  }
165  return usertime;
166 }
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:38
long System::virtualMemory ( MemoryUnit  unit = kByte,
InfoType  fetch = Memory,
long  pid = -1 
)

Basic Process Information: priority boost.

Definition at line 213 of file Memory.cpp.

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

System Process Limits: Maximum amount of the page file this process is allowed to use.

Definition at line 229 of file Memory.cpp.

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

Basic Process Information: priority boost.

Definition at line 221 of file Memory.cpp.

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