summaryrefslogtreecommitdiff
path: root/simpleperf/report_utils.h
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2020-12-09 16:27:57 -0800
committerYabin Cui <yabinc@google.com>2020-12-11 13:56:24 -0800
commitac4b249ecf3887a1b258b95a54754389b4ec8b79 (patch)
tree4490728f66db3df2bb656184be5bbae04c130cd0 /simpleperf/report_utils.h
parentcae896b243eeb852b57c778e95b7ef5fae65d403 (diff)
downloadextras-ac4b249ecf3887a1b258b95a54754389b4ec8b79.tar.gz
simpleperf: extract common code into report_utils.cpp
Extract common code in cmd_report_sample.cpp and report_lib_interface.cpp, into report_utils.cpp. Bug: 175163225 Test: run simpleperf_unit_test. Test: run test.py TestReportLibs*. Change-Id: Ic64956cd1a73ef3165337aa3509a15d14e095959
Diffstat (limited to 'simpleperf/report_utils.h')
-rw-r--r--simpleperf/report_utils.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/simpleperf/report_utils.h b/simpleperf/report_utils.h
new file mode 100644
index 00000000..fb628bc5
--- /dev/null
+++ b/simpleperf/report_utils.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <inttypes.h>
+
+#include <vector>
+
+#include "dso.h"
+#include "thread_tree.h"
+
+namespace simpleperf {
+
+struct CallChainReportEntry {
+ uint64_t ip = 0;
+ const Symbol* symbol = nullptr;
+ Dso* dso = nullptr;
+ const char* dso_name = nullptr;
+ uint64_t vaddr_in_file = 0;
+ const MapEntry* map = nullptr;
+};
+
+class CallChainReportBuilder {
+ public:
+ CallChainReportBuilder(ThreadTree& thread_tree) : thread_tree_(thread_tree) {}
+ // If true, remove interpreter frames both before and after a Java frame.
+ // Default is true.
+ void SetRemoveArtFrame(bool enable) { remove_art_frame_ = enable; }
+ // If true, convert a JIT method into its corresponding interpreted Java method. So they can be
+ // merged in reports like flamegraph. Default is true.
+ void SetConvertJITFrame(bool enable) { convert_jit_frame_ = enable; }
+ std::vector<CallChainReportEntry> Build(const ThreadEntry* thread,
+ const std::vector<uint64_t>& ips, size_t kernel_ip_count);
+
+ private:
+ struct JavaMethod {
+ Dso* dso;
+ const Symbol* symbol;
+ JavaMethod(Dso* dso, const Symbol* symbol) : dso(dso), symbol(symbol) {}
+ };
+
+ void ConvertJITFrame(std::vector<CallChainReportEntry>& callchain);
+ void CollectJavaMethods();
+
+ ThreadTree& thread_tree_;
+ bool remove_art_frame_ = true;
+ bool convert_jit_frame_ = true;
+ bool java_method_initialized_ = false;
+ std::unordered_map<std::string, JavaMethod> java_method_map_;
+};
+
+} // namespace simpleperf