aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxliuprof <xliuprof@google.com>2023-09-11 15:06:10 -0700
committerSvilen Kanev <svilen.kanev@gmail.com>2023-10-12 10:08:16 -0700
commitfbdee59f37b1199fd3acb3f9dccf82987f47f76f (patch)
tree2027bf5cf01e11e2446dbd9195f4ad9856b9f6a8
parent380f048e0e51e5b1cc22b9e3962a3430fe397e81 (diff)
downloadperf_data_converter-fbdee59f37b1199fd3acb3f9dccf82987f47f76f.tar.gz
Add the support of snoop label obtained from data source.
PiperOrigin-RevId: 564512939
-rw-r--r--src/perf_data_converter.cc37
-rw-r--r--src/perf_data_converter.h1
-rw-r--r--src/perf_data_converter_test.cc30
-rw-r--r--src/testdata/perf-datasrc.textproto12
4 files changed, 68 insertions, 12 deletions
diff --git a/src/perf_data_converter.cc b/src/perf_data_converter.cc
index b4a9631..70703df 100644
--- a/src/perf_data_converter.cc
+++ b/src/perf_data_converter.cc
@@ -8,6 +8,7 @@
#include "src/perf_data_converter.h"
#include <algorithm>
+#include <cstdint>
#include <deque>
#include <map>
#include <sstream>
@@ -112,6 +113,7 @@ struct SampleKey {
uint32_t cpu = 0;
uint64_t weight = 0;
uint64_t data_src = 0;
+ uint64_t snoop_status = 0;
LocationIdVector stack;
};
@@ -124,7 +126,7 @@ struct SampleKeyEqualityTester {
(a.code_page_size == b.code_page_size) &&
(a.data_page_size == b.data_page_size) && (a.cpu == b.cpu) &&
(a.weight == b.weight) && (a.data_src == b.data_src) &&
- (a.stack == b.stack));
+ (a.snoop_status == b.snoop_status) && (a.stack == b.stack));
}
};
@@ -144,6 +146,7 @@ struct SampleKeyHasher {
hash ^= std::hash<uint32_t>()(k.cpu);
hash ^= std::hash<uint64_t>()(k.weight);
hash ^= std::hash<uint64_t>()(k.data_src);
+ hash ^= std::hash<uint64_t>()(k.snoop_status);
for (const auto& id : k.stack) {
hash ^= std::hash<uint64_t>()(id);
}
@@ -396,7 +399,8 @@ SampleKey PerfDataConverter::MakeSampleKey(
sample_key.weight = sample.sample.weight();
}
}
- // If sample has a data_src, we decode it to find the data source.
+ // If sample has a data_src, we decode it to find the data source and snoop
+ // status.
if (IncludeDataSrcLabels() && sample.sample.has_data_src()) {
quipper::perf_mem_data_src ds;
std::string cache_lvl;
@@ -426,6 +430,20 @@ SampleKey PerfDataConverter::MakeSampleKey(
cache_lvl = "Unknown Level";
sample_key.data_src = UTF8StringId(cache_lvl, builder);
}
+ // Obtain the snoop status
+ std::string snoop_status;
+ if (ds.mem_snoop & quipper::PERF_MEM_SNOOP_NONE) {
+ snoop_status = "None";
+ } else if (ds.mem_snoop & quipper::PERF_MEM_SNOOP_HIT) {
+ snoop_status = "Hit";
+ } else if (ds.mem_snoop & quipper::PERF_MEM_SNOOP_MISS) {
+ snoop_status = "Miss";
+ } else if (ds.mem_snoop & quipper::PERF_MEM_SNOOP_HITM) {
+ snoop_status = "HitM";
+ } else {
+ snoop_status = "Unknown Status";
+ }
+ sample_key.snoop_status = UTF8StringId(snoop_status, builder);
}
return sample_key;
}
@@ -632,10 +650,17 @@ void PerfDataConverter::AddOrUpdateSample(
label->set_num(sample_key.weight);
label->set_num_unit(builder->StringId("cycles"));
}
- if (IncludeDataSrcLabels() && sample_key.data_src != 0) {
- auto* label = sample->add_label();
- label->set_key(builder->StringId(DataSrcLabelKey));
- label->set_str(sample_key.data_src);
+ if (IncludeDataSrcLabels()) {
+ if (sample_key.data_src != 0) {
+ auto* label = sample->add_label();
+ label->set_key(builder->StringId(DataSrcLabelKey));
+ label->set_str(sample_key.data_src);
+ }
+ if (sample_key.snoop_status != 0) {
+ auto* label = sample->add_label();
+ label->set_key(builder->StringId(SnoopStatusLabelKey));
+ label->set_str(sample_key.snoop_status);
+ }
}
// Two values per collected event: the first is sample counts, the second is
// event counts (unsampled weight for each sample).
diff --git a/src/perf_data_converter.h b/src/perf_data_converter.h
index c9beb38..b295ace 100644
--- a/src/perf_data_converter.h
+++ b/src/perf_data_converter.h
@@ -82,6 +82,7 @@ const char DataPageSizeLabelKey[] = "data_page_size";
const char CpuLabelKey[] = "cpu";
const char CacheLatencyLabelKey[] = "cache_latency";
const char DataSrcLabelKey[] = "data_src";
+const char SnoopStatusLabelKey[] = "snoop_status";
// Execution mode label values.
const char ExecutionModeHostKernel[] = "Host Kernel";
diff --git a/src/perf_data_converter_test.cc b/src/perf_data_converter_test.cc
index 1d2e79c..de1940b 100644
--- a/src/perf_data_converter_test.cc
+++ b/src/perf_data_converter_test.cc
@@ -1025,6 +1025,36 @@ TEST_F(PerfDataConverterTest, ConvertsDataSrc) {
EXPECT_THAT(counts_by_datasrc, UnorderedPointwise(Eq(), expected_counts));
}
+TEST_F(PerfDataConverterTest, ConvertsSnoop) {
+ const std::string ascii_pb(
+ GetContents(GetResource("perf-datasrc.textproto")));
+ ASSERT_FALSE(ascii_pb.empty());
+ PerfDataProto perf_data_proto;
+ ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(ascii_pb, &perf_data_proto));
+
+ const ProcessProfiles pps =
+ PerfDataProtoToProfiles(&perf_data_proto, kDataSrcLabel);
+ ASSERT_EQ(pps.size(), 1);
+
+ std::unordered_map<std::string, uint64_t> counts_by_snoop;
+ const auto& p = pps[0]->data;
+ for (const auto& sample : p.sample()) {
+ std::string snoop_status;
+ for (const auto& label : sample.label()) {
+ if (p.string_table(label.key()) == SnoopStatusLabelKey) {
+ snoop_status = p.string_table(label.str());
+ counts_by_snoop[snoop_status]++;
+ }
+ }
+ }
+ const std::unordered_map<std::string, uint64_t> expected_counts{
+ {"Hit", 1},
+ {"Miss", 1},
+ {"HitM", 1},
+ };
+ EXPECT_THAT(counts_by_snoop, UnorderedPointwise(Eq(), expected_counts));
+}
+
TEST_F(PerfDataConverterTest, HandlesAlternateKernelNames) {
std::string ascii_pb =
GetContents(GetResource("perf-kernel-mapping-by-name.textproto"));
diff --git a/src/testdata/perf-datasrc.textproto b/src/testdata/perf-datasrc.textproto
index b674dcb..085c027 100644
--- a/src/testdata/perf-datasrc.textproto
+++ b/src/testdata/perf-datasrc.textproto
@@ -60,8 +60,8 @@ events {
period: 3170393
cpu: 0
weight: 352
- # Set hit level bit and L1 bit
- data_src: 320
+ # Set hit level bit and L1 bit and Snoop_hit bit
+ data_src: 2097472
}
}
events {
@@ -78,8 +78,8 @@ events {
period: 3170393
cpu: 0
weight: 146
- # Set hit level bit and L2 bit
- data_src: 1088
+ # Set hit level bit and L2 bit and Snoop_miss bit
+ data_src: 4195392
}
}
events {
@@ -96,8 +96,8 @@ events {
period: 3170393
cpu: 0
weight: 352
- # Set hit level bit and L3 bit
- data_src: 2112
+ # Set hit level bit and L3 bit and Snoop_HitM bit
+ data_src: 8390720
}
}
timestamp_sec: 0