diff options
author | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-15 23:05:01 +0000 |
---|---|---|
committer | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-15 23:05:01 +0000 |
commit | 90895d0f3265926221f00b3571332066a0bcb375 (patch) | |
tree | ee36e96f7bc1bfd52d0370cfc9324bee7ac1d631 /third_party | |
parent | a8c119da0066b18c472559dd80e58e9895d5ee06 (diff) | |
download | chromium_src-90895d0f3265926221f00b3571332066a0bcb375.zip chromium_src-90895d0f3265926221f00b3571332066a0bcb375.tar.gz chromium_src-90895d0f3265926221f00b3571332066a0bcb375.tar.bz2 |
Support use of third party time function for about:profiler
This uses TCMalloc to provide a time function, allowing
us to see how much memory was allocated on a single thread
during the running of a task. The alternate time function
is put in place only when a specific environment variable
is detected during TCMalloc startup.
This change currently is activated only in Windows/Linux,
as it is based on changes TCMalloc (not used on Mac).
We also create an infrastructure for using any alternate
timer, to replace the "wall clock time," on a per-thread
basis, in the about:profiler infrastructure. That interface
may be used on other platforms, including scenarios where
we have a per-thread-CPU-time function to replace the
wall-clock timer. In all cases, when this alternate timer
is activated, we lose the ability to calculated queueing
time. Queueing time is based on a time snapshot taken on
a second thread, and hence is not comparable to the
alternate timer (when the alternate timer is engaged).
r=rtenneti
BUG=103321
Review URL: https://chromiumcodereview.appspot.com/9212025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122180 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party')
-rw-r--r-- | third_party/tcmalloc/chromium/src/tcmalloc.cc | 8 | ||||
-rw-r--r-- | third_party/tcmalloc/chromium/src/thread_cache.cc | 6 | ||||
-rw-r--r-- | third_party/tcmalloc/chromium/src/thread_cache.h | 23 |
3 files changed, 37 insertions, 0 deletions
diff --git a/third_party/tcmalloc/chromium/src/tcmalloc.cc b/third_party/tcmalloc/chromium/src/tcmalloc.cc index 51fe5b3..9381aaf 100644 --- a/third_party/tcmalloc/chromium/src/tcmalloc.cc +++ b/third_party/tcmalloc/chromium/src/tcmalloc.cc @@ -1130,6 +1130,8 @@ inline void* do_malloc_pages(ThreadCache* heap, size_t size) { Length num_pages = tcmalloc::pages(size); size = num_pages << kPageShift; + heap->AddToByteAllocatedTotal(size); // Chromium profiling. + if ((FLAGS_tcmalloc_sample_parameter > 0) && heap->SampleAllocation(size)) { result = DoSampledAllocation(size); @@ -1159,6 +1161,12 @@ inline void* do_malloc(size_t size) { size_t cl = Static::sizemap()->SizeClass(size); size = Static::sizemap()->class_to_size(cl); + // TODO(jar): If this has any detectable performance impact, it can be + // optimized by only tallying sizes if the profiler was activated to recall + // these tallies. I don't think this is performance critical, but we really + // should measure it. + heap->AddToByteAllocatedTotal(size); // Chromium profiling. + if ((FLAGS_tcmalloc_sample_parameter > 0) && heap->SampleAllocation(size)) { ret = DoSampledAllocation(size); MarkAllocatedRegion(ret); diff --git a/third_party/tcmalloc/chromium/src/thread_cache.cc b/third_party/tcmalloc/chromium/src/thread_cache.cc index a951f77..1c189f3 100644 --- a/third_party/tcmalloc/chromium/src/thread_cache.cc +++ b/third_party/tcmalloc/chromium/src/thread_cache.cc @@ -103,6 +103,7 @@ bool kernel_supports_tls = false; // be conservative void ThreadCache::Init(pthread_t tid) { size_ = 0; + total_bytes_allocated_ = 0; max_size_ = 0; IncreaseCacheLimitLocked(); @@ -303,6 +304,11 @@ int ThreadCache::GetSamplePeriod() { return sampler_.GetSamplePeriod(); } +// static +unsigned int ThreadCache::GetBytesAllocatedOnCurrentThread() { + return ThreadCache::GetThreadHeap()->GetTotalBytesAllocated(); +} + void ThreadCache::InitModule() { SpinLockHolder h(Static::pageheap_lock()); if (!phinited) { diff --git a/third_party/tcmalloc/chromium/src/thread_cache.h b/third_party/tcmalloc/chromium/src/thread_cache.h index 9220aab..d631f45 100644 --- a/third_party/tcmalloc/chromium/src/thread_cache.h +++ b/third_party/tcmalloc/chromium/src/thread_cache.h @@ -96,6 +96,17 @@ class ThreadCache { // should be sampled bool SampleAllocation(size_t k); + // Record additional bytes allocated. + void AddToByteAllocatedTotal(size_t k) { total_bytes_allocated_ += k; } + + // Return the total number of bytes allocated from this heap. The value will + // wrap when there is an overflow, and so only the differences between two + // values should be relied on (and even then, modulo 2^32). + uint32 GetTotalBytesAllocated() const; + + // On the current thread, return GetTotalBytesAllocated(). + static uint32 GetBytesAllocatedOnCurrentThread(); + static void InitModule(); static void InitTSD(); static ThreadCache* GetThreadHeap(); @@ -291,6 +302,14 @@ class ThreadCache { size_t size_; // Combined size of data size_t max_size_; // size_ > max_size_ --> Scavenge() + // The following is the tally of bytes allocated on a thread as a response to + // any flavor of malloc() call. The aggegated amount includes all padding to + // the smallest class that can hold the request, or to the nearest whole page + // when a large allocation is made without using a class. This sum is + // currently used for Chromium profiling, where tallies are kept of the amount + // of memory allocated during the running of each task on each thread. + uint32 total_bytes_allocated_; // Total, modulo 2^32. + // We sample allocations, biased by the size of the allocation Sampler sampler_; // A sampler @@ -327,6 +346,10 @@ inline bool ThreadCache::SampleAllocation(size_t k) { return sampler_.SampleAllocation(k); } +inline uint32 ThreadCache::GetTotalBytesAllocated() const { + return total_bytes_allocated_; +} + inline void* ThreadCache::Allocate(size_t size, size_t cl) { ASSERT(size <= kMaxSize); ASSERT(size == Static::sizemap()->ByteSizeForClass(cl)); |