From 156faaddbce495ca281d68a0e87f110e1d4be8df Mon Sep 17 00:00:00 2001 From: Derek Bruening Date: Tue, 29 Nov 2022 19:20:47 -0500 Subject: [PATCH] i#2039 trace trim, part 5: Drop early data Part 4 added a minimum timestamp, but it only works for data that is not actually emitted until we are fully attached. For data emitted before that point, we'll use a too-early timestamp. We solve that here by dropping such data. Tested on a large app where these changes solve gaps at the start of the trace due to an early timestamp in one thread. Issue: #2039 --- clients/drcachesim/tracer/output.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/clients/drcachesim/tracer/output.cpp b/clients/drcachesim/tracer/output.cpp index 3dadfd13485..395d4c1d879 100644 --- a/clients/drcachesim/tracer/output.cpp +++ b/clients/drcachesim/tracer/output.cpp @@ -918,7 +918,6 @@ process_and_output_buffer(void *drcontext, bool skip_size_cap) // the first buffer. if (data->has_thread_header && op_offline.get_value()) header_size += data->init_header_size; - data->has_thread_header = false; if (align_attach_detach_endpoints()) { // This is the attach counterpart to instru_t::set_frozen_timestamp(): we place @@ -927,12 +926,20 @@ process_and_output_buffer(void *drcontext, bool skip_size_cap) // tracing. (Switching back to timestamps at buffer output is actually // worse as we then have the identical frozen timestamp for all the flushes // during detach, plus they are all on the same cpu too.) + uint64 min_timestamp = attached_timestamp.load(std::memory_order_acquire); + if (min_timestamp == 0) { + // This data is too early: we drop it. + BUF_PTR(data->seg_base) = data->buf_base + header_size; + return; + } size_t stamp_offs = header_size > buf_hdr_slots_size ? header_size - buf_hdr_slots_size : 0; - uint64 min_timestamp = attached_timestamp.load(std::memory_order_acquire); instru->refresh_unit_header_timestamp(data->buf_base + stamp_offs, min_timestamp); } + // Clear after we know we're not dropping for align_attach_detach_endpoints. + data->has_thread_header = false; + buf_ptr = BUF_PTR(data->seg_base); // We may get called with nothing to write: e.g., on a syscall for // -L0I_filter and -L0D_filter.