diff --git a/Makefile b/Makefile index 7f2e26c6..2c5466c7 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,7 @@ LIBRARY_SOURCES = $(QUIPPER_LIBRARY_SOURCES) $(CONVERTER_LIBRARY_SOURCES) QUIPPER_PROTOS = perf_data.proto perf_stat.proto QUIPPER_PROTOS := $(QUIPPER_PROTOS:%=${CWP}/%) -CONVERTER_PROTOS = profile.proto profile_wrappers.proto +CONVERTER_PROTOS = profile.proto QUIPPER_GENERATED_SOURCES = $(QUIPPER_PROTOS:.proto=.pb.cc) QUIPPER_GENERATED_HEADERS = $(QUIPPER_PROTOS:.proto=.pb.h) GENERATED_SOURCES = $(CONVERTER_PROTOS:.proto=.pb.cc) \ diff --git a/perf_data_converter.cc b/perf_data_converter.cc index d65b118c..974c2a3b 100644 --- a/perf_data_converter.cc +++ b/perf_data_converter.cc @@ -39,7 +39,6 @@ #include "int_compat.h" #include "intervalmap.h" #include "perf_data_handler.h" -#include "profile_wrappers.pb.h" #include "string_compat.h" namespace perftools { @@ -513,21 +512,6 @@ ProfileVector PerfDataConverter::Profiles() { return profiles; } -// Returns the provided ProfileVector as a serialized proto. -string SerializedProfileList(const ProfileVector& vec) { - ProfileList list; - for (const auto& profile : vec) { - *list.add_profile() = *profile; - } - - string serialized_out; - if (!list.SerializeToString(&serialized_out)) { - std::cerr << "Failed to serialize ProfileList" << std::endl; - abort(); - } - return serialized_out; -} - ProfileVector PerfDataProtoToProfileList(quipper::PerfDataProto* perf_data, uint32 sample_labels, bool group_by_pids) { @@ -539,8 +523,7 @@ ProfileVector PerfDataProtoToProfileList(quipper::PerfDataProto* perf_data, } // namespace ProfileVector RawPerfDataToProfileProto(const void* raw, int raw_size, - const void* build_ids, - int build_ids_size, + const std::map &build_id_map, uint32 sample_labels, bool group_by_pids) { std::unique_ptr reader(new quipper::PerfReader); @@ -556,15 +539,6 @@ ProfileVector RawPerfDataToProfileProto(const void* raw, int raw_size, return ProfileVector(); } - StringMap build_id_map_pb; - if (!build_id_map_pb.ParseFromArray(build_ids, build_ids_size)) { - std::cerr << "Unable to parse build ids." << std::endl; - abort(); - } - std::map build_id_map; - for (const auto& item : build_id_map_pb.key_value()) { - build_id_map[item.key()] = item.value(); - } reader->InjectBuildIDs(build_id_map); // Perf populates info about the kernel using multiple pathways, // which don't actually all match up how they name kernel data; in @@ -591,43 +565,4 @@ ProfileVector SerializedPerfDataProtoToProfileProto( return PerfDataProtoToProfileList(&perf_data, sample_labels, group_by_pids); } -// Returns a serialized ProfileList following the semantics of -// RawPerfDataToProfileProto -string RawPerfDataToSerializedProfileList(const void* raw, int raw_size, - const void* build_ids, - int build_ids_size, - uint32 sample_labels, - bool group_by_pids) { - const auto& profiles = RawPerfDataToProfileProto( - raw, raw_size, build_ids, build_ids_size, sample_labels, group_by_pids); - return SerializedProfileList(profiles); -} - -string RawPerfDataUniqueMappedFiles(const void* raw, int raw_size) { - std::unique_ptr reader(new quipper::PerfReader); - if (!reader->ReadFromPointer(reinterpret_cast(raw), raw_size)) { - LOG(ERROR) << "Could not read input perf.data"; - return ""; - } - std::vector filenames; - reader->GetFilenames(&filenames); - StringList list; - for (const auto& filename : filenames) { - list.add_item(filename); - } - string serialized; - if (!list.SerializeToString(&serialized)) { - std::cerr << "Failed to serialize StringList" << std::endl; - abort(); - } - return serialized; -} - -string SerializedPerfDataProtoToSerializedProfileList( - const string& perf_data_str, uint32 sample_labels) { - const auto& profiles = - SerializedPerfDataProtoToProfileProto(perf_data_str, sample_labels); - return SerializedProfileList(profiles); -} - } // namespace perftools diff --git a/perf_data_converter.h b/perf_data_converter.h index 01fe32ac..fd58d70c 100644 --- a/perf_data_converter.h +++ b/perf_data_converter.h @@ -81,8 +81,9 @@ const char ExecutionModeHypervisor[] = "Hypervisor"; // // Returns an empty vector if any error occurs. extern std::vector > -RawPerfDataToProfileProto(const void* raw, int raw_size, const void* build_ids, - int build_ids_size, uint32 sample_labels = kNoLabels, +RawPerfDataToProfileProto(const void* raw, int raw_size, + const std::map &build_id_map, + uint32 sample_labels = kNoLabels, bool group_by_pids = true); extern std::vector > @@ -94,16 +95,6 @@ SerializedPerfDataProtoToProfileProto(const string& serialized_perf_data, // raw perf.data. string RawPerfDataUniqueMappedFiles(const void* raw, int raw_size); -// Returns a serialized ProfileList following the semantics of -// RawPerfDataToProfileProto -string RawPerfDataToSerializedProfileList(const void* raw_perf_data, - int raw_size, const void* build_ids, - int build_ids_size, - uint32 sample_labels = kNoLabels, - bool group_by_pids = true); - -string SerializedPerfDataProtoToSerializedProfileList( - const string& perf_data_str, uint32 sample_labels = kNoLabels); } // namespace perftools #endif // PERFTOOLS_PERF_DATA_CONVERTER_H_ diff --git a/perf_data_converter_test.cc b/perf_data_converter_test.cc index ba1d4ac2..ffa62b22 100644 --- a/perf_data_converter_test.cc +++ b/perf_data_converter_test.cc @@ -217,9 +217,10 @@ TEST_F(PerfDataConverterTest, Converts) { GetContents(c.filename, &raw_perf_data); // Test RawPerfData input. + std::map build_ids; ProfileVector profiles = RawPerfDataToProfileProto( reinterpret_cast(raw_perf_data.c_str()), - raw_perf_data.size(), nullptr, 0, kNoLabels, false); + raw_perf_data.size(), build_ids, kNoLabels, false); // Does not group by PID, Vector should only contain one element EXPECT_EQ(profiles.size(), 1); auto counts = GetMapCounts(profiles); @@ -287,22 +288,14 @@ TEST_F(PerfDataConverterTest, Injects) { string raw_perf_data; GetContents(path, &raw_perf_data); const string want_buildid = "abcdabcd"; - perftools::StringMap string_map; - string_map.add_key_value(); - string_map.mutable_key_value(0)->set_key("[kernel.kallsyms]"); - string_map.mutable_key_value(0)->set_value(want_buildid); - string serialized_string_map; - if (!string_map.SerializeToString(&serialized_string_map)) { - std::cerr << "Failed to serizlied string_map to string." << std::endl; - abort(); - } + std::map build_ids; + build_ids["[kernel.kallsyms]"] = want_buildid; // Test RawPerfData input. ProfileVector profiles = RawPerfDataToProfileProto( reinterpret_cast(raw_perf_data.c_str()), - raw_perf_data.size(), - reinterpret_cast(serialized_string_map.c_str()), - serialized_string_map.size(), kNoLabels, false); + raw_perf_data.size(), build_ids, + kNoLabels, false); bool found = false; for (const auto& profile : profiles) { for (const auto& it : profile->mapping()) { diff --git a/perf_to_profile.cc b/perf_to_profile.cc index 87b146df..0822a7b4 100644 --- a/perf_to_profile.cc +++ b/perf_to_profile.cc @@ -55,8 +55,10 @@ int main(int argc, char **argv) { } const auto perf_data = ReadFileToString(argv[1]); const auto raw_perf_data = static_cast(perf_data.data()); + + std::map build_ids; const ProfileVector profiles = perftools::RawPerfDataToProfileProto( - raw_perf_data, perf_data.length(), nullptr, 0, perftools::kNoLabels, + raw_perf_data, perf_data.length(), build_ids, perftools::kNoLabels, false); // group_by_pid is false, all of the PID profiles should be merged into a // single one. diff --git a/profile_wrappers.proto b/profile_wrappers.proto deleted file mode 100644 index 6d1badd6..00000000 --- a/profile_wrappers.proto +++ /dev/null @@ -1,59 +0,0 @@ -// 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 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 Google Inc. 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. -// -//////////////////////////////////////////////////////////////////////////////// - - -// Glue protobufs to facilitate SWIG wrapping C++ converters. -// These protobufs are never persisted, so they can be modified -// without backward compatibility concerns. -syntax = "proto2"; - -package perftools; - -option java_package = "com.google.perftools"; - -import "profile.proto"; - -// NEXT_TAG = 2; -message ProfileList { - repeated profiles.Profile profile = 1; -} - -// NEXT_TAG = 3; -message KeyValue { - optional string key = 1; - optional string value = 2; -} - -// NEXT_TAG = 2 -message StringMap { - repeated KeyValue key_value = 1; -} - -// NEXT_TAG = 2 -message StringList { - repeated string item = 1; -}