aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlankhaar <vlankhaar@users.noreply.github.com>2017-10-31 16:43:19 -0700
committerAlexey Alexandrov <aalexand@users.noreply.github.com>2017-10-31 16:43:19 -0700
commit733f709feefe4c3b1dc76943e4f02ee90068c86b (patch)
treec4876ff1d1228f6c9e925a125ebde68fca225c6a
parent8b0ce896364d24a920cb329f2a00dfeb9b2c2ed8 (diff)
downloadperf_data_converter-733f709feefe4c3b1dc76943e4f02ee90068c86b.tar.gz
Copybara staging (#33)
* Add dependency on googlemock to enable EXPECT_THAT(<container>, Contains(...)); This should allow simplified tests that are more readable and easier to add. (also clean up an attempt to LOG() a streamstream that failed to compile.) PiperOrigin-RevId: 174061634 * Store perf-version in profile.proto comment. PiperOrigin-RevId: 174094448
-rw-r--r--Makefile6
-rw-r--r--compat/test_compat.h1
-rw-r--r--perf_data_converter.cc17
-rw-r--r--perf_data_converter_test.cc34
4 files changed, 49 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index 794fa7d..f798dea 100644
--- a/Makefile
+++ b/Makefile
@@ -116,11 +116,11 @@ third_party/protobuf/src/.libs/libprotobuf.a: third_party/protobuf/configure
ifeq ($(wildcard third_party/googletest/googletest/include/gtest/gtest.h),)
# Use local gtest includes, already on the system path
GTEST_INCLUDES =
-GTEST_LIBS = -lgtest
+GTEST_LIBS = -lgtest -lgmock
else
# Pick up gtest includes from submodule.
-GTEST_INCLUDES = -Ithird_party/googletest/googletest/include
-GTEST_LIBS = -Ithird_party/googletest/googletest third_party/googletest/googletest/src/gtest-all.cc
+GTEST_INCLUDES = -Ithird_party/googletest/googlemock/include -Ithird_party/googletest/googletest/include
+GTEST_LIBS = -Ithird_party/googletest/googlemock third_party/googletest/googlemock/src/gmock-all.cc -Ithird_party/googletest/googletest third_party/googletest/googletest/src/gtest-all.cc
endif
ifneq ($(MAKECMDGOALS),clean)
diff --git a/compat/test_compat.h b/compat/test_compat.h
index b3fcec0..9a35f21 100644
--- a/compat/test_compat.h
+++ b/compat/test_compat.h
@@ -29,5 +29,6 @@
#define PERFTOOLS_COMPAT_TEST_COMPAT_H_
#include <gtest/gtest.h>
+#include <gmock/gmock.h>
#endif // PERFTOOLS_COMPAT_TEST_COMPAT_H_
diff --git a/perf_data_converter.cc b/perf_data_converter.cc
index 70b74c1..d74a46e 100644
--- a/perf_data_converter.cc
+++ b/perf_data_converter.cc
@@ -207,9 +207,9 @@ class PerfDataConverter : public PerfDataHandler {
ProcessProfiles Profiles();
// Callbacks for PerfDataHandler
- virtual void Sample(const PerfDataHandler::SampleContext& sample);
- virtual void Comm(const CommContext& comm);
- virtual void MMap(const MMapContext& mmap);
+ void Sample(const PerfDataHandler::SampleContext& sample) override;
+ void Comm(const CommContext& comm) override;
+ void MMap(const MMapContext& mmap) override;
private:
// Adds a new sample updating the event counters if such sample is not present
@@ -354,6 +354,17 @@ ProfileBuilder* PerfDataConverter::GetOrCreateBuilder(
} else {
AddOrGetMapping(sample.sample.pid(), sample.main_mapping, builder);
}
+ if (perf_data_.string_metadata().has_perf_version()) {
+ string perf_version =
+ "perf-version:" + perf_data_.string_metadata().perf_version().value();
+ profile->add_comment(UTF8StringId(perf_version, builder));
+ }
+ if (perf_data_.string_metadata().has_perf_command_line_whole()) {
+ string perf_command =
+ "perf-command:" +
+ perf_data_.string_metadata().perf_command_line_whole().value();
+ profile->add_comment(UTF8StringId(perf_command, builder));
+ }
} else {
Profile* profile = per_pid.builder->mutable_profile();
if ((options_ & kGroupByPids) && sample.main_mapping != nullptr &&
diff --git a/perf_data_converter_test.cc b/perf_data_converter_test.cc
index 8e1de2e..85db524 100644
--- a/perf_data_converter_test.cc
+++ b/perf_data_converter_test.cc
@@ -31,6 +31,7 @@ using perftools::ProcessProfiles;
using perftools::profiles::Location;
using perftools::profiles::Mapping;
using quipper::PerfDataProto;
+using testing::Contains;
namespace {
@@ -104,6 +105,16 @@ std::unordered_set<string> AllBuildIDs(const ProcessProfiles& pps) {
}
return ret;
}
+
+std::unordered_set<string> AllComments(const ProcessProfiles& pps) {
+ std::unordered_set<string> ret;
+ for (const auto& pp : pps) {
+ for (const auto& it : pp->data.comment()) {
+ ret.insert(pp->data.string_table(it));
+ }
+ }
+ return ret;
+}
} // namespace
namespace perftools {
@@ -192,8 +203,7 @@ TEST_F(PerfDataConverterTest, Converts) {
cases.emplace_back(TestCase{stack_profile, 1138, 1210, 2247});
for (const auto& c : cases) {
- std::stringstream casename;
- casename << "case " << Basename(c.filename);
+ string casename = "case " + Basename(c.filename);
string raw_perf_data;
GetContents(c.filename, &raw_perf_data);
@@ -277,7 +287,7 @@ TEST_F(PerfDataConverterTest, Injects) {
reinterpret_cast<const void*>(raw_perf_data.c_str()),
raw_perf_data.size(), build_ids);
std::unordered_set<string> all_build_ids = AllBuildIDs(pps);
- EXPECT_TRUE(all_build_ids.find(want_build_id) != all_build_ids.end());
+ EXPECT_THAT(all_build_ids, Contains(want_build_id));
}
TEST_F(PerfDataConverterTest, HandlesKernelMmapOverlappingUserCode) {
@@ -304,6 +314,24 @@ TEST_F(PerfDataConverterTest, HandlesKernelMmapOverlappingUserCode) {
EXPECT_EQ(kernel_mapping_id, profile.location(2).mapping_id());
}
+TEST_F(PerfDataConverterTest, PerfInfoSavedInComment) {
+ string path = GetResource(
+ "testdata"
+ "/single-event-single-process.perf.data");
+ string raw_perf_data;
+ GetContents(path, &raw_perf_data);
+ const string want_version = "perf-version:3.16.7-ckt20";
+ const string want_command = "perf-command:/usr/bin/perf_3.16 record ./a.out";
+
+ // Test RawPerfData input.
+ const ProcessProfiles pps = RawPerfDataToProfiles(
+ reinterpret_cast<const void*>(raw_perf_data.c_str()),
+ raw_perf_data.size(), {});
+ std::unordered_set<string> comments = AllComments(pps);
+ EXPECT_THAT(comments, Contains(want_version));
+ EXPECT_THAT(comments, Contains(want_command));
+}
+
} // namespace perftools
int main(int argc, char** argv) {