diff options
author | Wessam Hassanein <wessam@google.com> | 2021-02-09 14:09:10 -0800 |
---|---|---|
committer | Treehugger Robot <treehugger-gerrit@google.com> | 2021-03-10 21:07:35 +0000 |
commit | 45a9fc9b683449bc0e996e64f3b37e2de071be76 (patch) | |
tree | 918e373ac2e24ed0759b8e093fd420aa42bb0784 /runtime/javaheapprof/javaheapsampler.cc | |
parent | f2893adb27211609c17c4cc8d083371da4888032 (diff) |
Add API to ART/Perfetto Java Heap Profiler (reland)
Add Perfetto API calls to ART Sampling Java Heap Profiler.
Test: Passing Tests
Local Testing
Bug: 160214819
Test: art/tools/run-gtests.sh
in ART chroot built on master-art (silvermont target)
Test: art/test/testrunner/testrunner.py --target --optimizing
in ART chroot built on master-art (silvermont target)
Test: art/tools/run-libcore-tests.sh --mode=device
in ART chroot built on master-art (silvermont target)
Test: m test-art-host-gtest
on master-art
Test: art/tools/buildbot-build.sh --host && \
art/test/testrunner/testrunner.py --host --64 --optimizing
on master-art
Bug: 179915934
This reverts commit 2291439187b06d995bb298683246416c75d92740
Change-Id: I600313b9515a2a3ff64361d7307b88d9a76c07e4
Diffstat (limited to 'runtime/javaheapprof/javaheapsampler.cc')
-rw-r--r-- | runtime/javaheapprof/javaheapsampler.cc | 46 |
1 files changed, 11 insertions, 35 deletions
diff --git a/runtime/javaheapprof/javaheapsampler.cc b/runtime/javaheapprof/javaheapsampler.cc index a1c58d8912..a73ed0b719 100644 --- a/runtime/javaheapprof/javaheapsampler.cc +++ b/runtime/javaheapprof/javaheapsampler.cc @@ -18,6 +18,9 @@ #include "base/locks.h" #include "gc/heap.h" #include "javaheapprof/javaheapsampler.h" +#ifdef ART_TARGET_ANDROID +#include "perfetto/heap_profile.h" +#endif #include "runtime.h" namespace art { @@ -58,8 +61,13 @@ size_t HeapSampler::PickAndAdjustNextSample(size_t sample_adjust_bytes) { // Also bytes_until_sample can only be updated after the allocation and reporting is done. // Thus next bytes_until_sample is previously calculated (before allocation) to be able to // get the next tlab_size, but only saved/updated here. -void HeapSampler::ReportSample(art::mirror::Object* obj ATTRIBUTE_UNUSED, size_t allocation_size) { +void HeapSampler::ReportSample(art::mirror::Object* obj, size_t allocation_size) { VLOG(heap) << "JHP:***Report Perfetto Allocation: alloc_size: " << allocation_size; + uint64_t perf_alloc_id = reinterpret_cast<uint64_t>(obj); + VLOG(heap) << "JHP:***Report Perfetto Allocation: obj: " << perf_alloc_id; +#ifdef ART_TARGET_ANDROID + AHeapProfile_reportSample(perfetto_heap_id_, perf_alloc_id, allocation_size); +#endif } // Check whether we should take a sample or not at this allocation and calculate the sample @@ -123,51 +131,19 @@ void HeapSampler::AdjustSampleOffset(size_t adjustment) { << " next_bytes_until_sample = " << next_bytes_until_sample; } -// Enable the heap sampler and initialize/set the sampling interval. -void HeapSampler::EnableHeapSampler(void* enable_ptr ATTRIBUTE_UNUSED, - const void* enable_info_ptr ATTRIBUTE_UNUSED) { - uint64_t interval = 4 * 1024; - // Set the ART profiler sampling interval to the value from AHeapProfileSessionInfo - // Set interval to sampling interval from AHeapProfileSessionInfo - if (interval > 0) { - // Make sure that rng_ and geo_dist are thread safe by acquiring a lock to access. - art::MutexLock mu(art::Thread::Current(), geo_dist_rng_lock_); - SetSamplingInterval(interval); - } - // Else default is 4K sampling interval. However, default case shouldn't happen for Perfetto API. - // AHeapProfileEnableCallbackInfo_getSamplingInterval should always give the requested - // (non-negative) sampling interval. It is a uint64_t and gets checked for != 0 - // Do not call heap->GetPerfettoJavaHeapProfHeapID() as a temp here, it will build but test run - // will silently fail. Heap is not fully constructed yet. - // heap_id will be set through the Perfetto API. - perfetto_heap_id_ = 1; // To be set by Perfetto API - enabled_.store(true, std::memory_order_release); -} - bool HeapSampler::IsEnabled() { return enabled_.load(std::memory_order_acquire); } -void HeapSampler::DisableHeapSampler(void* disable_ptr ATTRIBUTE_UNUSED, - const void* disable_info_ptr ATTRIBUTE_UNUSED) { - enabled_.store(false, std::memory_order_release); -} - int HeapSampler::GetSamplingInterval() { return p_sampling_interval_.load(std::memory_order_acquire); } void HeapSampler::SetSamplingInterval(int sampling_interval) { + // Make sure that rng_ and geo_dist are thread safe by acquiring a lock to access. + art::MutexLock mu(art::Thread::Current(), geo_dist_rng_lock_); p_sampling_interval_.store(sampling_interval, std::memory_order_release); geo_dist_.param(std::geometric_distribution<size_t>::param_type(1.0/p_sampling_interval_)); } -void HeapSampler::SetSessionInfo(void* info) { - perfetto_session_info_ = info; -} - -void* HeapSampler::GetSessionInfo() { - return perfetto_session_info_; -} - } // namespace art |