aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2021-10-20 10:35:40 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-10-20 10:35:40 +0000
commit325af8a206785c6a168303dff66c367a8e7f0b4f (patch)
treec150701efaddcd66b1821740db7e8d9b17afdcfd
parent5f0b3b9c3082422bc98513edbfddd802c5ff0926 (diff)
parentec95742c8bbfd9d06af6610848875fc340f53d39 (diff)
downloadperfetto-325af8a206785c6a168303dff66c367a8e7f0b4f.tar.gz
Merge "traced_probes: add crash keys to debug hang on ReadProcPidFile"
-rw-r--r--include/perfetto/ext/base/crash_keys.h5
-rw-r--r--src/traced/probes/ps/process_stats_data_source.cc21
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 =