StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMemoryInfo.cc
1 /***************************************************************************
2  *
3  * $Id: StMemoryInfo.cc,v 1.5 2013/01/17 14:40:04 fisyak Exp $
4  *
5  * Author: Thomas Ullrich, June 1999
6  ***************************************************************************
7  *
8  * Description:
9  *
10  ***************************************************************************
11  *
12  * $Log: StMemoryInfo.cc,v $
13  * Revision 1.5 2013/01/17 14:40:04 fisyak
14  * Add APPLE
15  *
16  * Revision 1.4 2012/06/11 15:29:26 fisyak
17  * std namespace
18  *
19  * Revision 1.3 1999/12/21 15:14:16 ullrich
20  * Modified to cope with new compiler version on Sun (CC5.0).
21  *
22  * Revision 1.2 1999/11/05 18:10:47 ullrich
23  * Added blank line as last printed line.
24  *
25  * Revision 1.1 1999/06/04 17:57:01 ullrich
26  * Initial Revision
27  *
28  **************************************************************************/
29 #include "StMemoryInfo.hh"
30 
31 StMemoryInfo* StMemoryInfo::mMemoryInfo = 0;
32 
33 StMemoryInfo* StMemoryInfo::instance()
34 {
35  if (!mMemoryInfo)
36  mMemoryInfo = new StMemoryInfo();
37  return mMemoryInfo;
38 }
39 
40 StMemoryInfo::StMemoryInfo()
41 {
42 #if !defined(__SUNPRO_CC) && !defined(__APPLE__)
43  mInfo = mOldInfo = mallinfo();
44 #endif
45  mCounter = 0;
46 }
47 
48 StMemoryInfo::StMemoryInfo(const StMemoryInfo &) {/* private */}
49 
50 const StMemoryInfo&
51 StMemoryInfo::operator=(const StMemoryInfo &) {/* private */ return *this;}
52 
53 void StMemoryInfo::snapshot()
54 {
55 #ifndef __APPLE__
56  mOldInfo = mInfo;
57 #endif
58 #if !defined(__SUNPRO_CC) && !defined(__APPLE__)
59  mInfo = mallinfo();
60 #endif
61  mCounter++;
62 }
63 
64 void StMemoryInfo::printLine(ostream& os, const char* str, int cur, int old, const char* unit)
65 {
66  os.width(40);
67  // os.fill('.');
68  os.setf(std::ios::left);
69  os << str << ' ' << cur << " (";
70  os.setf(std::ios::showpos);
71  os << cur-old << ") ";
72  if (unit) os << unit;
73  os << endl;
74  os.unsetf(std::ios::showpos);
75 }
76 
77 void StMemoryInfo::print(ostream& os)
78 {
79  os << "---------- Memory Status (snapshot #" << mCounter << ") ----------" << endl;
80 #if defined(__SUNPRO_CC) || defined(__APPLE__)
81  os << "Sorry, StMemoryInfo is not supported on SUN." << endl;
82 #elif defined(__GNUC__)
83  printLine(os, "total space allocated from system", mInfo.arena, mOldInfo.arena);
84  printLine(os, "number of non-inuse chunks", mInfo.ordblks, mOldInfo.ordblks);
85  printLine(os, "number of mmapped regions", mInfo.hblks, mOldInfo.hblks);
86  printLine(os, "total space in mmapped regions", mInfo.hblkhd, mOldInfo.hblkhd);
87  printLine(os, "total allocated space", mInfo.uordblks, mOldInfo.uordblks);
88  printLine(os, "total non-inuse space", mInfo.fordblks, mOldInfo.fordblks);
89  printLine(os, "top-most, releasable space", mInfo.keepcost, mOldInfo.keepcost);
90 #else
91  printLine(os, "total space in arena", mInfo.arena, mOldInfo.arena);
92  printLine(os, "number of ordinary blocks", mInfo.ordblks, mOldInfo.ordblks);
93  printLine(os, "number of small blocks", mInfo.smblks, mOldInfo.smblks);
94  printLine(os, "space in holding block headers", mInfo.hblks, mOldInfo.hblks);
95  printLine(os, "number of holding blocks", mInfo.hblkhd, mOldInfo.hblkhd);
96  printLine(os, "space in small blocks in use", mInfo.usmblks, mOldInfo.usmblks);
97  printLine(os, "space in free small blocks", mInfo.fsmblks, mOldInfo.fsmblks);
98  printLine(os, "space in ordinary blocks in use", mInfo.uordblks, mOldInfo.uordblks);
99  printLine(os, "space in free ordinary blocks", mInfo.fordblks, mOldInfo.fordblks);
100  printLine(os, "space penalty if keep option is used", mInfo.keepcost, mOldInfo.keepcost);
101 #endif
102  os << endl;
103 }