sipxportlib  Version 3.3
UtlRscTrace.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 
12 #ifndef _UtlRscTrace_h_
13 #define _UtlRscTrace_h_
14 
15 #define RSC_TEST
16 #undef RSC_TEST
17 
18 #ifdef RSC_TEST
19 
20 // SYSTEM INCLUDES
21 #include "utl/UtlRscStore.h"
22 #include <os/OsMutex.h>
23 
24 // APPLICATION INCLUDES
25 // EXTERNAL FUNCTIONS
26 // EXTERNAL VARIABLES
27 // CONSTANTS
28 // STRUCTS
29 // TYPEDEFS
30 // FORWARD DECLARATIONS
31 
32 //:A class used to keep track of the number of resource allocations and frees
33 // This class is used in conjunction with instrumented versions of the global
34 // new and delete operators.
35 class UtlRscTrace
36 {
37 /* //////////////////////////// PUBLIC //////////////////////////////////// */
38 public:
39  static unsigned long sAllocCnt; // Track the number of memory allocs
40  static unsigned long sFreeCnt; // Track the number of memory frees
41  static int sTraceFlag;// If non-zero, print a line of info
42  // for every call to new()/delete()
43  static unsigned long sStartTime; //
44  static UtlRscStore mResourceStore;
45 
46  enum RscType
47  {
48  NONE = 0,
49  MEMORY = 1,
50  OSSOCKET = 2,
51  OSMSGQ = 3,
52  OSBSEM = 4,
53  OSCSEM = 5,
54  OSMUTEX = 6,
55  OSRWMUTEX = 7,
56  OSTIMER = 8,
57  OSTASK = 9
58  };
59 
60 
61 /* ============================ CREATORS ================================== */
62 
63  UtlRscTrace();
64  //:Default constructor (and take a checkpoint)
65 
66  UtlRscTrace(const UtlRscTrace& rRscTrace);
67  //:Copy constructor
68 
69  virtual
70  ~UtlRscTrace();
71  //:Destructor
72 
73 /* ============================ MANIPULATORS ============================== */
74 
75  UtlRscTrace& operator=(const UtlRscTrace& rhs);
76  //:Assignment operator
77 
78  virtual void checkpoint();
79  //:Remember the count of outstanding memory allocations
80 
81  static void setTraceFlag(int flag) { sTraceFlag = flag; };
82  //: Set trace flag, if non-zero, print a line of info
83 
84  static int enableMemTracking(int taskId = 0);
85  //: Set trace flag, if non-zero, print a line of info
86 
87  static int enableMsgQTracking(int taskId = 0);
88  //: Set trace flag, if non-zero, print a line of info
89 
90  static int enableBSemTracking(int taskId = 0);
91  //: Set trace flag, if non-zero, print a line of info
92 
93  static int enableCSemTracking(int taskId = 0);
94  //: Set trace flag, if non-zero, print a line of info
95 
96  static int enableMutexTracking(int taskId = 0);
97  //: Set trace flag, if non-zero, print a line of info
98 
99  static int enableRWMutexTracking(int taskId = 0);
100  //: Set trace flag, if non-zero, print a line of info
101 
102  static int enableTimerTracking(int taskId = 0);
103  //: Set trace flag, if non-zero, print a line of info
104 
105  static int enableTaskTracking(int taskId = 0);
106  //: Set trace flag, if non-zero, print a line of info
107 
108  static int enableSocketTracking(int taskId = 0);
109  //: Set trace flag, if non-zero, print a line of info
110 
111  static int disableTracking();
112  //: Set trace flag, if non-zero, print a line of info
113 
114  static void addAllocCnt(int addr,
115  int taskId);
116  //: Add allocCnt for the task, used for OsSocket tracking
117 
118  static void addAllocCnt(int size,
119  int addr,
120  int taskId);
121  //: Add allocCnt for the task, used for memory/OsMutex/OsRWMutex tracking
122 
123  static void addAllocCnt(int size,
124  int addr,
125  const char* name,
126  int pArg,
127  int priority,
128  int options,
129  int taskId);
130  //: Add allocCnt for the task, used for OsTask tracking
131 
132  static void addAllocCnt(int state,
133  int addr,
134  int timerId,
135  int type,
136  int taskId);
137  //: Add allocCnt for the task, used for OsTimer/OsCSem tracking
138 
139  static void addAllocCnt(int options,
140  int addr,
141  int state,
142  int taskId);
143  //: Add allocCnt for the task, used for OsBSem tracking
144 
145  static void addAllocCnt(int addr,
146  const char* name,
147  int taskId);
148  //: Add allocCnt for the task, used for OsMsgQ tracking
149 
150  static void addFreeCnt(int addr, int taskId = 0);
151  //: Add freeCnt for the task
152 
153 /* ============================ ACCESSORS ================================= */
154 
155  static void showMem(int taskId = 0);
156 
157  static int delta();
158  //:Return the change to the number of outstanding memory allocations
159  //:since the last checkpoint.
160 
161  static int delta(int taskId);
162  //:Return the change to the number of outstanding memory allocations
163  //:since the last checkpoint.
164 
165  static int allocCnt(int taskId = 0);
166  //:Return the number of memory allocations (monotonically increasing)
167 
168  static int rscStatus();
169  //:Return the number of memory frees (monotonically increasing)
170 
171  static int freeCnt(int taskId = 0);
172  //:Return the number of memory frees (monotonically increasing)
173 
174  static int netAllocCnt();
175  //:Return the net number of allocations (allocCnt - freeCnt)
176 
177  static int netAllocCnt(int taskId);
178  //:Return the net number of allocations (allocCnt - freeCnt)
179 
180 /* ============================ INQUIRY =================================== */
181 
182 /* //////////////////////////// PROTECTED ///////////////////////////////// */
183 protected:
184 
185 /* //////////////////////////// PRIVATE /////////////////////////////////// */
186 private:
187  static long mCheckpoint; // Used to remember the net number of
188  // allocations at time of checkpoint
189  static OsMutex *mpResourceStoreLock;
190 
191  static UtlRscStore mUtlRscStore;
192 
193  static int mTaskId;
194 };
195 
196 
197 /* ============================ INLINE METHODS ============================ */
198 #endif // RSC_TEST
199 
200 #endif // _UtlRscTrace_h_
201