MemoryStats.cpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4 /* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
5 /* */
6 /* This program and the accompanying materials are made available under */
7 /* the terms of the Common Public License v1.0 which accompanies this */
8 /* distribution. A copy is also available at the following address: */
9 /* http://www.oorexx.org/license.html */
10 /* */
11 /* Redistribution and use in source and binary forms, with or */
12 /* without modification, are permitted provided that the following */
13 /* conditions are met: */
14 /* */
15 /* Redistributions of source code must retain the above copyright */
16 /* notice, this list of conditions and the following disclaimer. */
17 /* Redistributions in binary form must reproduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in */
19 /* the documentation and/or other materials provided with the distribution. */
20 /* */
21 /* Neither the name of Rexx Language Association nor the names */
22 /* of its contributors may be used to endorse or promote products */
23 /* derived from this software without specific prior written permission. */
24 /* */
25 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
28 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
31 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
32 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
33 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
34 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
35 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 /* */
37 /*----------------------------------------------------------------------------*/
38 /******************************************************************************/
39 /* REXX Kernel Memorystats.cpp */
40 /* */
41 /* Support classes for managing memory profiling */
42 /* */
43 /******************************************************************************/
44 #include "RexxCore.h"
45 
46 
48 /******************************************************************************/
49 /* Function: clear out the memory statistics. */
50 /******************************************************************************/
51 {
52  count = 0;
54  largestSegment = 0;
55  totalBytes = 0;
56  deadBytes = 0;
57  liveBytes = 0;
58  deadObjects = 0;
59  liveObjects = 0;
60 }
61 
62 
63 void SegmentStats::recordObject(MemoryStats *memStats, char *obj)
64 /******************************************************************************/
65 /* Function: Accumulate memory statistics for a scanned object */
66 /******************************************************************************/
67 {
68  /* get size of this object */
69  size_t bytes = ((RexxObject *)obj)->getObjectSize();
70  totalBytes += bytes;
71  /* Is this object alive? */
72  if (((RexxObject *)obj)->isObjectLive(memoryObject.markWord))
73  {
74  /* update the type specific counters */
75  memStats->logObject((RexxObject *)obj);
76  /* update total live bytes */
77  liveBytes += bytes;
78  /* and total number of live objs */
79  liveObjects++;
80  }
81  else
82  {
83  /* its a dead object, update total dead objects */
84  deadObjects++;
85  deadBytes += bytes;
86  }
87 }
88 
89 
91 /******************************************************************************/
92 /* Function: Print out accumulated image statistics */
93 /******************************************************************************/
94 {
95  printf(" ObjectTypeNum Total Objects TotalBytes\n");
96  printf(" ============= ============== ==========\n");
97 
98  for (int i = 0; i <= T_Last_Class_Type; i++)
99  {
100  objectStats[i].printStats(i);
101  }
102 }
103 
104 
106 /******************************************************************************/
107 /* Function: Print out statistics for a memory snapshot */
108 /******************************************************************************/
109 {
110  printf("All Objects in Object Memory, by allocation type\n\n");
111 
112  printf(" ObjectTypeNum Total Objects TotalBytes\n");
113  printf(" ============= ============== ==========\n");
114  int i;
115 
116  for (i = 0; i <= T_Last_Class_Type; i++)
117  {
118  objectStats[i].printStats(i);
119  }
120 
121  printf("\nSegment set allocation statistics\n\n");
122 
125 }
126 
127 
129 /******************************************************************************/
130 /* Function: Print out statistics for a segment set snapshot */
131 /******************************************************************************/
132 {
133  printf("\n\n %s: Total bytes %lu in %lu segments \n", name, totalBytes, count);
134  printf("Largest segment is %lu bytes, smallest is %lu bytes\n", largestSegment, smallestSegment);
135  printf("Total Live objects %lu, using %lu bytes\n", liveObjects, liveBytes);
136  printf("Total Dead objects %lu, using %lu bytes\n\n", deadObjects, deadBytes);
137 }
138 
139 
141 /******************************************************************************/
142 /* Function: Print out accumulated statistics for an individual objec type */
143 /******************************************************************************/
144 {
145  printf(" %3d %8lu %8lu \n", type, count, size);
146 }
147 
148 
150 /******************************************************************************/
151 /* Function: clear out the memory statistics. */
152 /******************************************************************************/
153 {
154  normalStats.clear();
155  largeStats.clear();
156 
157  for (int i = 0; i <= T_Last_Class_Type; i++)
158  {
159  objectStats[i].clear();
160  }
161 }
162 
163 
165 /******************************************************************************/
166 /* Function: Log the memory statistics for an individual object */
167 /******************************************************************************/
168 {
170 }
@ T_Last_Class_Type
RexxMemory memoryObject
Definition: RexxMemory.cpp:85
#define MaximumObjectSize
Definition: RexxMemory.hpp:86
ObjectStats objectStats[T_Last_Class_Type+1]
void logObject(RexxObject *obj)
SegmentStats normalStats
void printSavedImageStats()
Definition: MemoryStats.cpp:90
void printMemoryStats()
SegmentStats largeStats
void logObject(RexxObject *obj)
Definition: MemoryStats.hpp:58
size_t count
Definition: MemoryStats.hpp:63
void printStats(int type)
void clear()
Definition: MemoryStats.hpp:57
size_t getObjectTypeNumber()
size_t markWord
Definition: RexxMemory.hpp:301
size_t smallestSegment
Definition: MemoryStats.hpp:87
size_t deadObjects
Definition: MemoryStats.hpp:93
size_t totalBytes
Definition: MemoryStats.hpp:89
size_t liveObjects
Definition: MemoryStats.hpp:92
size_t largestSegment
Definition: MemoryStats.hpp:86
size_t deadBytes
Definition: MemoryStats.hpp:91
void printStats()
const char * name
Definition: MemoryStats.hpp:94
void recordObject(MemoryStats *memStats, char *obj)
Definition: MemoryStats.cpp:63
size_t liveBytes
Definition: MemoryStats.hpp:90
int type
Definition: cmdparse.cpp:383