Cleanup TraceMe idioms
PiperOrigin-RevId: 325260871 Change-Id: Ifa970a3529c1c53a5b25899a61c8de940963d423
This commit is contained in:
parent
eaebc51dd6
commit
916e5e54be
tensorflow
@ -38,12 +38,12 @@ class AnnotatedTraceMe {
|
||||
bool annotation_enabled = ScopedAnnotation::IsEnabled();
|
||||
bool traceme_enabled = TraceMe::Active(level);
|
||||
if (TF_PREDICT_FALSE(annotation_enabled || traceme_enabled)) {
|
||||
string label = name_generator();
|
||||
string name = name_generator();
|
||||
if (annotation_enabled) {
|
||||
scoped_annotation_.emplace(absl::string_view(label));
|
||||
scoped_annotation_.emplace(absl::string_view(name));
|
||||
}
|
||||
if (TF_PREDICT_TRUE(traceme_enabled)) {
|
||||
trace_me_.emplace(std::move(label), level);
|
||||
trace_me_.emplace([name = std::move(name)] { return name; }, level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,8 +120,11 @@ void PythonHooks::ProfileFast(PyFrameObject* frame, int what, PyObject* arg) {
|
||||
function = py::reinterpret_borrow<py::str>(f_code->co_name);
|
||||
}
|
||||
|
||||
tracemes_[thread_id].push_back(absl::make_unique<TraceMe>(absl::StrCat(
|
||||
"$", io::Basename(filename), ":", line_no, " ", function)));
|
||||
tracemes_[thread_id].push_back(
|
||||
absl::make_unique<TraceMe>([&filename, line_no, &function] {
|
||||
return absl::StrCat("$", io::Basename(filename), ":", line_no, " ",
|
||||
function);
|
||||
}));
|
||||
} else if (what == PyTrace_C_CALL && PyCFunction_Check(arg)) {
|
||||
// Python stack does not have a filename/line_no for native calls.
|
||||
auto* func = reinterpret_cast<PyCFunctionObject*>(arg);
|
||||
@ -139,9 +142,10 @@ void PythonHooks::ProfileFast(PyFrameObject* frame, int what, PyObject* arg) {
|
||||
filename = "<unknown>";
|
||||
}
|
||||
|
||||
string function(func->m_ml->ml_name);
|
||||
tracemes_[thread_id].push_back(absl::make_unique<TraceMe>(
|
||||
absl::StrCat(filename, " ", func->m_ml->ml_name)));
|
||||
tracemes_[thread_id].push_back(
|
||||
absl::make_unique<TraceMe>([&filename, func] {
|
||||
return absl::StrCat(filename, " ", func->m_ml->ml_name);
|
||||
}));
|
||||
} else if (what == PyTrace_RETURN || what == PyTrace_C_RETURN ||
|
||||
what == PyTrace_EXCEPTION || what == PyTrace_C_EXCEPTION) {
|
||||
auto& thread_tracemes = tracemes_[thread_id];
|
||||
|
Loading…
Reference in New Issue
Block a user