staticvoid trace_begin_internal(constchar* message) { int trace_marker_fd = get_trace_marker_fd(); if (trace_marker_fd == -1) { return;
}
// If bionic tracing has been enabled, then write the message to the // kernel trace_marker. int length = strlen(message); char buf[length + WRITE_OFFSET];
size_t len = async_safe_format_buffer(buf, length + WRITE_OFFSET, "B|%d|%s", getpid(), message);
// Tracing may stop just after checking property and before writing the message. // So the write is acceptable to fail. See b/20666100.
TEMP_FAILURE_RETRY(write(trace_marker_fd, buf, len));
}
void bionic_trace_begin(constchar* message) { // Some functions called by trace_begin_internal() can call // bionic_trace_begin(). Prevent infinite recursion and non-recursive mutex // deadlock by using a flag in the thread local storage.
bionic_tls& tls = __get_bionic_tls(); if (!tls.bionic_systrace_enabled || !should_trace()) return;
tls.bionic_systrace_enabled = false;
trace_begin_internal(message);
tls.bionic_systrace_enabled = true;
}
staticvoid trace_end_internal() { int trace_marker_fd = get_trace_marker_fd(); if (trace_marker_fd == -1) { return;
}
// This code is intentionally "sub-optimal"; do not optimize this by inlining // the E| string into the write. // // This is because if the const char* string passed to write(trace_marker) is not // in resident memory (e.g. the page of the .rodata section that contains it has // been paged out, or the anonymous page that contained a heap-based string is // swapped in zram), the ftrace code will NOT page it in and instead report // <faulted>. // // We "fix" this by putting the string on the stack, which is more unlikely // to be paged out and pass the pointer to that instead. // // See b/197620214 for more context on this. volatilechar buf[2]{'E', '|'};
TEMP_FAILURE_RETRY(write(trace_marker_fd, const_cast<constchar*>(buf), 2));
}
void bionic_trace_end() { // Some functions called by trace_end_internal() can call // bionic_trace_begin(). Prevent infinite recursion and non-recursive mutex // deadlock by using a flag in the thread local storage.
bionic_tls& tls = __get_bionic_tls(); if (!tls.bionic_systrace_enabled || !should_trace()) return;
tls.bionic_systrace_enabled = false;
trace_end_internal();
tls.bionic_systrace_enabled = true;
}
ScopedTrace::ScopedTrace(constchar* message) : called_end_(false) { // Do not call should_trace if tracing is disabled, the call can crash if // done during initialization.
bionic_tls& tls = __get_bionic_tls();
should_trace_ = tls.bionic_systrace_enabled && should_trace(); if (!should_trace_) return;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.