Add end() method to bionic's ScopedTrace class
Bug: http://b/27195126 Test: make Change-Id: I8243629200606ca87b11cbd479ca093add42eb56
This commit is contained in:
parent
e0561cb0c9
commit
2a4a5e72f1
|
@ -48,10 +48,11 @@ static bool should_trace() {
|
||||||
// case an audit will be logged, and during boot before the property server has
|
// case an audit will be logged, and during boot before the property server has
|
||||||
// been started, in which case we store the global property_area serial to prevent
|
// been started, in which case we store the global property_area serial to prevent
|
||||||
// the costly find operation until we see a changed property_area.
|
// the costly find operation until we see a changed property_area.
|
||||||
if (!g_pinfo && g_property_area_serial != __system_property_area_serial()) {
|
if (g_pinfo == nullptr && g_property_area_serial != __system_property_area_serial()) {
|
||||||
g_property_area_serial = __system_property_area_serial();
|
g_property_area_serial = __system_property_area_serial();
|
||||||
g_pinfo = __system_property_find(SYSTRACE_PROPERTY_NAME);
|
g_pinfo = __system_property_find(SYSTRACE_PROPERTY_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_pinfo) {
|
if (g_pinfo) {
|
||||||
// Find out which tags have been enabled on the command line and set
|
// Find out which tags have been enabled on the command line and set
|
||||||
// the value of tags accordingly. If the value of the property changes,
|
// the value of tags accordingly. If the value of the property changes,
|
||||||
|
@ -61,10 +62,11 @@ static bool should_trace() {
|
||||||
// not to move.
|
// not to move.
|
||||||
uint32_t cur_serial = __system_property_serial(g_pinfo);
|
uint32_t cur_serial = __system_property_serial(g_pinfo);
|
||||||
if (cur_serial != g_property_serial) {
|
if (cur_serial != g_property_serial) {
|
||||||
g_property_serial = cur_serial;
|
__system_property_read_callback(g_pinfo,
|
||||||
char value[PROP_VALUE_MAX];
|
[] (void*, const char*, const char* value, uint32_t serial) {
|
||||||
__system_property_read(g_pinfo, 0, value);
|
g_property_serial = serial;
|
||||||
g_tags = strtoull(value, nullptr, 0);
|
g_tags = strtoull(value, nullptr, 0);
|
||||||
|
}, nullptr);
|
||||||
}
|
}
|
||||||
result = ((g_tags & ATRACE_TAG_BIONIC) != 0);
|
result = ((g_tags & ATRACE_TAG_BIONIC) != 0);
|
||||||
}
|
}
|
||||||
|
@ -81,7 +83,7 @@ static int get_trace_marker_fd() {
|
||||||
return g_trace_marker_fd;
|
return g_trace_marker_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedTrace::ScopedTrace(const char* message) {
|
void bionic_trace_begin(const char* message) {
|
||||||
if (!should_trace()) {
|
if (!should_trace()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -102,7 +104,7 @@ ScopedTrace::ScopedTrace(const char* message) {
|
||||||
TEMP_FAILURE_RETRY(write(trace_marker_fd, buf, len));
|
TEMP_FAILURE_RETRY(write(trace_marker_fd, buf, len));
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedTrace::~ScopedTrace() {
|
void bionic_trace_end() {
|
||||||
if (!should_trace()) {
|
if (!should_trace()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -114,3 +116,18 @@ ScopedTrace::~ScopedTrace() {
|
||||||
|
|
||||||
TEMP_FAILURE_RETRY(write(trace_marker_fd, "E", 1));
|
TEMP_FAILURE_RETRY(write(trace_marker_fd, "E", 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScopedTrace::ScopedTrace(const char* message) : called_end_(false) {
|
||||||
|
bionic_trace_begin(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedTrace::~ScopedTrace() {
|
||||||
|
End();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScopedTrace::End() {
|
||||||
|
if (!called_end_) {
|
||||||
|
bionic_trace_end();
|
||||||
|
called_end_ = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -28,8 +28,13 @@ class __LIBC_HIDDEN__ ScopedTrace {
|
||||||
explicit ScopedTrace(const char* message);
|
explicit ScopedTrace(const char* message);
|
||||||
~ScopedTrace();
|
~ScopedTrace();
|
||||||
|
|
||||||
|
void End();
|
||||||
private:
|
private:
|
||||||
|
bool called_end_;
|
||||||
DISALLOW_COPY_AND_ASSIGN(ScopedTrace);
|
DISALLOW_COPY_AND_ASSIGN(ScopedTrace);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void bionic_trace_begin(const char* message);
|
||||||
|
void bionic_trace_end();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue