summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Mythri Alle <mythria@google.com> 2025-02-25 13:52:16 +0000
committer Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2025-02-26 04:44:39 -0800
commit710c7ae5369908cc40ecffb2e04eeba03cc3926a (patch)
tree12d17c9b04fda1921d74f5dff3e04c4674fcab30
parentc9fd9b7cd6d2eba801e4fdf72a4122b7e731458f (diff)
A few fixes when dumping long running traces
This CL has a few fixes: 1. When recording on stack methods at the start of the trace, the current buffer index wasn't set correctly. It was set to the buffer size which basically means there are no entries. Fixed by setting it to the correct index. 2. We have some placeholder entries which should be ignored when dumping the trace. 3. We should encode the eventy type as a first value. Based on the event type we read the next value only for method entry events. 4. Encode the number of bytes written for each block of events, so it is easy when parsing. 5. Don't remove the event type when recording the timestamp_and_action. We need to clear the lsb to get the timestamp but when writing the entry we encode both timestamp and the event type as a single value. Bug: 352518093 Test: Manual testing Change-Id: Ibe72ad82daa37eb2f4760decbb207663836796c7
-rw-r--r--runtime/trace_profile.cc23
1 files changed, 15 insertions, 8 deletions
diff --git a/runtime/trace_profile.cc b/runtime/trace_profile.cc
index 58927d8948..26f80ad60d 100644
--- a/runtime/trace_profile.cc
+++ b/runtime/trace_profile.cc
@@ -58,7 +58,7 @@ static constexpr size_t kProfileMagicValue = 0x4C4F4D54;
// TODO(mythria): 10 is a randomly chosen value. Tune it if required.
static constexpr size_t kBufSizeForEncodedData = kMinBufSizeForEncodedData * 10;
-static constexpr size_t kAlwaysOnTraceHeaderSize = 8;
+static constexpr size_t kAlwaysOnTraceHeaderSize = 12;
bool TraceProfiler::profile_in_progress_ = false;
@@ -198,7 +198,7 @@ void RecordMethodsOnThreadStack(Thread* thread, uintptr_t* method_trace_buffer)
// Record a placeholder method exit event into the buffer so we record method exits for the
// methods that are currently on stack.
method_trace_buffer[index] = 0x1;
- thread->SetMethodTraceBufferCurrentEntry(index);
+ thread->SetMethodTraceBuffer(method_trace_buffer, index);
}
// Records the thread and method info.
@@ -236,7 +236,6 @@ static class LongRunningMethodsTraceStartCheckpoint final : public Closure {
// Record methods that are currently on stack.
RecordMethodsOnThreadStack(thread, buffer);
thread->UpdateTlsLowOverheadTraceEntrypoints(LowOverheadTraceType::kLongRunningMethods);
- thread->SetMethodTraceBuffer(buffer, kAlwaysOnTraceBufSize);
}
} long_running_methods_checkpoint_;
@@ -509,12 +508,17 @@ size_t TraceProfiler::DumpLongRunningMethodBuffer(uint32_t thread_id,
size_t end_index = end_trace_entries - method_trace_entries;
for (size_t i = kAlwaysOnTraceBufSize - 1; i >= end_index;) {
uintptr_t event = method_trace_entries[i--];
+ if (event == 0x1) {
+ // This is a placeholder event. Ignore this event.
+ continue;
+ }
+
bool is_method_exit = event & 0x1;
uint64_t timestamp_action_encoding;
uintptr_t method_ptr;
if (is_method_exit) {
// Method exit. We only have timestamp here.
- timestamp_action_encoding = event & ~1;
+ timestamp_action_encoding = event;
} else {
// method entry
method_ptr = event;
@@ -522,26 +526,29 @@ size_t TraceProfiler::DumpLongRunningMethodBuffer(uint32_t thread_id,
}
int64_t timestamp_action_diff = timestamp_action_encoding - prev_timestamp_action_encoding;
- int64_t method_diff;
+ curr_buffer_ptr = EncodeSignedLeb128(curr_buffer_ptr, timestamp_action_diff);
+ prev_timestamp_action_encoding = timestamp_action_encoding;
+
if (!is_method_exit) {
- method_diff = method_ptr - prev_method_ptr;
+ int64_t method_diff = method_ptr - prev_method_ptr;
ArtMethod* method = reinterpret_cast<ArtMethod*>(method_ptr);
methods.insert(method);
prev_method_ptr = method_ptr;
curr_buffer_ptr = EncodeSignedLeb128(curr_buffer_ptr, method_diff);
}
- curr_buffer_ptr = EncodeSignedLeb128(curr_buffer_ptr, timestamp_action_diff);
num_records++;
- prev_timestamp_action_encoding = timestamp_action_encoding;
}
// Fill in header information:
// 1 byte of header identifier
// 4 bytes of thread_id
// 3 bytes of number of records
+ // 4 bytes the size of the data
buffer[0] = kEntryHeaderV2;
Append4LE(buffer + 1, thread_id);
Append3LE(buffer + 5, num_records);
+ size_t size = curr_buffer_ptr - buffer;
+ Append4LE(buffer + 8, size - kAlwaysOnTraceHeaderSize);
return curr_buffer_ptr - buffer;
}