Index: trunk/SophyaLib/SysTools/Makefile
===================================================================
--- trunk/SophyaLib/SysTools/Makefile	(revision 1929)
+++ trunk/SophyaLib/SysTools/Makefile	(revision 2101)
@@ -3,7 +3,7 @@
 all: $(LIB)libSysTools.a
 clean:
-	rm -f $(OBJ)ctimer.o $(OBJ)cxxcmplnk.o $(OBJ)pdlmgr.o $(OBJ)periodic.o $(OBJ)psighand.o $(OBJ)zthread.o $(OBJ)timing.o
+	rm -f $(OBJ)ctimer.o $(OBJ)cxxcmplnk.o $(OBJ)pdlmgr.o $(OBJ)periodic.o $(OBJ)psighand.o $(OBJ)resusage.o $(OBJ)zthread.o $(OBJ)timing.o
 	rm -f $(LIB)libSysTools.a
-$(LIB)libSysTools.a : $(OBJ)ctimer.o $(OBJ)cxxcmplnk.o $(OBJ)pdlmgr.o $(OBJ)periodic.o $(OBJ)psighand.o $(OBJ)timing.o $(OBJ)zthread.o
+$(LIB)libSysTools.a : $(OBJ)ctimer.o $(OBJ)cxxcmplnk.o $(OBJ)pdlmgr.o $(OBJ)periodic.o $(OBJ)psighand.o $(OBJ)resusage.o $(OBJ)timing.o $(OBJ)zthread.o
 	$(ARCXX) $(ARCXXFLAGS) $@ $($(ARARGS))
 ifeq ($(CXX),cxx)
@@ -20,4 +20,6 @@
  $(INC)machdefs.h \
  $(INC)pexceptions.h
+$(OBJ)resusage.o: resusage.cc resusage.h \
+ $(INC)machdefs.h
 $(OBJ)zthread.o: zthread.cc zthread.h \
  $(INC)machdefs.h \
Index: trunk/SophyaLib/SysTools/objlist.list
===================================================================
--- trunk/SophyaLib/SysTools/objlist.list	(revision 1929)
+++ trunk/SophyaLib/SysTools/objlist.list	(revision 2101)
@@ -4,4 +4,5 @@
 periodic.o
 psighand.o
+resusage.o
 timing.o
 zthread.o
