OLD | NEW |
1 // Copyright (c) 2009, Google Inc. | 1 // Copyright (c) 2009, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 17 matching lines...) Expand all Loading... |
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 // --- | 30 // --- |
31 // Author: Andrew Fikes | 31 // Author: Andrew Fikes |
32 | 32 |
33 #include <config.h> | 33 #include <config.h> |
34 #include "stack_trace_table.h" | 34 #include "stack_trace_table.h" |
35 #include <string.h> // for NULL, memset | 35 #include <string.h> // for NULL, memset |
36 #include "base/spinlock.h" // for SpinLockHolder | 36 #include "base/spinlock.h" // for SpinLockHolder |
37 #include "common.h" // for StackTrace | 37 #include "common.h" // for StackTrace |
38 #include "internal_logging.h" // for MESSAGE, ASSERT | 38 #include "internal_logging.h" // for ASSERT, Log |
39 #include "page_heap_allocator.h" // for PageHeapAllocator | 39 #include "page_heap_allocator.h" // for PageHeapAllocator |
40 #include "static_vars.h" // for Static | 40 #include "static_vars.h" // for Static |
41 | 41 |
42 namespace tcmalloc { | 42 namespace tcmalloc { |
43 | 43 |
44 bool StackTraceTable::Bucket::KeyEqual(uintptr_t h, | 44 bool StackTraceTable::Bucket::KeyEqual(uintptr_t h, |
45 const StackTrace& t) const { | 45 const StackTrace& t) const { |
46 const bool eq = (this->hash == h && this->trace.depth == t.depth); | 46 const bool eq = (this->hash == h && this->trace.depth == t.depth); |
47 for (int i = 0; eq && i < t.depth; ++i) { | 47 for (int i = 0; eq && i < t.depth; ++i) { |
48 if (this->trace.stack[i] != t.stack[i]) { | 48 if (this->trace.stack[i] != t.stack[i]) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 b = b->next; | 86 b = b->next; |
87 } | 87 } |
88 if (b != NULL) { | 88 if (b != NULL) { |
89 b->count++; | 89 b->count++; |
90 b->trace.size += t.size; // keep cumulative size | 90 b->trace.size += t.size; // keep cumulative size |
91 } else { | 91 } else { |
92 depth_total_ += t.depth; | 92 depth_total_ += t.depth; |
93 bucket_total_++; | 93 bucket_total_++; |
94 b = Static::bucket_allocator()->New(); | 94 b = Static::bucket_allocator()->New(); |
95 if (b == NULL) { | 95 if (b == NULL) { |
96 MESSAGE("tcmalloc: could not allocate bucket", sizeof(*b)); | 96 Log(kLog, __FILE__, __LINE__, |
| 97 "tcmalloc: could not allocate bucket", sizeof(*b)); |
97 error_ = true; | 98 error_ = true; |
98 } else { | 99 } else { |
99 b->hash = h; | 100 b->hash = h; |
100 b->trace = t; | 101 b->trace = t; |
101 b->count = 1; | 102 b->count = 1; |
102 b->next = table_[idx]; | 103 b->next = table_[idx]; |
103 table_[idx] = b; | 104 table_[idx] = b; |
104 } | 105 } |
105 } | 106 } |
106 } | 107 } |
107 | 108 |
108 void** StackTraceTable::ReadStackTracesAndClear() { | 109 void** StackTraceTable::ReadStackTracesAndClear() { |
109 if (error_) { | 110 if (error_) { |
110 return NULL; | 111 return NULL; |
111 } | 112 } |
112 | 113 |
113 // Allocate output array | 114 // Allocate output array |
114 const int out_len = bucket_total_ * 3 + depth_total_ + 1; | 115 const int out_len = bucket_total_ * 3 + depth_total_ + 1; |
115 void** out = new void*[out_len]; | 116 void** out = new void*[out_len]; |
116 if (out == NULL) { | 117 if (out == NULL) { |
117 MESSAGE("tcmalloc: allocation failed for stack traces\n", | 118 Log(kLog, __FILE__, __LINE__, |
118 out_len * sizeof(*out)); | 119 "tcmalloc: allocation failed for stack traces", |
| 120 out_len * sizeof(*out)); |
119 return NULL; | 121 return NULL; |
120 } | 122 } |
121 | 123 |
122 // Fill output array | 124 // Fill output array |
123 int idx = 0; | 125 int idx = 0; |
124 for (int i = 0; i < kHashTableSize; ++i) { | 126 for (int i = 0; i < kHashTableSize; ++i) { |
125 Bucket* b = table_[i]; | 127 Bucket* b = table_[i]; |
126 while (b != NULL) { | 128 while (b != NULL) { |
127 out[idx++] = reinterpret_cast<void*>(static_cast<uintptr_t>(b->count)); | 129 out[idx++] = reinterpret_cast<void*>(static_cast<uintptr_t>(b->count)); |
128 out[idx++] = reinterpret_cast<void*>(b->trace.size); // cumulative size | 130 out[idx++] = reinterpret_cast<void*>(b->trace.size); // cumulative size |
(...skipping 19 matching lines...) Expand all Loading... |
148 Static::bucket_allocator()->Delete(b); | 150 Static::bucket_allocator()->Delete(b); |
149 b = next; | 151 b = next; |
150 } | 152 } |
151 table_[i] = NULL; | 153 table_[i] = NULL; |
152 } | 154 } |
153 | 155 |
154 return out; | 156 return out; |
155 } | 157 } |
156 | 158 |
157 } // namespace tcmalloc | 159 } // namespace tcmalloc |
OLD | NEW |