OLD | NEW |
1 // Copyright (c) 2005, Google Inc. | 1 // Copyright (c) 2005, 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 27 matching lines...) Expand all Loading... |
38 #include <stdint.h> | 38 #include <stdint.h> |
39 #elif defined HAVE_INTTYPES_H | 39 #elif defined HAVE_INTTYPES_H |
40 #include <inttypes.h> | 40 #include <inttypes.h> |
41 #else | 41 #else |
42 #include <sys/types.h> | 42 #include <sys/types.h> |
43 #endif | 43 #endif |
44 #include <string> | 44 #include <string> |
45 #include "base/dynamic_annotations.h" | 45 #include "base/dynamic_annotations.h" |
46 #include "base/sysinfo.h" // for FillProcSelfMaps | 46 #include "base/sysinfo.h" // for FillProcSelfMaps |
47 #ifndef NO_HEAP_CHECK | 47 #ifndef NO_HEAP_CHECK |
48 #include "gperftools/heap-checker.h" | 48 #include "google/heap-checker.h" |
49 #endif | 49 #endif |
50 #include "gperftools/malloc_extension.h" | 50 #include "google/malloc_extension.h" |
51 #include "gperftools/malloc_extension_c.h" | |
52 #include "maybe_threads.h" | 51 #include "maybe_threads.h" |
53 | 52 |
54 using STL_NAMESPACE::string; | 53 using STL_NAMESPACE::string; |
55 using STL_NAMESPACE::vector; | 54 using STL_NAMESPACE::vector; |
56 | 55 |
57 static void DumpAddressMap(string* result) { | 56 static void DumpAddressMap(string* result) { |
58 *result += "\nMAPPED_LIBRARIES:\n"; | 57 *result += "\nMAPPED_LIBRARIES:\n"; |
59 // We keep doubling until we get a fit | 58 // We keep doubling until we get a fit |
60 const size_t old_resultlen = result->size(); | 59 const size_t old_resultlen = result->size(); |
61 for (int amap_size = 10240; amap_size < 10000000; amap_size *= 2) { | 60 for (int amap_size = 10240; amap_size < 10000000; amap_size *= 2) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 dummy += "!"; // so the definition of dummy isn't optimized out | 100 dummy += "!"; // so the definition of dummy isn't optimized out |
102 #endif /* __GLIBC__ */ | 101 #endif /* __GLIBC__ */ |
103 } | 102 } |
104 | 103 |
105 // SysAllocator implementation | 104 // SysAllocator implementation |
106 SysAllocator::~SysAllocator() {} | 105 SysAllocator::~SysAllocator() {} |
107 | 106 |
108 // Default implementation -- does nothing | 107 // Default implementation -- does nothing |
109 MallocExtension::~MallocExtension() { } | 108 MallocExtension::~MallocExtension() { } |
110 bool MallocExtension::VerifyAllMemory() { return true; } | 109 bool MallocExtension::VerifyAllMemory() { return true; } |
111 bool MallocExtension::VerifyNewMemory(const void* p) { return true; } | 110 bool MallocExtension::VerifyNewMemory(void* p) { return true; } |
112 bool MallocExtension::VerifyArrayNewMemory(const void* p) { return true; } | 111 bool MallocExtension::VerifyArrayNewMemory(void* p) { return true; } |
113 bool MallocExtension::VerifyMallocMemory(const void* p) { return true; } | 112 bool MallocExtension::VerifyMallocMemory(void* p) { return true; } |
114 | 113 |
115 bool MallocExtension::GetNumericProperty(const char* property, size_t* value) { | 114 bool MallocExtension::GetNumericProperty(const char* property, size_t* value) { |
116 return false; | 115 return false; |
117 } | 116 } |
118 | 117 |
119 bool MallocExtension::SetNumericProperty(const char* property, size_t value) { | 118 bool MallocExtension::SetNumericProperty(const char* property, size_t value) { |
120 return false; | 119 return false; |
121 } | 120 } |
122 | 121 |
123 void MallocExtension::GetStats(char* buffer, int length) { | 122 void MallocExtension::GetStats(char* buffer, int length) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 } | 169 } |
171 | 170 |
172 double MallocExtension::GetMemoryReleaseRate() { | 171 double MallocExtension::GetMemoryReleaseRate() { |
173 return -1.0; | 172 return -1.0; |
174 } | 173 } |
175 | 174 |
176 size_t MallocExtension::GetEstimatedAllocatedSize(size_t size) { | 175 size_t MallocExtension::GetEstimatedAllocatedSize(size_t size) { |
177 return size; | 176 return size; |
178 } | 177 } |
179 | 178 |
180 size_t MallocExtension::GetAllocatedSize(const void* p) { | 179 size_t MallocExtension::GetAllocatedSize(void* p) { |
181 assert(GetOwnership(p) != kNotOwned); | |
182 return 0; | 180 return 0; |
183 } | 181 } |
184 | 182 |
185 MallocExtension::Ownership MallocExtension::GetOwnership(const void* p) { | |
186 return kUnknownOwnership; | |
187 } | |
188 | |
189 void MallocExtension::GetFreeListSizes( | 183 void MallocExtension::GetFreeListSizes( |
190 vector<MallocExtension::FreeListInfo>* v) { | 184 vector<MallocExtension::FreeListInfo>* v) { |
191 v->clear(); | 185 v->clear(); |
192 } | 186 } |
193 | 187 |
194 // The current malloc extension object. | 188 // The current malloc extension object. |
195 | 189 |
196 static pthread_once_t module_init = PTHREAD_ONCE_INIT; | 190 static pthread_once_t module_init = PTHREAD_ONCE_INIT; |
197 static MallocExtension* current_instance = NULL; | 191 static MallocExtension* current_instance = NULL; |
198 | 192 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 return reinterpret_cast<uintptr_t>(entry[2]); | 231 return reinterpret_cast<uintptr_t>(entry[2]); |
238 } | 232 } |
239 void* PC(void** entry, int i) { | 233 void* PC(void** entry, int i) { |
240 return entry[3+i]; | 234 return entry[3+i]; |
241 } | 235 } |
242 | 236 |
243 void PrintCountAndSize(MallocExtensionWriter* writer, | 237 void PrintCountAndSize(MallocExtensionWriter* writer, |
244 uintptr_t count, uintptr_t size) { | 238 uintptr_t count, uintptr_t size) { |
245 char buf[100]; | 239 char buf[100]; |
246 snprintf(buf, sizeof(buf), | 240 snprintf(buf, sizeof(buf), |
247 "%6"PRIu64": %8"PRIu64" [%6"PRIu64": %8"PRIu64"] @", | 241 "%6lld: %8lld [%6lld: %8lld] @", |
248 static_cast<uint64>(count), | 242 static_cast<long long>(count), |
249 static_cast<uint64>(size), | 243 static_cast<long long>(size), |
250 static_cast<uint64>(count), | 244 static_cast<long long>(count), |
251 static_cast<uint64>(size)); | 245 static_cast<long long>(size)); |
252 writer->append(buf, strlen(buf)); | 246 writer->append(buf, strlen(buf)); |
253 } | 247 } |
254 | 248 |
255 void PrintHeader(MallocExtensionWriter* writer, | 249 void PrintHeader(MallocExtensionWriter* writer, |
256 const char* label, void** entries) { | 250 const char* label, void** entries) { |
257 // Compute the total count and total size | 251 // Compute the total count and total size |
258 uintptr_t total_count = 0; | 252 uintptr_t total_count = 0; |
259 uintptr_t total_size = 0; | 253 uintptr_t total_size = 0; |
260 for (void** entry = entries; Count(entry) != 0; entry += 3 + Depth(entry)) { | 254 for (void** entry = entries; Count(entry) != 0; entry += 3 + Depth(entry)) { |
261 total_count += Count(entry); | 255 total_count += Count(entry); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 } | 330 } |
337 | 331 |
338 // These are C shims that work on the current instance. | 332 // These are C shims that work on the current instance. |
339 | 333 |
340 #define C_SHIM(fn, retval, paramlist, arglist) \ | 334 #define C_SHIM(fn, retval, paramlist, arglist) \ |
341 extern "C" PERFTOOLS_DLL_DECL retval MallocExtension_##fn paramlist { \ | 335 extern "C" PERFTOOLS_DLL_DECL retval MallocExtension_##fn paramlist { \ |
342 return MallocExtension::instance()->fn arglist; \ | 336 return MallocExtension::instance()->fn arglist; \ |
343 } | 337 } |
344 | 338 |
345 C_SHIM(VerifyAllMemory, int, (void), ()); | 339 C_SHIM(VerifyAllMemory, int, (void), ()); |
346 C_SHIM(VerifyNewMemory, int, (const void* p), (p)); | 340 C_SHIM(VerifyNewMemory, int, (void* p), (p)); |
347 C_SHIM(VerifyArrayNewMemory, int, (const void* p), (p)); | 341 C_SHIM(VerifyArrayNewMemory, int, (void* p), (p)); |
348 C_SHIM(VerifyMallocMemory, int, (const void* p), (p)); | 342 C_SHIM(VerifyMallocMemory, int, (void* p), (p)); |
349 C_SHIM(MallocMemoryStats, int, | 343 C_SHIM(MallocMemoryStats, int, |
350 (int* blocks, size_t* total, int histogram[kMallocHistogramSize]), | 344 (int* blocks, size_t* total, int histogram[kMallocHistogramSize]), |
351 (blocks, total, histogram)); | 345 (blocks, total, histogram)); |
352 | 346 |
353 C_SHIM(GetStats, void, | 347 C_SHIM(GetStats, void, |
354 (char* buffer, int buffer_length), (buffer, buffer_length)); | 348 (char* buffer, int buffer_length), (buffer, buffer_length)); |
355 C_SHIM(GetNumericProperty, int, | 349 C_SHIM(GetNumericProperty, int, |
356 (const char* property, size_t* value), (property, value)); | 350 (const char* property, size_t* value), (property, value)); |
357 C_SHIM(SetNumericProperty, int, | 351 C_SHIM(SetNumericProperty, int, |
358 (const char* property, size_t value), (property, value)); | 352 (const char* property, size_t value), (property, value)); |
359 | 353 |
360 C_SHIM(MarkThreadIdle, void, (void), ()); | 354 C_SHIM(MarkThreadIdle, void, (void), ()); |
361 C_SHIM(MarkThreadBusy, void, (void), ()); | 355 C_SHIM(MarkThreadBusy, void, (void), ()); |
362 C_SHIM(ReleaseFreeMemory, void, (void), ()); | 356 C_SHIM(ReleaseFreeMemory, void, (void), ()); |
363 C_SHIM(ReleaseToSystem, void, (size_t num_bytes), (num_bytes)); | 357 C_SHIM(ReleaseToSystem, void, (size_t num_bytes), (num_bytes)); |
364 C_SHIM(GetEstimatedAllocatedSize, size_t, (size_t size), (size)); | 358 C_SHIM(GetEstimatedAllocatedSize, size_t, (size_t size), (size)); |
365 C_SHIM(GetAllocatedSize, size_t, (const void* p), (p)); | 359 C_SHIM(GetAllocatedSize, size_t, (void* p), (p)); |
366 | |
367 // Can't use the shim here because of the need to translate the enums. | |
368 extern "C" | |
369 MallocExtension_Ownership MallocExtension_GetOwnership(const void* p) { | |
370 return static_cast<MallocExtension_Ownership>( | |
371 MallocExtension::instance()->GetOwnership(p)); | |
372 } | |
OLD | NEW |