aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2018-03-12 09:36:28 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2018-03-12 09:36:28 +0000
commit07806a3e66c8c976463007b29abf2dd007bc1719 (patch)
treef352fe7b5e91bdfe93ff6b89d6683d3cc2eea7b4
parent032f93be52d777a62d17d0e2f530b5cc4039f08e (diff)
parenta3429024faffa2025b280d88af46cdab5a7c4a77 (diff)
downloadperf_data_converter-07806a3e66c8c976463007b29abf2dd007bc1719.tar.gz
Snap for 4648378 from a3429024faffa2025b280d88af46cdab5a7c4a77 to qt-release
Change-Id: Iefbdf09d981a92d8bc6f955eb90802b883201d0f
-rw-r--r--.gitignore1
-rw-r--r--.gitmodules6
-rw-r--r--METADATA17
-rw-r--r--MODULE_LICENSE_BSD0
-rw-r--r--NOTICE25
-rw-r--r--src/quipper/Android.bp241
-rw-r--r--src/quipper/androidbase/base/logging.cc11
-rw-r--r--src/quipper/androidbase/base/logging.h30
-rw-r--r--src/quipper/androidbase/base/macros.h10
-rw-r--r--src/quipper/dso_android.cc97
-rw-r--r--src/quipper/dso_test_utils.cc6
-rw-r--r--src/quipper/huge_page_deducer.cc5
12 files changed, 440 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index 4399f82..f9b4105 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,7 +3,6 @@
*.d
*.o
-quipper
perf_converter
perf_to_profile
intervalmap_test
diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644
index 68fa4b9..0000000
--- a/.gitmodules
+++ /dev/null
@@ -1,6 +0,0 @@
-[submodule "third_party/protobuf"]
- path = third_party/protobuf
- url = git://github.com/google/protobuf.git
-[submodule "third_party/googletest"]
- path = third_party/googletest
- url = git://github.com/google/googletest.git
diff --git a/METADATA b/METADATA
new file mode 100644
index 0000000..1101596
--- /dev/null
+++ b/METADATA
@@ -0,0 +1,17 @@
+name: "perf_data_converter"
+description:
+ "Tool to convert Linux perf files to the profile.proto format used by pprof"
+
+third_party {
+ url {
+ type: HOMEPAGE
+ value: "https://github.com/google/perf_data_converter"
+ }
+ url {
+ type: GIT
+ value: "https://github.com/gooogle/perf_data_converter"
+ }
+ version: "e8f1389fde85a2b7e9e05afdb66bfbb794632c00"
+ last_upgrade_date { year: 2018 month: 2 day: 27 }
+ license_type: NOTICE
+}
diff --git a/MODULE_LICENSE_BSD b/MODULE_LICENSE_BSD
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/MODULE_LICENSE_BSD
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..1a881d7
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,25 @@
+Copyright (c) 2016, Google Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the Google Inc. nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/src/quipper/Android.bp b/src/quipper/Android.bp
new file mode 100644
index 0000000..bdc2378
--- /dev/null
+++ b/src/quipper/Android.bp
@@ -0,0 +1,241 @@
+//
+// Copyright (C) 2018 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.
+//
+
+cc_defaults {
+ name: "libquipper_defaults",
+
+ cflags: [
+ "-Wno-unused",
+ "-Wno-unused-parameter",
+ "-Wno-missing-field-initializers",
+ "-O3",
+ "-g",
+ ],
+
+ srcs: [
+ "address_mapper.cc",
+ "binary_data_utils.cc",
+ "buffer_reader.cc",
+ "buffer_writer.cc",
+ "data_reader.cc",
+ "data_writer.cc",
+ "dso_android.cc", // Android-modified, rely on simpleperf/LLVM.
+ "file_reader.cc",
+ "file_utils.cc",
+ "huge_page_deducer.cc",
+ "androidbase/base/logging.cc",
+ "perf_option_parser.cc",
+ "perf_data_utils.cc",
+ "perf_parser.cc",
+ "perf_protobuf_io.cc",
+ "perf_reader.cc",
+ "perf_recorder.cc",
+ "perf_serializer.cc",
+ "perf_stat_parser.cc",
+ "run_command.cc",
+ "sample_info_reader.cc",
+ "scoped_temp_path.cc",
+ "string_utils.cc",
+ // Protos.
+ "perf_data.proto",
+ "perf_stat.proto",
+ ],
+ local_include_dirs: [
+ "compat/non_cros",
+ "androidbase",
+ ],
+ static_libs: [
+ "libbase",
+ "libsimpleperf_elf_read",
+ ],
+ whole_static_libs: [
+ "libcrypto", // For MD5.
+ ],
+
+ export_include_dirs: [
+ ".",
+ "androidbase",
+ ],
+ proto: {
+ canonical_path_from_root: true,
+ export_proto_headers: true,
+ },
+
+ target: {
+ darwin: {
+ enabled: false,
+ },
+ },
+}
+
+cc_library_static {
+ name: "libquipper",
+ defaults: [ "libquipper_defaults" ],
+ host_supported: true,
+
+ proto: {
+ type: "lite",
+ },
+ static_libs: [
+ "libprotobuf-cpp-lite",
+ ],
+}
+
+cc_library_static {
+ name: "libquipper-full",
+ defaults: [ "libquipper_defaults" ],
+ host_supported: true,
+
+ srcs: [
+ "conversion_utils.cc",
+ ],
+
+ proto: {
+ type: "full",
+ },
+ shared_libs: [
+ "libprotobuf-cpp-full",
+ ],
+}
+
+cc_defaults {
+ name: "quipper_test_defaults",
+ host_supported: true,
+ srcs: [
+ // Independent test infra.
+ "perf_test_files.cc",
+ "test_perf_data.cc",
+ "test_runner.cc",
+ ],
+ local_include_dirs: [
+ "compat/non_cros",
+ ],
+ cflags: [
+ "-Wno-ignored-qualifiers",
+ "-Wno-missing-field-initializers",
+ "-Wno-sign-compare",
+ "-Wno-unused",
+ "-Wno-unused-parameter",
+ ],
+ static_libs: [
+ "libsimpleperf_elf_read",
+ ],
+ target: {
+ darwin: {
+ enabled: false,
+ },
+ },
+}
+
+cc_defaults {
+ name: "quipper_android_test_defaults",
+ defaults: ["quipper_test_defaults"],
+ srcs: [
+ // Independent tests.
+ "address_mapper_test.cc",
+ "binary_data_utils_test.cc",
+ "buffer_reader_test.cc",
+ "buffer_writer_test.cc",
+ "file_reader_test.cc",
+ "perf_data_utils_test.cc",
+ "perf_option_parser_test.cc",
+ "perf_stat_parser_test.cc",
+ "run_command_test.cc",
+ "sample_info_reader_test.cc",
+ "scoped_temp_path_test.cc",
+ ],
+}
+
+cc_test {
+ name: "quipper_unit_tests",
+ defaults: [ "quipper_android_test_defaults" ],
+ host_supported: true,
+
+ static_libs: [
+ "libbase",
+ "liblog",
+ "libprotobuf-cpp-lite",
+ "libquipper",
+ ],
+}
+
+cc_test {
+ name: "quipper-full_unit_tests",
+ defaults: [ "quipper_android_test_defaults" ],
+ host_supported: true,
+
+ srcs: [
+ "test_utils.cc",
+
+ "conversion_utils_test.cc",
+ "perf_reader_test.cc",
+ "perf_serializer_test.cc",
+ ],
+
+ static_libs: [
+ "libquipper-full",
+ "libutils",
+ ],
+ shared_libs: [
+ "libbase",
+ "libprotobuf-cpp-full",
+ ],
+
+ target: {
+ // Required for LLVM in libsimpleperf_elf_read.
+ linux_glibc: {
+ host_ldlibs: [
+ "-lncurses",
+ ],
+ },
+ },
+}
+
+cc_test {
+ name: "quipper_libelf_test",
+ defaults: [ "quipper_test_defaults" ],
+ device_supported: false,
+ enabled: false,
+
+ srcs: [
+ "dso_test_utils.cc",
+ "test_utils.cc",
+
+ "dso_test.cc",
+ "perf_parser_test.cc",
+ ],
+
+ static_libs: [
+ "libcap", // For cap_get_proc etc.
+ "libelf", // For gelf.h, elf_version, ...
+ "libquipper-full",
+ "libutils",
+ "libz", // For libelf.
+ ],
+ shared_libs: [
+ "libprotobuf-cpp-full",
+ ],
+
+ target: {
+ // Required for LLVM in libsimpleperf_elf_read.
+ linux_glibc: {
+ host_ldlibs: [
+ "-lncurses",
+ ],
+ },
+ },
+}
+
diff --git a/src/quipper/androidbase/base/logging.cc b/src/quipper/androidbase/base/logging.cc
new file mode 100644
index 0000000..89df308
--- /dev/null
+++ b/src/quipper/androidbase/base/logging.cc
@@ -0,0 +1,11 @@
+// Copyright 2015 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/logging.h"
+
+namespace logging {
+
+bool gVlogEnabled = false;
+
+} // namespace logging
diff --git a/src/quipper/androidbase/base/logging.h b/src/quipper/androidbase/base/logging.h
new file mode 100644
index 0000000..f19babc
--- /dev/null
+++ b/src/quipper/androidbase/base/logging.h
@@ -0,0 +1,30 @@
+// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMIUMOS_WIDE_PROFILING_MYBASE_BASE_LOGGING_H_
+#define CHROMIUMOS_WIDE_PROFILING_MYBASE_BASE_LOGGING_H_
+
+#include <errno.h> // for errno
+#include <string.h> // for strerror
+
+#include <iostream>
+#include <sstream>
+#include <string>
+
+#include "android-base/logging.h"
+
+// Emulate Chrome-like logging.
+
+namespace logging {
+
+extern bool gVlogEnabled;
+
+} // namespace logging
+
+#define VLOG(level) ::logging::gVlogEnabled && LOG(INFO)
+
+#define DLOG(x) LOG(x)
+#define DVLOG(x) VLOG(x)
+
+#endif // CHROMIUMOS_WIDE_PROFILING_MYBASE_BASE_LOGGING_H_
diff --git a/src/quipper/androidbase/base/macros.h b/src/quipper/androidbase/base/macros.h
new file mode 100644
index 0000000..be04d17
--- /dev/null
+++ b/src/quipper/androidbase/base/macros.h
@@ -0,0 +1,10 @@
+// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMIUMOS_WIDE_PROFILING_MYBASE_BASE_MACROS_H_
+#define CHROMIUMOS_WIDE_PROFILING_MYBASE_BASE_MACROS_H_
+
+#include "android-base/macros.h"
+
+#endif // CHROMIUMOS_WIDE_PROFILING_MYBASE_BASE_MACROS_H_
diff --git a/src/quipper/dso_android.cc b/src/quipper/dso_android.cc
new file mode 100644
index 0000000..614c4e8
--- /dev/null
+++ b/src/quipper/dso_android.cc
@@ -0,0 +1,97 @@
+// Copyright 2016 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "dso.h"
+
+#include <elf.h>
+#include <fcntl.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
+#include <unistd.h>
+
+#include <algorithm>
+#include <vector>
+
+#include <build_id.h>
+#include <read_elf.h>
+
+#include "base/logging.h"
+#include "compat/string.h"
+#include "file_reader.h"
+
+namespace quipper {
+
+void InitializeLibelf() {
+ // Unnecessary.
+}
+
+bool ReadElfBuildId(const string &filename, string *buildid) {
+ BuildId id;
+ ElfStatus status = GetBuildIdFromElfFile(filename, &id);
+ if (status == ElfStatus::NO_ERROR) {
+ *buildid = id.ToString();
+ return true;
+ }
+ return false;
+}
+
+bool ReadElfBuildId(int fd, string *buildid) {
+ // TODO: Implement. b/74410255.
+ return false;
+}
+
+// read /sys/module/<module_name>/notes/.note.gnu.build-id
+bool ReadModuleBuildId(const string &module_name, string *buildid) {
+ string note_filename =
+ "/sys/module/" + module_name + "/notes/.note.gnu.build-id";
+
+ FileReader file(note_filename);
+ if (!file.IsOpen()) return false;
+
+ return ReadBuildIdNote(&file, buildid);
+}
+
+bool ReadBuildIdNote(DataReader *data, string *buildid) {
+ // Non-simpleperf implementation, as a reader is given.
+ Elf64_Nhdr note_header;
+
+ while (data->ReadData(sizeof(note_header), &note_header)) {
+ size_t name_size = Align<4>(note_header.n_namesz);
+ size_t desc_size = Align<4>(note_header.n_descsz);
+
+ string name;
+ if (!data->ReadString(name_size, &name)) return false;
+ string desc;
+ if (!data->ReadDataString(desc_size, &desc)) return false;
+ if (note_header.n_type == NT_GNU_BUILD_ID && name == ELF_NOTE_GNU) {
+ *buildid = desc;
+ return true;
+ }
+ }
+ return false;
+}
+
+bool IsKernelNonModuleName(string name) {
+ // List from kernel: tools/perf/util/dso.c : __kmod_path__parse()
+ static const std::vector<string> kKernelNonModuleNames{
+ "[kernel.kallsyms]",
+ "[guest.kernel.kallsyms",
+ "[vdso]",
+ "[vsyscall]",
+ };
+
+ for (const auto &n : kKernelNonModuleNames) {
+ if (name.compare(0, n.size(), n) == 0) return true;
+ }
+ return false;
+}
+
+// Do the |DSOInfo| and |struct stat| refer to the same inode?
+bool SameInode(const DSOInfo &dso, const struct stat *s) {
+ return dso.maj == major(s->st_dev) && dso.min == minor(s->st_dev) &&
+ dso.ino == s->st_ino;
+}
+
+} // namespace quipper
diff --git a/src/quipper/dso_test_utils.cc b/src/quipper/dso_test_utils.cc
index fd8aae0..9ba4f24 100644
--- a/src/quipper/dso_test_utils.cc
+++ b/src/quipper/dso_test_utils.cc
@@ -85,6 +85,12 @@ void WriteElfWithMultipleBuildids(
int fd = open(filename.data(), O_WRONLY | O_CREAT | O_TRUNC, 0660);
CHECK_GE(fd, 0) << strerror(errno);
+ // ANDROID-CHANGED: Ensure libelf is initialized, as dso_android doesn't.
+ {
+ const unsigned int kElfVersionNone = EV_NONE; // correctly typed.
+ CHECK_NE(kElfVersionNone, elf_version(EV_CURRENT)) << elf_errmsg(-1);
+ }
+
Elf *elf = elf_begin(fd, ELF_C_WRITE, nullptr);
CHECK(elf) << elf_errmsg(-1);
Elf64_Ehdr *elf_header = elf64_newehdr(elf);
diff --git a/src/quipper/huge_page_deducer.cc b/src/quipper/huge_page_deducer.cc
index d68d703..f4c3486 100644
--- a/src/quipper/huge_page_deducer.cc
+++ b/src/quipper/huge_page_deducer.cc
@@ -189,8 +189,9 @@ void UpdateRangeFromNext(const MMapRange& range, const MMapRange& next_range,
// Replace "//anon" with a regular name if possible.
if (IsAnon(*mmap)) {
- CHECK_EQ(mmap->pgoff(), 0) << "//anon should have offset=0 for mmap"
- << event->ShortDebugString();
+ // ANDROID-CHANGED: protobuf-lite.
+ CHECK_EQ(mmap->pgoff(), 0u) << "//anon should have offset=0 for mmap";
+ // << event->ShortDebugString();
SetMmapFilename(event, src.filename(), src.filename_md5_prefix());
}