summaryrefslogtreecommitdiff
path: root/runtime/javaheapprof/javaheapsampler.cc
diff options
context:
space:
mode:
authorNicolas Geoffray <ngeoffray@google.com>2021-03-09 08:59:55 +0000
committerNicolas Geoffray <ngeoffray@google.com>2021-03-09 08:59:55 +0000
commit2291439187b06d995bb298683246416c75d92740 (patch)
tree8ae6ebb82f270ff7065e24105e57c79b8e7d83af /runtime/javaheapprof/javaheapsampler.cc
parent08e44f1a6289695530fcae887312fe69079ddf9a (diff)
Revert "Add API to ART/Perfetto Java Heap Profiler"
This reverts commit 08e44f1a6289695530fcae887312fe69079ddf9a. Bug: 160214819 Reason for revert: Tests breakage on target: +CANNOT LINK EXECUTABLE "/apex/com.android.art/bin/dex2oatd32": library "heapprofd_client_api.so" not found: needed by /apex/com.android.art/lib/libartd.so in namespace com_android_art Change-Id: I9509cc1e3c85ed4b1ec3347317c0e33fc1f96dea
Diffstat (limited to 'runtime/javaheapprof/javaheapsampler.cc')
-rw-r--r--runtime/javaheapprof/javaheapsampler.cc46
1 files changed, 35 insertions, 11 deletions
diff --git a/runtime/javaheapprof/javaheapsampler.cc b/runtime/javaheapprof/javaheapsampler.cc
index a73ed0b719..a1c58d8912 100644
--- a/runtime/javaheapprof/javaheapsampler.cc
+++ b/runtime/javaheapprof/javaheapsampler.cc
@@ -18,9 +18,6 @@
#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 {
@@ -61,13 +58,8 @@ 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, size_t allocation_size) {
+void HeapSampler::ReportSample(art::mirror::Object* obj ATTRIBUTE_UNUSED, 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
@@ -131,19 +123,51 @@ 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