From 1a5f8eb7edb7aaf16debf13947b22027870b2b7b Mon Sep 17 00:00:00 2001 From: Pete Stevenson Date: Tue, 15 Feb 2022 17:49:59 -0800 Subject: [PATCH] PerfProfiler: on exit, or target proc. termination, remove all symbolization artifacts create inside the target container. Summary: TSIA Test Plan: Tested on local dev. cluster. Reviewers: #stirling, oazizi Reviewed By: #stirling, oazizi JIRA Issues: PP-2982, PP-3252 Signed-off-by: Pete Stevenson Differential Revision: https://phab.corp.pixielabs.ai/D10788 GitOrigin-RevId: b3ff7389cb5d0b869c58390514ad061843ee3fb4 --- .../perf_profiler/symbolizers/java_symbolizer.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/stirling/source_connectors/perf_profiler/symbolizers/java_symbolizer.cc b/src/stirling/source_connectors/perf_profiler/symbolizers/java_symbolizer.cc index f469204e824..45de7a546ad 100644 --- a/src/stirling/source_connectors/perf_profiler/symbolizers/java_symbolizer.cc +++ b/src/stirling/source_connectors/perf_profiler/symbolizers/java_symbolizer.cc @@ -132,7 +132,21 @@ JavaSymbolizationContext::JavaSymbolizationContext(const struct upid_t& target_u host_artifacts_path_resolved_ = true; } -JavaSymbolizationContext::~JavaSymbolizationContext() { symbol_file_->close(); } +JavaSymbolizationContext::~JavaSymbolizationContext() { + symbol_file_->close(); + + if (host_artifacts_path_resolved_) { + // Remove the host artifacts path entirely; this cleans up all the files (and the subdir) we + // created inside of the target container mount namespace. + const auto& sysconfig = system::Config::GetInstance(); + const std::filesystem::path host_artifacts_path = sysconfig.ToHostPath(host_artifacts_path_); + const Status remove_status = fs::RemoveAll(host_artifacts_path); + if (!remove_status.ok()) { + char const* const fmt = "Could not remove host artifacts path: $0, $1."; + LOG(WARNING) << absl::Substitute(fmt, host_artifacts_path_.string(), remove_status.msg()); + } + } +} std::string_view JavaSymbolizationContext::Symbolize(const uintptr_t addr) { if (requires_refresh_) {