diff options
author | Primiano Tucci <primiano@google.com> | 2021-10-19 19:54:49 +0100 |
---|---|---|
committer | Primiano Tucci <primiano@google.com> | 2021-10-19 19:54:49 +0100 |
commit | ec95742c8bbfd9d06af6610848875fc340f53d39 (patch) | |
tree | aa976097a85230fced246db1efed68c7e1b81091 | |
parent | 997ab09fc74e523dca4c1aac75e548307fec33ee (diff) | |
download | perfetto-ec95742c8bbfd9d06af6610848875fc340f53d39.tar.gz |
traced_probes: add crash keys to debug hang on ReadProcPidFile
Also switch some usages of sprintf to base::StackString<N>
Bug: 189749310
Change-Id: Iaceea6dc063f1257b286c9e244c51350bfe45041
-rw-r--r-- | include/perfetto/ext/base/crash_keys.h | 5 | ||||
-rw-r--r-- | src/traced/probes/ps/process_stats_data_source.cc | 21 |
2 files changed, 18 insertions, 8 deletions
diff --git a/include/perfetto/ext/base/crash_keys.h b/include/perfetto/ext/base/crash_keys.h index 921265fdd..1d550f6e6 100644 --- a/include/perfetto/ext/base/crash_keys.h +++ b/include/perfetto/ext/base/crash_keys.h @@ -99,7 +99,10 @@ class CrashKey { enum class Type : uint8_t { kUnset = 0, kInt, kStr }; - void Clear() { type_ = Type::kUnset; } + void Clear() { + int_value_ = 0; + type_ = Type::kUnset; + } void Set(int64_t value) { int_value_ = value; diff --git a/src/traced/probes/ps/process_stats_data_source.cc b/src/traced/probes/ps/process_stats_data_source.cc index 9dafa729f..4ac0a63d7 100644 --- a/src/traced/probes/ps/process_stats_data_source.cc +++ b/src/traced/probes/ps/process_stats_data_source.cc @@ -23,6 +23,7 @@ #include "perfetto/base/task_runner.h" #include "perfetto/base/time.h" +#include "perfetto/ext/base/crash_keys.h" #include "perfetto/ext/base/file_utils.h" #include "perfetto/ext/base/hash.h" #include "perfetto/ext/base/metatrace.h" @@ -54,6 +55,10 @@ namespace { // was provided in the config. The cache is trimmed if it exceeds this size. const size_t kThreadTimeInStateCacheSize = 10000; +// TODO(b/189749310): For debugging of b/189749310. Remove by Jan 2022. +base::CrashKey g_crash_key_proc_file("proc_file"); +base::CrashKey g_crash_key_proc_count("proc_count"); + int32_t ReadNextNumericDir(DIR* dirp) { while (struct dirent* dir_ent = readdir(dirp)) { if (dir_ent->d_type != DT_DIR) @@ -152,9 +157,8 @@ void ProcessStatsDataSource::WriteAllProcesses() { return; while (int32_t pid = ReadNextNumericDir(*proc_dir)) { WriteProcessOrThread(pid); - char task_path[255]; - sprintf(task_path, "/proc/%d/task", pid); - base::ScopedDir task_dir(opendir(task_path)); + base::StackString<128> task_path("/proc/%d/task", pid); + base::ScopedDir task_dir(opendir(task_path.c_str())); if (!task_dir) continue; @@ -279,17 +283,19 @@ base::ScopedDir ProcessStatsDataSource::OpenProcDir() { std::string ProcessStatsDataSource::ReadProcPidFile(int32_t pid, const std::string& file) { + base::StackString<128> path("/proc/%" PRId32 "/%s", pid, file.c_str()); + auto scoped_key = g_crash_key_proc_file.SetScoped(path.string_view()); + g_crash_key_proc_count.Set(g_crash_key_proc_count.int_value() + 1); std::string contents; contents.reserve(4096); - if (!base::ReadFile("/proc/" + std::to_string(pid) + "/" + file, &contents)) + if (!base::ReadFile(path.c_str(), &contents)) return ""; return contents; } base::ScopedDir ProcessStatsDataSource::OpenProcTaskDir(int32_t pid) { - char task_path[255]; - sprintf(task_path, "/proc/%d/task", pid); - return base::ScopedDir(opendir(task_path)); + base::StackString<128> task_path("/proc/%d/task", pid); + return base::ScopedDir(opendir(task_path.c_str())); } std::string ProcessStatsDataSource::ReadProcStatusEntry(const std::string& buf, @@ -367,6 +373,7 @@ void ProcessStatsDataSource::Tick( base::WeakPtr<ProcessStatsDataSource> weak_this) { if (!weak_this) return; + g_crash_key_proc_count.Clear(); ProcessStatsDataSource& thiz = *weak_this; uint32_t period_ms = thiz.poll_period_ms_; uint32_t delay_ms = |