Changeset 2212 in Sophya for trunk/SophyaLib
- Timestamp:
- Oct 15, 2002, 5:48:53 PM (23 years ago)
- Location:
- trunk/SophyaLib/SysTools
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/SysTools/cxxcmplnk.cc
r2190 r2212 36 36 37 37 /* --Methode-- */ 38 /*! 39 Constructor 40 \param fglibsophya : if \c true libsophya.so is used when linking 41 \param fglibextsophya : if \c true libextsophya.so is used when linking 42 \param fglibpi : if \c true libPI.so is used when linking 43 */ 38 44 CxxCompilerLinker::CxxCompilerLinker(bool fglibsophya, bool fglibextsophya, bool fglibpi) 39 45 : verbose(false) … … 136 142 137 143 /* --Methode-- */ 144 /*! 145 Compiles the file \c name using the C++ compiler driver and produces 146 the output object file \c oname. If no output name is specified, 147 a default output file name is made from the input name, with the 148 suffix .o , the in temporary directory. 149 \param name : input C++ source file 150 \param oname : output object file 151 */ 138 152 int CxxCompilerLinker::Compile(string const & name, string & oname) 139 153 { … … 160 174 161 175 /* --Methode-- */ 176 /*! 177 Creates a shared library from the object file \c oname. 178 If no output name \c soname is specified, 179 a default output file name is made from the object name, with the 180 suffix .so , in the temporary directory. 181 \param oname : input object file 182 \param soname : shared library name 183 */ 162 184 int CxxCompilerLinker::BuildSO(string const & oname, string & soname) 163 185 { -
trunk/SophyaLib/SysTools/cxxcmplnk.h
r1900 r2212 23 23 virtual int BuildSO(string const & oname, string & soname); 24 24 25 //! Adds compilation options \c opt . Appended to the present option string. 25 26 inline void AddCompileOptions(string const & opt) 26 27 { compOptions += " " + opt; } 28 //! Sets the compilation options. 27 29 inline void SetCompileOptions(string const & opt = "") 28 30 { compOptions = opt; } 31 //! Returns the currently defined compilation options. 29 32 inline string GetCompileOptions() 30 33 { return compOptions; } 31 34 35 //! Adds link options \c opt . Appended to the present option string. 32 36 inline void AddLinkOptions(string const & opt) 33 37 { linkOptions += " " + opt; } 38 //! Sets the link options. 34 39 inline void SetLinkOptions(string const & opt = "") 35 40 { linkOptions = opt; } 36 41 inline string GetLinkOptions() 42 //! Returns the currently defined link options. 37 43 { return linkOptions; } 38 44 45 //! Sets the temporary directory path. 39 46 inline void SetTmpDir(string const & tmpdir) 40 47 { tmpDir = tmpdir; } 48 //! returns the currently defined temporary directory path. 41 49 inline string GetTmpDir() 42 50 { return tmpDir; } 43 51 52 //! Activate (or deactivate) the verbose mode. 44 53 inline void SetVerbose(bool fg=false) 45 54 { verbose = fg; } -
trunk/SophyaLib/SysTools/resusage.cc
r2191 r2212 16 16 The information should be updated through the call to the 17 17 Update() method. 18 Note: The information is obtained through \c getrusage() 19 and \c getrlimit() system calls, and depending on the OS, 20 not all of the memory usage values are correctly filled. 21 \code 22 // How to check resource usage for a given part of the program 23 ResourceUsage res; 24 // --- Part of the program to be checked : Start 25 // ... 26 res.Update(); 27 cout << " Memory size increase (KB):" << res.getDeltaMemorySize() << endl; 28 cout << " Resource usage info : \n" << res << endl; 29 \endcode 18 30 */ 19 31 /*! 32 Constructor. the \b Update() method is called. 33 */ 20 34 ResourceUsage::ResourceUsage() 21 35 { … … 47 61 48 62 } 49 63 /*! 64 Destructor. 65 */ 50 66 ResourceUsage::~ResourceUsage() 51 67 { … … 58 74 } 59 75 76 /*! 77 Update the CPU and memory usage information. 78 */ 60 79 int ResourceUsage::Update() 61 80 { … … 82 101 } 83 102 103 /*! 104 Prints the CPU and memory usage information. 105 \param os : The output stream 106 \param lp : The print level (0 .. 2) 107 \param upd : if \c true , the Update method is called. 108 */ 84 109 void ResourceUsage::Print(ostream& os, int lp, bool upd) 85 110 { -
trunk/SophyaLib/SysTools/resusage.h
r2159 r2212 24 24 // Memory usage in kilo-bytes 25 25 // NOTE: getDataSize() getStackSize() retournent des valeurs bizarres 26 //! Returns the current memory (Resident) size (in kilo-bytes) 26 27 inline uint_8 getMemorySize() { return cur_rss; } 28 //! Returns the maximum allowed memory size: Min( \c MaxResidentSize , \c MaxDataSize )) 27 29 inline uint_8 getMaxMemorySize() 28 30 { return((getMaxResidentSize()<getMaxDataSize()) ? 29 31 getMaxResidentSize() :getMaxDataSize() ); } 32 //! Returns the increase in memory usage since the previous call to \b Update() 30 33 inline uint_8 getDeltaMemorySize() { return delta_rss; } 31 34 35 //! Returns the maximum allowd data segment size (in kilo-bytes) 32 36 inline uint_8 getMaxDataSize() { return((max_datasz>0)?max_datasz:1024); } 37 //! Returns the current data segment size (in kilo-bytes) 33 38 inline uint_8 getDataSize() { return cur_datasz; } 39 //! Returns the maximum allowed resident size (in kilo-bytes) 34 40 inline uint_8 getMaxResidentSize() { return((max_rss>0)?max_rss:1024); } 41 //! Returns the current resident memory size (in kilo-bytes) 35 42 inline uint_8 getResidentSize() { return cur_rss; } 43 //! Returns the maximum allowed stack size (in kilo-bytes) 36 44 inline uint_8 getMaxStackSize() { return max_stack; } 45 //! Returns the current stack size (in kilo-bytes) 37 46 inline uint_8 getStackSize() { return cur_stack; } 38 47 39 48 40 49 // Time in milli-second 50 //! Returns the total CPU time used (in milli-second) 41 51 inline uint_8 getCPUTime() { return cur_tottm; } 52 //! Returns the total elapsed time (in milli-second) 42 53 inline uint_8 getElapsedTime() { return elapsed_time; } 54 //! Returns the average load ( CPU time / elapsed time) 43 55 inline double getAverageCPULoad() 44 56 { return ((elapsed_time>1) ? (double)cur_tottm/(double)elapsed_time: 1.);} 45 57 58 //! Returns the CPU time used since the previous call to \b Update() (in milli-second) 46 59 inline uint_8 getDeltaCPUTime() { return delta_tottm; } 60 //! Returns the elapsed time since the previous call to \b Update() (in milli-second) 47 61 inline uint_8 getDeltaElapsedTime() { return delta_elapsed_time; } 62 //! Returns the CPU load since the previous call to \b Update() 48 63 inline double getCPULoad() 49 64 { return ((delta_elapsed_time>1) ? (double)delta_tottm/(double)delta_elapsed_time: 1.);} 50 65 51 66 67 //! Returns the total CPU time (in milli-second) 52 68 inline uint_8 getTotalCPUTime() { return cur_tottm; } 69 //! Returns the CPU time in user mode (in milli-second) 53 70 inline uint_8 getUserCPUTime() { return cur_usrtm; } 71 //! Returns the CPU time in system mode (in milli-second) 54 72 inline uint_8 getSysCPUTime() { return cur_systm; } 55 73 56 74 57 75 void Print(ostream& os, int lp=0, bool upd=true); 76 //! Alias for the \b Print() method. 58 77 inline void print(ostream& os, int lp=0, bool upd=true){ Print(os,lp,upd); } 59 78 … … 81 100 }; 82 101 102 //! Prints the resource usage information on the output stream 83 103 inline ostream& operator << (ostream& os, ResourceUsage& ru) 84 104 { ru.Print(os,0,true); return(os); } -
trunk/SophyaLib/SysTools/timing.c
r1783 r2212 37 37 38 38 /* Nouvelle-Fonction */ 39 /*! 40 \ingroup SysTools 41 Initializes CPU and elapsed time timer (C function). 42 The values of the CPU and elapsed time can then be printed 43 using \b PrtTim() 44 */ 39 45 void InitTim(void) 40 46 { … … 45 51 46 52 /* Nouvelle-Fonction */ 47 void PrtTim(char *Comm) 53 /*! 54 \ingroup SysTools 55 Prints the values of the CPU and elapsed time, since call to \b InitTim(). 56 */ 57 void PrtTim(const char * Comm) 48 58 { 49 59 float tcal,tcalt; -
trunk/SophyaLib/SysTools/timing.h
r219 r2212 10 10 11 11 void InitTim(void); 12 void PrtTim(c har *Comm);12 void PrtTim(const char * Comm); 13 13 14 14 #ifdef __cplusplus -
trunk/SophyaLib/SysTools/zthread.cc
r1612 r2212 5 5 #include <stdlib.h> 6 6 #include <stdio.h> 7 8 /*! 9 \class SOPHYA::ZThread 10 \ingroup SysTools 11 This class provides an interface for creating and controlling threads. 12 The implementation uses the POSIX thread interface. 13 The ZThread objects can be sub classed with the redefinition of 14 the \c run() method which then performs the task. 15 The default \c run() method of the base class can be used directly 16 to perform computation through a function (see \b setAction() method) 17 \sa SOPHYA::ZMutex 18 The following sample code shows the usage of ZThread object 19 to run simultaneously to functions to perform computation. 20 21 \code 22 // The functions to perform computing 23 void fun1(void *arg) { } 24 void fun2(void *arg) { } 25 // ... 26 ZThread zt1; 27 zt1.setAction(fun1, arg[1]); 28 ZThread zt2; 29 zt2.setAction(fun2, arg[1]); 30 cout << " Starting threads ... " << endl; 31 zt1.start(); 32 zt2.start(); 33 cout << " Waiting for threads to end ... " << endl; 34 zt1.join(); 35 zt2.join(); 36 \endcode 37 */ 7 38 8 39 #define CheckSt(st_, strg_) if (st_ != 0) perror(strg_); … … 24 55 25 56 /* ------ Classe ZThread ------- */ 26 57 /*! 58 Constructor, with optional specification of the thread stack size. 59 */ 27 60 ZThread::ZThread(size_t stacksize) 28 61 { … … 39 72 } 40 73 74 /*! 75 Method which starts the thread. 76 */ 41 77 void ZThread::start() 42 78 { … … 54 90 } 55 91 56 92 /*! 93 Calls the pthread_cancel. Can be used to stop a running thread. 94 */ 57 95 void ZThread::cancel() 58 96 { … … 64 102 65 103 104 /*! 105 Waits for the thread to terminate. 106 */ 66 107 void ZThread::join() 67 108 { … … 73 114 } 74 115 116 /*! 117 This virtual method can be redefined in the derived class, in order 118 to perform the actual computation. 119 */ 75 120 void ZThread::run() 76 121 { … … 82 127 83 128 /* ------ Classe ZMutex ------- */ 129 /*! 130 \class SOPHYA::ZMutex 131 \ingroup SysTools 132 This class implements an interface to the Mutual Exclusion objects 133 of the POSIX threads. 134 The ZMutex objects should be used to control acces from different threads 135 to common objects through the \b lock() and \b unlock() methods. 136 \sa SOPHYA::ZSync 137 */ 84 138 139 /*! 140 Constructor: Creates a associated pair of POSIX \c pthread_mutex_t 141 and \c pthread_cond_t objects 142 */ 85 143 ZMutex::ZMutex() 86 144 { … … 100 158 } 101 159 160 /*! 161 \class SOPHYA::ZSync 162 \ingroup SysTools 163 This class can be used to insure that the execution of a given 164 part of the code is synchronised, i.e. only a single thread 165 goes through this at a given time. 166 The constructor acquires a lock on given \b ZMutex object, 167 which is released by the destructor. 168 The ZSync object should then be instanciated at the beginning of 169 the synchronised instruction bloc. 170 \sa SOPHYA::ZMutex 171 */ -
trunk/SophyaLib/SysTools/zthread.h
r1612 r2212 14 14 15 15 typedef void (* ZThreadAction) (void *); 16 16 17 /*! 18 \class SOPHYA::ZThreadExc 19 \ingroup SysTools 20 This exception class is used by the classes implementing the interface 21 to the POSIX threads (\b ZThread ...) 22 */ 17 23 class ZThreadExc : public PException { 18 24 public: … … 31 37 virtual void run(); 32 38 39 //! Sets the return code for the thread object 33 40 inline void setRC(int rc) { _rc = rc; } 41 //! Return the value of the return code for the thread object 34 42 inline int getRC(int rc) { return(_rc); 35 43 } … … 61 69 explicit ZMutex(); 62 70 virtual ~ZMutex(); 71 //! Locks the mutex object 63 72 inline void lock() 64 73 { pthread_mutex_lock(_mutx); } 74 //! Unlocks the mutex object 65 75 inline void unlock() 66 { pthread_mutex_unlock(_mutx); } 76 { pthread_mutex_unlock(_mutx); } 77 //! Waits for a condition change 67 78 inline void wait() 68 79 { pthread_cond_wait(_condv, _mutx); } 80 //! Signal a condition change on the mutex object 69 81 inline void signal() 70 82 { pthread_cond_signal(_condv); } 83 //! Broadcasts a condition change on the mutex object 71 84 inline void broadcast() 72 85 { pthread_cond_broadcast(_condv); } … … 81 94 public: 82 95 explicit inline ZSync(ZMutex & mtx) {_mtx = &mtx; mtx.lock(); } 83 inline ~ZSync() { _mtx->unlock(); }96 inline ~ZSync() { if (_mtx) _mtx->unlock(); } 84 97 85 98 private:
Note:
See TracChangeset
for help on using the changeset viewer.