diff --git a/clients/drcachesim/tracer/instr_counter.cpp b/clients/drcachesim/tracer/instr_counter.cpp index 2b50bf3e83..fa5dfe357b 100644 --- a/clients/drcachesim/tracer/instr_counter.cpp +++ b/clients/drcachesim/tracer/instr_counter.cpp @@ -41,6 +41,7 @@ #include #include #include +#include // These libraries are safe to use during initialization only. // See api/docs/deployment.dox sec_static_DR. @@ -156,6 +157,8 @@ get_current_no_trace_for_instrs_value() return 0; } +// This function returns true if, at the current no-trace window, there exists an +// instruction count threshold to enable tracing. static bool has_instr_count_threshold_to_enable_tracing() { @@ -470,6 +473,13 @@ parse_instr_intervals_file(std::string path_to_file) if (!std::getline(ss, elem, ',')) FATAL("Fatal error: instruction duration not found.\n"); uint64 duration = std::stoull(elem); + if (duration == 0) { + NOTIFY(0, + "Instruction interval starting at %" PRIu64 " has duration of 0. " + "Removing interval.\n", + start); + continue; + } // Ignore the remaining comma-separated elements, if any. instr_intervals.emplace_back(start, duration); @@ -488,13 +498,18 @@ parse_instr_intervals_file(std::string path_to_file) // 2) Overlapping intervals must be merged. std::vector instr_intervals_merged; instr_intervals_merged.emplace_back(instr_intervals[0]); - for (instr_interval_t &interval : instr_intervals) { + for (size_t i = 1; i < instr_intervals.size(); ++i) { + instr_interval_t &interval = instr_intervals[i]; uint64 end = interval.start + interval.duration; instr_interval_t &last_interval = instr_intervals_merged.back(); uint64 last_end = last_interval.start + last_interval.duration; if (interval.start <= last_end) { uint64 max_end = last_end > end ? last_end : end; last_interval.duration = max_end - last_interval.start; + NOTIFY(0, + "Instruction interval starting at %" PRIu64 " has been merged with " + "instruction interval starting at %" PRIu64 " .\n", + last_interval.start, interval.start); } else { instr_intervals_merged.emplace_back(interval); } @@ -550,9 +565,9 @@ compute_irregular_trace_windows(std::vector &instr_intervals) // must have a duration long enough to cover the end of the program. irregular_window_ptr = (irregular_window_t *)dr_global_alloc(sizeof(irregular_window_t)); - // DELAY_FOREVER_THRESHOLD might be too small for long traces, but it doesn't matter - // because we trace_for_instrs = 0, so no window is created anyway. - irregular_window_ptr->no_trace_for_instrs = DELAY_FOREVER_THRESHOLD; + // We assume that a no_trace_for_instrs of UINT64_MAX is a long enough period that we + // stop tracing for the remaining execution of the traced program. + irregular_window_ptr->no_trace_for_instrs = UINT64_MAX; irregular_window_ptr->trace_for_instrs = 0; drvector_set_entry(&irregular_windows_list, num_intervals, irregular_window_ptr); }