Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i#6635 core filter, part 7: Improve init-idle subclass support #6707

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 13 additions & 37 deletions clients/drcachesim/tools/filter/record_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,17 @@ record_filter_t::initialize_shard_type(shard_type_t shard_type)
return "";
}

std::string
record_filter_t::get_output_basename(memtrace_stream_t *shard_stream)
{
if (shard_type_ == SHARD_BY_CORE) {
return output_dir_ + DIRSEP + "drmemtrace.core." +
std::to_string(shard_stream->get_shard_index()) + ".trace";
} else {
return output_dir_ + DIRSEP + shard_stream->get_stream_name();
}
}

std::string
record_filter_t::initialize_shard_output(per_shard_t *per_shard,
memtrace_stream_t *shard_stream)
Expand All @@ -192,8 +203,7 @@ record_filter_t::initialize_shard_output(per_shard_t *per_shard,
// Since some shards may not have inputs, we need to synchronize determining
// the file extension.
// First, get our path without the extension, so we can add it later.
per_shard->output_path = output_dir_ + DIRSEP + "drmemtrace.core." +
std::to_string(shard_stream->get_shard_index()) + ".trace";
per_shard->output_path = get_output_basename(shard_stream);
std::string input_name = shard_stream->get_stream_name();
// Now synchronize determining the extension.
auto lock = std::unique_lock<std::mutex>(input_info_mutex_);
Expand All @@ -218,7 +228,7 @@ record_filter_t::initialize_shard_output(per_shard_t *per_shard,
lock.unlock();
}
} else {
per_shard->output_path = output_dir_ + DIRSEP + shard_stream->get_stream_name();
per_shard->output_path = get_output_basename(shard_stream);
}
return "";
}
Expand All @@ -228,40 +238,6 @@ record_filter_t::get_writer(per_shard_t *per_shard, memtrace_stream_t *shard_str
{
if (per_shard->output_path.empty())
return "Error: output_path is empty";
if (shard_type_ == SHARD_BY_CORE) {
derekbruening marked this conversation as resolved.
Show resolved Hide resolved
// Each output is a mix of inputs so we do not want to reuse the input
// names with tids.
// Since some shards may not have inputs, we need to synchronize determining
// the file extension.
// First, get our path without the extension, so we can add it later.
per_shard->output_path = output_dir_ + DIRSEP + "drmemtrace.core." +
std::to_string(shard_stream->get_shard_index()) + ".trace";
std::string input_name = shard_stream->get_stream_name();
// Now synchronize determining the extension.
auto lock = std::unique_lock<std::mutex>(input_info_mutex_);
if (!output_ext_.empty()) {
per_shard->output_path += output_ext_;
lock.unlock();
} else if (!input_name.empty()) {
size_t last_dot = input_name.rfind('.');
if (last_dot == std::string::npos)
return "Failed to determine filename type from extension";
output_ext_ = input_name.substr(last_dot);
// Set the other key input data.
version_ = shard_stream->get_version();
filetype_ = add_to_filetype(shard_stream->get_filetype());
per_shard->output_path += output_ext_;
lock.unlock();
input_info_cond_var_.notify_all();
} else {
// We have to wait for another shard with an input to set output_ext_.
input_info_cond_var_.wait(lock, [this] { return !output_ext_.empty(); });
per_shard->output_path += output_ext_;
lock.unlock();
}
} else {
per_shard->output_path = output_dir_ + DIRSEP + shard_stream->get_stream_name();
}
#ifdef HAS_ZLIB
if (ends_with(per_shard->output_path, ".gz")) {
VPRINT(this, 3, "Using the gzip writer for %s\n", per_shard->output_path.c_str());
Expand Down
25 changes: 15 additions & 10 deletions clients/drcachesim/tools/filter/record_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,27 @@ class record_filter_t : public record_analysis_tool_t {
std::string
process_delayed_encodings(per_shard_t *per_shard, trace_entry_t &entry, bool output);

// Computes the output path without the extension output_ext_ which is added
// separately after determining the input path extension.
virtual std::string
get_output_basename(memtrace_stream_t *shard_stream);

std::unordered_map<int, per_shard_t *> shard_map_;
// This mutex is only needed in parallel_shard_init. In all other accesses
// to shard_map (print_results) we are single-threaded.
std::mutex shard_map_mutex_;
shard_type_t shard_type_ = SHARD_BY_THREAD;

// For core-sharded we don't have a 1:1 input:output file mapping.
// Thus, some shards may not have an input stream at init time, and
// need to figure out their file extension and header info from other shards.
std::mutex input_info_mutex_;
std::condition_variable input_info_cond_var_;
// The above locks guard these fields:
std::string output_ext_;
uint64_t version_ = 0;
uint64_t filetype_ = 0;

private:
virtual bool
write_trace_entry(per_shard_t *shard, const trace_entry_t &entry);
Expand Down Expand Up @@ -254,16 +269,6 @@ class record_filter_t : public record_analysis_tool_t {
// XXX: We could use a read-write lock but C++11 doesn't have a ready-made one.
// If we had the input count we could use an array and atomic reads.
std::unordered_map<int64_t, std::unique_ptr<per_input_t>> input2info_;

// For core-sharded we don't have a 1:1 input:output file mapping.
// Thus, some shards may not have an input stream at init time, and
// need to figure out their file extension and header info from other shards.
std::mutex input_info_mutex_;
std::condition_variable input_info_cond_var_;
// The above locks guard these fields:
std::string output_ext_;
uint64_t version_ = 0;
uint64_t filetype_ = 0;
};

} // namespace drmemtrace
Expand Down
Loading