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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 DEFINE_bool(mmap_profile, | 118 DEFINE_bool(mmap_profile, |
119 EnvToBool("HEAP_PROFILE_MMAP", false), | 119 EnvToBool("HEAP_PROFILE_MMAP", false), |
120 "If heap-profiling is on, also profile mmap, mremap, and sbrk)"); | 120 "If heap-profiling is on, also profile mmap, mremap, and sbrk)"); |
121 DEFINE_bool(only_mmap_profile, | 121 DEFINE_bool(only_mmap_profile, |
122 EnvToBool("HEAP_PROFILE_ONLY_MMAP", false), | 122 EnvToBool("HEAP_PROFILE_ONLY_MMAP", false), |
123 "If heap-profiling is on, only profile mmap, mremap, and sbrk; " | 123 "If heap-profiling is on, only profile mmap, mremap, and sbrk; " |
124 "do not profile malloc/new/etc"); | 124 "do not profile malloc/new/etc"); |
125 DEFINE_bool(deep_heap_profile, | 125 DEFINE_bool(deep_heap_profile, |
126 EnvToBool("DEEP_HEAP_PROFILE", false), | 126 EnvToBool("DEEP_HEAP_PROFILE", false), |
127 "If heap-profiling is on, profile deeper (only on Linux)"); | 127 "If heap-profiling is on, profile deeper (only on Linux)"); |
| 128 #if defined(TYPE_PROFILING) |
| 129 DEFINE_bool(heap_profile_type_statistics, |
| 130 EnvToBool("HEAP_PROFILE_TYPE_STATISTICS", false), |
| 131 "If heap-profiling is on, dump type statistics."); |
| 132 #endif // defined(TYPE_PROFILING) |
128 | 133 |
129 | 134 |
130 //---------------------------------------------------------------------- | 135 //---------------------------------------------------------------------- |
131 // Locking | 136 // Locking |
132 //---------------------------------------------------------------------- | 137 //---------------------------------------------------------------------- |
133 | 138 |
134 // A pthread_mutex has way too much lock contention to be used here. | 139 // A pthread_mutex has way too much lock contention to be used here. |
135 // | 140 // |
136 // I would like to use Mutex, but it can call malloc(), | 141 // I would like to use Mutex, but it can call malloc(), |
137 // which can cause us to fall into an infinite recursion. | 142 // which can cause us to fall into an infinite recursion. |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 if (global_profiler_buffer == NULL) { | 303 if (global_profiler_buffer == NULL) { |
299 global_profiler_buffer = | 304 global_profiler_buffer = |
300 reinterpret_cast<char*>(ProfilerMalloc(kProfileBufferSize)); | 305 reinterpret_cast<char*>(ProfilerMalloc(kProfileBufferSize)); |
301 } | 306 } |
302 | 307 |
303 char* profile = DoGetHeapProfileLocked(global_profiler_buffer, | 308 char* profile = DoGetHeapProfileLocked(global_profiler_buffer, |
304 kProfileBufferSize); | 309 kProfileBufferSize); |
305 RawWrite(fd, profile, strlen(profile)); | 310 RawWrite(fd, profile, strlen(profile)); |
306 RawClose(fd); | 311 RawClose(fd); |
307 | 312 |
| 313 #if defined(TYPE_PROFILING) |
| 314 if (FLAGS_heap_profile_type_statistics) { |
| 315 snprintf(file_name, sizeof(file_name), "%s.%05d.%04d.type", |
| 316 filename_prefix, getpid(), dump_count); |
| 317 RAW_VLOG(0, "Dumping type statistics to %s", file_name); |
| 318 heap_profile->DumpTypeStatistics(file_name); |
| 319 } |
| 320 #endif // defined(TYPE_PROFILING) |
| 321 |
308 dumping = false; | 322 dumping = false; |
309 } | 323 } |
310 | 324 |
311 //---------------------------------------------------------------------- | 325 //---------------------------------------------------------------------- |
312 // Profile collection | 326 // Profile collection |
313 //---------------------------------------------------------------------- | 327 //---------------------------------------------------------------------- |
314 | 328 |
315 // Dump a profile after either an allocation or deallocation, if | 329 // Dump a profile after either an allocation or deallocation, if |
316 // the memory use has changed enough since the last dump. | 330 // the memory use has changed enough since the last dump. |
317 static void MaybeDumpProfileLocked() { | 331 static void MaybeDumpProfileLocked() { |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 | 666 |
653 // class used for finalization -- dumps the heap-profile at program exit | 667 // class used for finalization -- dumps the heap-profile at program exit |
654 struct HeapProfileEndWriter { | 668 struct HeapProfileEndWriter { |
655 ~HeapProfileEndWriter() { HeapProfilerDump("Exiting"); } | 669 ~HeapProfileEndWriter() { HeapProfilerDump("Exiting"); } |
656 }; | 670 }; |
657 | 671 |
658 // We want to make sure tcmalloc is up and running before starting the profiler | 672 // We want to make sure tcmalloc is up and running before starting the profiler |
659 static const TCMallocGuard tcmalloc_initializer; | 673 static const TCMallocGuard tcmalloc_initializer; |
660 REGISTER_MODULE_INITIALIZER(heapprofiler, HeapProfilerInit()); | 674 REGISTER_MODULE_INITIALIZER(heapprofiler, HeapProfilerInit()); |
661 static HeapProfileEndWriter heap_profile_end_writer; | 675 static HeapProfileEndWriter heap_profile_end_writer; |
OLD | NEW |