Chromium Code Reviews| 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 // exit due to out-of-memory. This buffer is allocated in | 195 // exit due to out-of-memory. This buffer is allocated in |
| 196 // HeapProfilerStart. Access to this must be protected by heap_lock. | 196 // HeapProfilerStart. Access to this must be protected by heap_lock. |
| 197 static char* global_profiler_buffer = NULL; | 197 static char* global_profiler_buffer = NULL; |
| 198 | 198 |
| 199 | 199 |
| 200 //---------------------------------------------------------------------- | 200 //---------------------------------------------------------------------- |
| 201 // Profiling control/state data | 201 // Profiling control/state data |
| 202 //---------------------------------------------------------------------- | 202 //---------------------------------------------------------------------- |
| 203 | 203 |
| 204 // Access to all of these is protected by heap_lock. | 204 // Access to all of these is protected by heap_lock. |
| 205 static bool is_on = false; // If are on as a subsytem. | 205 static bool is_on = false; // If are on as a subsytem. |
|
jar (doing other things)
2012/06/11 08:53:14
nit: I couldn't make sense of the variable name, o
jochen (gone - plz use gerrit)
2012/06/11 13:13:47
I agree that the variable naming is not optimal, b
| |
| 206 static bool dumping = false; // Dumping status to prevent recursion | 206 static bool dumping = false; // Dumping status to prevent recursion |
| 207 static char* filename_prefix = NULL; // Prefix used for profile file names | 207 static char* filename_prefix = NULL; // Prefix used for profile file names |
| 208 // (NULL if no need for dumping yet) | 208 // (NULL if no need for dumping yet) |
| 209 static int dump_count = 0; // How many dumps so far | 209 static int dump_count = 0; // How many dumps so far |
| 210 static int64 last_dump_alloc = 0; // alloc_size when did we last dump | 210 static int64 last_dump_alloc = 0; // alloc_size when did we last dump |
| 211 static int64 last_dump_free = 0; // free_size when did we last dump | 211 static int64 last_dump_free = 0; // free_size when did we last dump |
| 212 static int64 high_water_mark = 0; // In-use-bytes at last high-water dump | 212 static int64 high_water_mark = 0; // In-use-bytes at last high-water dump |
| 213 static int64 last_dump_time = 0; // The time of the last dump | 213 static int64 last_dump_time = 0; // The time of the last dump |
| 214 | 214 |
| 215 static HeapProfileTable* heap_profile = NULL; // the heap profile table | 215 static HeapProfileTable* heap_profile = NULL; // the heap profile table |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 594 is_on = false; | 594 is_on = false; |
| 595 } | 595 } |
| 596 | 596 |
| 597 extern "C" void HeapProfilerDump(const char* reason) { | 597 extern "C" void HeapProfilerDump(const char* reason) { |
| 598 SpinLockHolder l(&heap_lock); | 598 SpinLockHolder l(&heap_lock); |
| 599 if (is_on && !dumping) { | 599 if (is_on && !dumping) { |
| 600 DumpProfileLocked(reason); | 600 DumpProfileLocked(reason); |
| 601 } | 601 } |
| 602 } | 602 } |
| 603 | 603 |
| 604 extern "C" void HeapProfilerMarkBaseline() { | |
| 605 SpinLockHolder l(&heap_lock); | |
| 606 | |
| 607 if (!is_on) return; | |
| 608 | |
| 609 heap_profile->MarkCurrentAllocations(HeapProfileTable::MARK_ONE); | |
| 610 } | |
| 611 | |
| 612 extern "C" void HeapProfilerMarkInteresting() { | |
| 613 SpinLockHolder l(&heap_lock); | |
| 614 | |
| 615 if (!is_on) return; | |
| 616 | |
| 617 heap_profile->MarkUnmarkedAllocations(HeapProfileTable::MARK_TWO); | |
| 618 } | |
| 619 | |
| 620 extern "C" void HeapProfilerDumpAliveObjects(const char* filename) { | |
| 621 SpinLockHolder l(&heap_lock); | |
| 622 | |
| 623 if (!is_on) return; | |
| 624 | |
| 625 heap_profile->DumpMarkedObjects(HeapProfileTable::MARK_TWO, filename); | |
| 626 } | |
| 627 | |
| 604 //---------------------------------------------------------------------- | 628 //---------------------------------------------------------------------- |
| 605 // Initialization/finalization code | 629 // Initialization/finalization code |
| 606 //---------------------------------------------------------------------- | 630 //---------------------------------------------------------------------- |
| 607 | 631 |
| 608 // Initialization code | 632 // Initialization code |
| 609 static void HeapProfilerInit() { | 633 static void HeapProfilerInit() { |
| 610 // Everything after this point is for setting up the profiler based on envvar | 634 // Everything after this point is for setting up the profiler based on envvar |
| 611 char fname[PATH_MAX]; | 635 char fname[PATH_MAX]; |
| 612 if (!GetUniquePathFromEnv("HEAPPROFILE", fname)) { | 636 if (!GetUniquePathFromEnv("HEAPPROFILE", fname)) { |
| 613 return; | 637 return; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 628 | 652 |
| 629 // class used for finalization -- dumps the heap-profile at program exit | 653 // class used for finalization -- dumps the heap-profile at program exit |
| 630 struct HeapProfileEndWriter { | 654 struct HeapProfileEndWriter { |
| 631 ~HeapProfileEndWriter() { HeapProfilerDump("Exiting"); } | 655 ~HeapProfileEndWriter() { HeapProfilerDump("Exiting"); } |
| 632 }; | 656 }; |
| 633 | 657 |
| 634 // We want to make sure tcmalloc is up and running before starting the profiler | 658 // We want to make sure tcmalloc is up and running before starting the profiler |
| 635 static const TCMallocGuard tcmalloc_initializer; | 659 static const TCMallocGuard tcmalloc_initializer; |
| 636 REGISTER_MODULE_INITIALIZER(heapprofiler, HeapProfilerInit()); | 660 REGISTER_MODULE_INITIALIZER(heapprofiler, HeapProfilerInit()); |
| 637 static HeapProfileEndWriter heap_profile_end_writer; | 661 static HeapProfileEndWriter heap_profile_end_writer; |
| OLD | NEW |