forked from OSchip/llvm-project
Add auto source map deduce count statistics
This patch adds auto source map deduce count as a target level statistics. This will help telemetry to track how many debug sessions benefit from this feature. Differential Revision: https://reviews.llvm.org/D134483
This commit is contained in:
parent
bd81524e7f
commit
c5073ed5f9
|
@ -37,7 +37,9 @@ public:
|
|||
|
||||
void Append(const PathMappingList &rhs, bool notify);
|
||||
|
||||
void AppendUnique(llvm::StringRef path, llvm::StringRef replacement,
|
||||
/// Append <path, replacement> pair without duplication.
|
||||
/// \return whether appending suceeds without duplication or not.
|
||||
bool AppendUnique(llvm::StringRef path, llvm::StringRef replacement,
|
||||
bool notify);
|
||||
|
||||
void Clear(bool notify);
|
||||
|
|
|
@ -133,6 +133,7 @@ public:
|
|||
void SetLaunchOrAttachTime();
|
||||
void SetFirstPrivateStopTime();
|
||||
void SetFirstPublicStopTime();
|
||||
void IncreaseSourceMapDeduceCount();
|
||||
|
||||
StatsDuration &GetCreateTime() { return m_create_time; }
|
||||
StatsSuccessFail &GetExpressionStats() { return m_expr_eval; }
|
||||
|
@ -146,6 +147,7 @@ protected:
|
|||
StatsSuccessFail m_expr_eval{"expressionEvaluation"};
|
||||
StatsSuccessFail m_frame_var{"frameVariable"};
|
||||
std::vector<intptr_t> m_module_identifiers;
|
||||
uint32_t m_source_map_deduce_count = 0;
|
||||
void CollectStats(Target &target);
|
||||
};
|
||||
|
||||
|
|
|
@ -261,8 +261,10 @@ void BreakpointResolverFileLine::DeduceSourceMapping(
|
|||
if (!new_mapping_from.empty() && !new_mapping_to.empty()) {
|
||||
LLDB_LOG(log, "generating auto source map from {0} to {1}",
|
||||
new_mapping_from, new_mapping_to);
|
||||
target.GetSourcePathMap().AppendUnique(new_mapping_from, new_mapping_to,
|
||||
/*notify*/ true);
|
||||
if (target.GetSourcePathMap().AppendUnique(new_mapping_from,
|
||||
new_mapping_to,
|
||||
/*notify*/ true))
|
||||
target.GetStatistics().IncreaseSourceMapDeduceCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,16 +76,17 @@ void PathMappingList::Append(const PathMappingList &rhs, bool notify) {
|
|||
}
|
||||
}
|
||||
|
||||
void PathMappingList::AppendUnique(llvm::StringRef path,
|
||||
bool PathMappingList::AppendUnique(llvm::StringRef path,
|
||||
llvm::StringRef replacement, bool notify) {
|
||||
auto normalized_path = NormalizePath(path);
|
||||
auto normalized_replacement = NormalizePath(replacement);
|
||||
for (const auto &pair : m_pairs) {
|
||||
if (pair.first.GetStringRef().equals(normalized_path) &&
|
||||
pair.second.GetStringRef().equals(normalized_replacement))
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
Append(path, replacement, notify);
|
||||
return true;
|
||||
}
|
||||
|
||||
void PathMappingList::Insert(llvm::StringRef path, llvm::StringRef replacement,
|
||||
|
|
|
@ -136,6 +136,7 @@ json::Value TargetStats::ToJSON(Target &target) {
|
|||
target_metrics_json.try_emplace("breakpoints", std::move(breakpoints_array));
|
||||
target_metrics_json.try_emplace("totalBreakpointResolveTime",
|
||||
totalBreakpointResolveTime);
|
||||
target_metrics_json.try_emplace("sourceMapDeduceCount", m_source_map_deduce_count);
|
||||
|
||||
return target_metrics_json;
|
||||
}
|
||||
|
@ -161,6 +162,10 @@ void TargetStats::SetFirstPublicStopTime() {
|
|||
m_first_public_stop_time = StatsClock::now();
|
||||
}
|
||||
|
||||
void TargetStats::IncreaseSourceMapDeduceCount() {
|
||||
++m_source_map_deduce_count;
|
||||
}
|
||||
|
||||
bool DebuggerStats::g_collecting_stats = false;
|
||||
|
||||
llvm::json::Value DebuggerStats::ReportStatistics(Debugger &debugger,
|
||||
|
|
|
@ -445,6 +445,18 @@ class BreakpointCommandTestCase(TestBase):
|
|||
self.assertEquals(entry[1], replacement,
|
||||
"source map entry 'replacement' does not match")
|
||||
|
||||
def verify_source_map_deduce_statistics(self, target, expected_count):
|
||||
stream = lldb.SBStream()
|
||||
res = target.GetStatistics().GetAsJSON(stream)
|
||||
self.assertTrue(res.Success())
|
||||
debug_stats = json.loads(stream.GetData())
|
||||
self.assertEqual('targets' in debug_stats, True,
|
||||
'Make sure the "targets" key in in target.GetStatistics()')
|
||||
target_stats = debug_stats['targets'][0]
|
||||
self.assertNotEqual(target_stats, None)
|
||||
self.assertEqual(target_stats['sourceMapDeduceCount'], expected_count)
|
||||
|
||||
|
||||
@skipIf(oslist=["windows"])
|
||||
@no_debug_info_test
|
||||
def test_breakpoints_auto_source_map_relative(self):
|
||||
|
@ -471,6 +483,7 @@ class BreakpointCommandTestCase(TestBase):
|
|||
|
||||
source_map_json = self.get_source_map_json()
|
||||
self.assertEquals(len(source_map_json), 0, "source map should be empty initially")
|
||||
self.verify_source_map_deduce_statistics(target, 0)
|
||||
|
||||
# Verify auto deduced source map when file path in debug info
|
||||
# is a suffix of request breakpoint file path
|
||||
|
@ -483,6 +496,7 @@ class BreakpointCommandTestCase(TestBase):
|
|||
source_map_json = self.get_source_map_json()
|
||||
self.assertEquals(len(source_map_json), 1, "source map should not be empty")
|
||||
self.verify_source_map_entry_pair(source_map_json[0], ".", "/x/y")
|
||||
self.verify_source_map_deduce_statistics(target, 1)
|
||||
|
||||
# Reset source map.
|
||||
self.runCmd("settings clear target.source-map")
|
||||
|
|
Loading…
Reference in New Issue