Index: trunk/SophyaLib/SysTools/resusage.cc
===================================================================
--- trunk/SophyaLib/SysTools/resusage.cc	(revision 2101)
+++ trunk/SophyaLib/SysTools/resusage.cc	(revision 2101)
@@ -0,0 +1,101 @@
+#include "resusage.h"
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <unistd.h>
+#include <time.h>
+
+/*!
+  \class SOPHYA::ResourceUsage
+  \ingroup SysTools
+  This class gives acces to various system resource usage 
+  (CPU, memory, ...).
+  All returned values are in kilobytes for memory consumptions
+  and in milli-seconds fo CPU and elapsed times.
+  The information should be updated through the call to the 
+  Update() method. 
+*/
+
+ResourceUsage::ResourceUsage()
+{
+  struct rlimit rl;
+  getrlimit(RLIMIT_DATA, &rl);
+  max_datasz = rl.rlim_cur/1024;
+  getrlimit(RLIMIT_RSS, &rl);
+  max_rss = rl.rlim_cur/1024;
+  getrlimit(RLIMIT_STACK, &rl);
+  max_stack = rl.rlim_cur/1024;
+
+  cur_datasz = 0;
+  cur_stack = 0; 
+  cur_rss = 0; 
+  delta_rss = 0; 
+  cur_tottm = 0;
+  cur_usrtm = 0;
+  cur_systm = 0;
+  elapsed_time = 0;
+  delta_rss = 0;
+  delta_tottm = 0;
+  delta_elapsed_time = 0;
+  Update();
+  
+}
+
+ResourceUsage::~ResourceUsage()
+{
+}
+
+inline uint_8 s_timeval2msec(struct timeval & tv)
+{ 
+  uint_8 ret = tv.tv_sec; ret *= 1000; 
+  ret += tv.tv_usec/1000; return(ret); 
+}
+
+int ResourceUsage::Update()
+{
+  struct rusage rsu;
+  int rc = getrusage(RUSAGE_SELF, &rsu);
+  delta_tottm = cur_tottm;
+  delta_rss = cur_rss;
+  cur_usrtm = s_timeval2msec(rsu.ru_utime);
+  cur_systm = s_timeval2msec(rsu.ru_stime);
+  cur_tottm = cur_usrtm+cur_systm;
+  cur_rss = rsu.ru_maxrss;
+  cur_datasz = rsu.ru_idrss;
+  cur_stack = rsu.ru_isrss;
+  delta_tottm = cur_tottm-delta_tottm;
+  delta_rss = cur_rss-delta_rss;
+
+  delta_elapsed_time = elapsed_time;
+  
+  delta_elapsed_time = elapsed_time;
+  time_t tm = time(NULL);
+  if (elapsed_time == 0) t0_time = tm;
+  elapsed_time = (tm - t0_time)*1000;
+  if (elapsed_time < 1) elapsed_time = 1;
+  delta_elapsed_time = elapsed_time-delta_elapsed_time;
+  return(rc);
+}
+
+void ResourceUsage::Print(ostream& os, int lp, bool upd) 
+{
+  if (upd) Update();
+  os << " --------------- ResourceUsage::Print(lp=" << lp 
+     <<" ) --------------- " << endl;
+  int load = getAverageCPULoad()*100.;
+  os << " CPU-Usage= " << getCPUTime() << " Elapsed= " << getElapsedTime()
+     << " msec - Load= " << load << " %" << endl;
+  long fracmem = getMemorySize()*100/getMaxMemorySize();
+  os << " MemoryUsage= " << getMemorySize() << " /Max= " << getMaxMemorySize() 
+     << " kbytes (" << fracmem << " %)" << endl;
+  if (lp < 1) return;
+  os << " CPU-Usage= " << cur_tottm << "ms (usr,sys)=(" 
+     << cur_usrtm << "," << cur_systm << ")" << endl;
+  os << "  DataSize=" << cur_datasz << " /Max " << max_datasz 
+     << " kbytes" << endl;
+  os << " StackSize=" << cur_stack  << " /Max " << max_stack 
+     << " kbytes" << endl;
+  os << "   ResSize=" << cur_rss  << " /Max " << max_rss 
+     << " kbytes" << endl;
+}
Index: trunk/SophyaLib/SysTools/resusage.h
===================================================================
--- trunk/SophyaLib/SysTools/resusage.h	(revision 2101)
+++ trunk/SophyaLib/SysTools/resusage.h	(revision 2101)
@@ -0,0 +1,86 @@
+// This may look like C code, but it is really -*- C++ -*-
+// permet d'obtenir des informations sur les ressources utilisees
+//                                R. Ansari - Juillet 2002
+// LAL (Orsay) / IN2P3-CNRS  DAPNIA/SPP (Saclay) / CEA
+
+#ifndef RESUSAGE_H_SEEN
+#define RESUSAGE_H_SEEN
+
+#include "machdefs.h"
+#include <iostream.h>
+
+namespace SOPHYA {
+
+//! Acces to nformation about resource usage (memory, CPU, ...)
+
+class ResourceUsage
+{
+public:
+  ResourceUsage();
+  ~ResourceUsage();
+
+  int Update();
+
+  // Memory usage in kilo-bytes  
+  // NOTE: getDataSize() getStackSize() retournent des valeurs bizarres
+  inline uint_8 getMemorySize() { return cur_rss; }
+  inline uint_8 getMaxMemorySize() 
+    { return((max_rss<max_datasz) ? max_rss : max_datasz); }
+  inline uint_8 getDeltaMemorySize() { return delta_rss; }
+
+  inline uint_8 getMaxDataSize() { return max_datasz; }
+  inline uint_8 getDataSize() { return cur_datasz; }  
+  inline uint_8 getMaxResidentSize() { return max_rss; }
+  inline uint_8 getResidentSize() { return cur_rss; }
+  inline uint_8 getMaxStackSize() { return max_stack; }
+  inline uint_8 getStackSize() { return cur_stack; }
+
+  
+  // Time in milli-second
+  inline uint_8 getCPUTime() { return cur_tottm; }
+  inline uint_8 getElapsedTime() { return elapsed_time; }
+  inline float  getAverageCPULoad() 
+    { return ((elapsed_time>1) ? (float)cur_tottm/(float)elapsed_time: 1.);}
+
+  inline uint_8 getDeltaCPUTime() { return delta_tottm; }
+  inline uint_8 getDeltaElapsedTime() { return elapsed_time; }
+
+
+  inline uint_8 getTotalCPUTime() { return cur_tottm; }
+  inline uint_8 getUserCPUTime() { return cur_usrtm; }
+  inline uint_8 getSysCPUTime() { return cur_systm; }
+
+
+  void  Print(ostream& os, int lp=0, bool upd=true);
+  inline void print(ostream& os, int lp=0, bool upd=true){ Print(os,lp,upd); }
+
+protected:
+  uint_8 max_datasz;  // Max data segment size (KBytes)
+  uint_8 max_rss;     // Max resident size
+  uint_8 max_stack;   // Max stack size
+
+  uint_8 cur_datasz;  // Current data segment size
+  uint_8 cur_rss;     // Current resident size
+  uint_8 cur_stack;   // Current stack size
+
+  uint_8 cur_tottm;   // Current total CPU-Time - in milli-second
+  uint_8 cur_usrtm;   // Current user CPU-Time - in milli-second 
+  uint_8 cur_systm;   // Current system CPU-Time - in milli-second 
+  uint_8 elapsed_time; // Elapsed time - in milli-second
+  uint_8 t0_time;      // time T0 in seconds 
+
+  // Delta_values : difference since last call to Update()
+  uint_8 delta_rss;     // Max resident size
+  uint_8 delta_tottm;   // Delta total CPU-Time - in milli-second
+ 
+  uint_8 delta_elapsed_time; // Elapsed time - in milli-second
+ 
+};
+
+inline ostream& operator << (ostream& os, ResourceUsage& ru)
+{ ru.Print(os,0,true); return(os); }
+
+} // namespace SOPHYA
+
+#endif
+
Index: trunk/SophyaLib/SysTools/systools.h
===================================================================
--- trunk/SophyaLib/SysTools/systools.h	(revision 1929)
+++ trunk/SophyaLib/SysTools/systools.h	(revision 2101)
@@ -14,4 +14,5 @@
 #include "periodic.h"
 #include "psighand.h"
+#include "resusage.h"
 
 #endif
