Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: third_party/tcmalloc/chromium/src/stack_trace_table.cc

Issue 9667026: Revert 126020 - Experiment for updating the tcmalloc chromium branch to r144 (gperftools 2.0). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 ASSERT, Log 38 #include "internal_logging.h" // for MESSAGE, ASSERT
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
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 Log(kLog, __FILE__, __LINE__, 96 MESSAGE("tcmalloc: could not allocate bucket", sizeof(*b));
97 "tcmalloc: could not allocate bucket", sizeof(*b));
98 error_ = true; 97 error_ = true;
99 } else { 98 } else {
100 b->hash = h; 99 b->hash = h;
101 b->trace = t; 100 b->trace = t;
102 b->count = 1; 101 b->count = 1;
103 b->next = table_[idx]; 102 b->next = table_[idx];
104 table_[idx] = b; 103 table_[idx] = b;
105 } 104 }
106 } 105 }
107 } 106 }
108 107
109 void** StackTraceTable::ReadStackTracesAndClear() { 108 void** StackTraceTable::ReadStackTracesAndClear() {
110 if (error_) { 109 if (error_) {
111 return NULL; 110 return NULL;
112 } 111 }
113 112
114 // Allocate output array 113 // Allocate output array
115 const int out_len = bucket_total_ * 3 + depth_total_ + 1; 114 const int out_len = bucket_total_ * 3 + depth_total_ + 1;
116 void** out = new void*[out_len]; 115 void** out = new void*[out_len];
117 if (out == NULL) { 116 if (out == NULL) {
118 Log(kLog, __FILE__, __LINE__, 117 MESSAGE("tcmalloc: allocation failed for stack traces\n",
119 "tcmalloc: allocation failed for stack traces", 118 out_len * sizeof(*out));
120 out_len * sizeof(*out));
121 return NULL; 119 return NULL;
122 } 120 }
123 121
124 // Fill output array 122 // Fill output array
125 int idx = 0; 123 int idx = 0;
126 for (int i = 0; i < kHashTableSize; ++i) { 124 for (int i = 0; i < kHashTableSize; ++i) {
127 Bucket* b = table_[i]; 125 Bucket* b = table_[i];
128 while (b != NULL) { 126 while (b != NULL) {
129 out[idx++] = reinterpret_cast<void*>(static_cast<uintptr_t>(b->count)); 127 out[idx++] = reinterpret_cast<void*>(static_cast<uintptr_t>(b->count));
130 out[idx++] = reinterpret_cast<void*>(b->trace.size); // cumulative size 128 out[idx++] = reinterpret_cast<void*>(b->trace.size); // cumulative size
(...skipping 19 matching lines...) Expand all
150 Static::bucket_allocator()->Delete(b); 148 Static::bucket_allocator()->Delete(b);
151 b = next; 149 b = next;
152 } 150 }
153 table_[i] = NULL; 151 table_[i] = NULL;
154 } 152 }
155 153
156 return out; 154 return out;
157 } 155 }
158 156
159 } // namespace tcmalloc 157 } // namespace tcmalloc
OLDNEW
« no previous file with comments | « third_party/tcmalloc/chromium/src/span.cc ('k') | third_party/tcmalloc/chromium/src/stacktrace.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698