Panda3D

memoryUsagePointerCounts.cxx
Go to the documentation of this file.
1 /**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file memoryUsagePointerCounts.cxx
10 * @author drose
11 * @date 2001-06-04
12 */
13
14 #include "memoryUsagePointerCounts.h"
15 #include "memoryInfo.h"
16
17 /**
18 * Adds a pointer definition to the counter.
19 */
20 void MemoryUsagePointerCounts::
21 add_info(MemoryInfo *info) {
22 #ifdef DO_MEMORY_USAGE
23 _count++;
24
25 if (info->is_size_known()) {
26 _size += info->get_size();
27 } else {
28 _unknown_size_count++;
29 }
30 #endif
31 }
32
33 /**
34 *
35 */
36 void MemoryUsagePointerCounts::
37 output(std::ostream &out) const {
38 #ifdef DO_MEMORY_USAGE
39 out << _count << " pointers";
40 if (_unknown_size_count < _count) {
41 out << ", ";
42 output_bytes(out, _size);
43 out << ", avg ";
44 output_bytes(out, _size / (_count - _unknown_size_count));
45 out << " each";
46
47 if (_unknown_size_count != 0) {
48 out << " (" << _unknown_size_count << " of unknown size)";
49 }
50 }
51 #endif
52 }
53
54 /**
55 * Formats a size in bytes in a meaningful and concise way for output, with
56 * units.
57 */
58 void MemoryUsagePointerCounts::
59 output_bytes(std::ostream &out, size_t size) {
60 #ifdef DO_MEMORY_USAGE
61 if (size < 4 * 1024) {
62 out << size << " bytes";
63
64 } else if (size < 4 * 1024 * 1024) {
65 out << size / 1024 << " Kb";
66
67 } else {
68 out << size / (1024 * 1024) << " Mb";
69 }
70 #endif
71 }
MemoryUsagePointerCounts::add_info
void add_info(MemoryInfo *info)
Adds a pointer definition to the counter.
Definition: memoryUsagePointerCounts.cxx:21
memoryInfo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
memoryUsagePointerCounts.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.