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

Add memory and time thresholds to filter out fast templates #7

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ The `templight-convert` utility supports the following options:
- `--format` or `-f` - Specify the format of Templight outputs (protobuf / xml / text / graphml / graphviz / nestedxml / graphml-cg / graphviz-cg / callgrind, default is protobuf).
- `--blacklist` or `-b` - Use regex expressions in <file> to filter out undesirable traces.
- `--compression` or `-c` - Specify the compression level of Templight outputs whenever the format allows.
- `--time-threshold` or `-t` - Filter out all the template instantitation below this time (in seconds) threshold.
- `--mem-threshold` or `-m` - Filter out all the template instantitation below this memory (in bytes) threshold.
- `--blacklist=<file>` - Specify a blacklist file that lists declaration contexts (e.g., namespaces) and identifiers (e.g., `std::basic_string`) as regular expressions to be filtered out of the trace (not appear in the profiler trace files). Every line of the blacklist file should contain either "context" or "identifier", followed by a single space character and then, a valid regular expression.

### Template Instantiation Tree vs. Meta-Call-Graph
Expand Down
7 changes: 6 additions & 1 deletion convert/templight_convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ int main(int argc, const char **argv) {
("compression,c", po::value<int>()->default_value(0), "Specify the compression level of Templight outputs whenever the format allows.")
("input,i", po::value< std::vector<std::string> >(), "Read Templight profiling traces from <input-file>. If not specified, the traces will be read from stdin.")
("inst-only", "Only keep template instantiations in the output trace.")
("time-threshold,t", po::value<double>()->default_value(0.0), "Filter out all the template instantitation below this time (in seconds) threshold.")
("mem-threshold,m", po::value<uint64_t>()->default_value(0), "Filter out all the template instantitation below this memory (in bytes) threshold.")
;

po::options_description cmdline_options;
Expand Down Expand Up @@ -121,7 +123,10 @@ int main(int argc, const char **argv) {
printer.takeWriter(new GraphMLCGWriter(*printer.getTraceStream()));
}
else if ( Format == "graphviz-cg" ) {
printer.takeWriter(new GraphVizCGWriter(*printer.getTraceStream()));
double time_threshold = vm["time-threshold"].as<double>();
uint64_t memory_threshold = vm["mem-threshold"].as<uint64_t>();
printer.takeWriter(new GraphVizCGWriter(
*printer.getTraceStream(), time_threshold, memory_threshold));
}
else if ( Format == "callgrind" ) {
printer.takeWriter(new CallGrindWriter(*printer.getTraceStream()));
Expand Down
Binary file removed images/fibonacci.o.trace.cg.gv.png
Binary file not shown.
Binary file removed images/fibonacci.o.trace.gv.png
Binary file not shown.
Binary file removed images/fibonacci_brief.o.trace.cg.gv.png
Binary file not shown.
Binary file removed images/fibonacci_brief.o.trace.gv.png
Binary file not shown.
Binary file removed images/fibonacci_inv.o.trace.cg.gv.png
Binary file not shown.
Binary file removed images/fibonacci_inv.o.trace.gv.png
Binary file not shown.
Binary file removed images/fibonacci_inv_brief.o.trace.gv.png
Binary file not shown.
Binary file removed images/fibonacci_small.o.trace.cg.gv.png
Binary file not shown.
Binary file removed images/fibonacci_small.o.trace.gv.png
Binary file not shown.
Binary file removed images/kcachegrind_snap1.png
Binary file not shown.
Binary file removed images/kcachegrind_snap1_small.png
Binary file not shown.
5 changes: 3 additions & 2 deletions include/templight/CallGraphWriters.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class CallGraphWriter : public TreeWriter {
*
* Creates an entry-writer for the given output stream.
*/
CallGraphWriter(std::ostream& aOS);
CallGraphWriter(
std::ostream& aOS, double time_threshold = 0, uint64_t memory_threshold = 0);
~CallGraphWriter();

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, MetaCGVertex, MetaCGEdge> graph_t;
Expand Down Expand Up @@ -154,7 +155,7 @@ class GraphVizCGWriter : public CallGraphWriter {
*
* Creates an entry-writer for the given output stream.
*/
GraphVizCGWriter(std::ostream& aOS);
GraphVizCGWriter(std::ostream& aOS, double time_threshold, uint64_t memory_threshold);
~GraphVizCGWriter();

protected:
Expand Down
5 changes: 4 additions & 1 deletion include/templight/ExtraWriters.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ class TreeWriter : public EntryWriter {
*
* Creates an entry-writer for the given output stream.
*/
TreeWriter(std::ostream& aOS);
TreeWriter(
std::ostream& aOS, double time_threshold = 0, uint64_t memory_threshold = 0);
~TreeWriter();

void initialize(const std::string& aSourceName = "") override;
Expand Down Expand Up @@ -204,6 +205,8 @@ class TreeWriter : public EntryWriter {
virtual void finalizeTree() = 0;

RecordedDFSEntryTree tree;
double time_threshold_;
uint64_t memory_threshold_;
};


Expand Down
33 changes: 20 additions & 13 deletions src/CallGraphWriters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ static std::string escapeXml(const std::string& Input) {



CallGraphWriter::CallGraphWriter(std::ostream& aOS) :
TreeWriter(aOS), g() {}
CallGraphWriter::CallGraphWriter(
std::ostream& aOS, double time_threshold, uint64_t memory_threshold) :
TreeWriter(aOS, time_threshold, memory_threshold), g() {}

CallGraphWriter::~CallGraphWriter() { }

Expand Down Expand Up @@ -120,6 +121,16 @@ void CallGraphWriter::openPrintedTreeNode(const EntryTraversalTask& aNode) {
std::uint64_t mem_diff = 0;
if( EndEntry.MemoryUsage > BegEntry.MemoryUsage ) // avoid underflow
mem_diff = EndEntry.MemoryUsage - BegEntry.MemoryUsage;

// Filter all the instantiations below the memory threshold
if (memory_threshold_ > 0 && mem_diff < memory_threshold_) {
return;
}

// Filter all the instantiations below the time threshold
if (time_threshold_ > 0 && (dT_ns - (time_threshold_ * 1e9)) < 0) {
return;
}

if( BegEntry.InstantiationKind == MemoizationVal ) {
// try to find an existing instantiation:
Expand Down Expand Up @@ -291,8 +302,9 @@ void GraphMLCGWriter::writeGraph() {
}


GraphVizCGWriter::GraphVizCGWriter(std::ostream& aOS) :
CallGraphWriter(aOS) { }
GraphVizCGWriter::GraphVizCGWriter(
std::ostream& aOS, double time_threshold, uint64_t memory_threshold) :
CallGraphWriter(aOS, time_threshold, memory_threshold) { }

GraphVizCGWriter::~GraphVizCGWriter() {}

Expand All @@ -303,15 +315,10 @@ namespace {
GraphVizCGLabelWriter(CallGraphWriter::graph_t* pG) : p_g(pG) { };

void operator()(std::ostream& out, CallGraphWriter::vertex_t v) const {
std::string EscapedName = escapeXml((*p_g)[v].Name);
out
<< "[label = \"" << InstantiationKindStrings[(*p_g)[v].InstantiationKind]
<< "\\n" << EscapedName << "\\n"
<< "At " << (*p_g)[v].CalleeFileName
<< ":" << (*p_g)[v].CalleeLine
<< ":" << (*p_g)[v].CalleeColumn << "\\n"
<< "Time: " << std::fixed << std::setprecision(9) << (1e-9 * double((*p_g)[v].TimeExclCost))
<< " seconds; Memory: " << (*p_g)[v].MemoryExclCost << " bytes\"]";
std::string EscapedName = (*p_g)[v].Name;
out << "Time: " << std::fixed << std::setprecision(9)
<< (1e-9 * double((*p_g)[v].TimeExclCost))
<< " seconds | " << EscapedName;
}
};

Expand Down
7 changes: 5 additions & 2 deletions src/ExtraWriters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,11 @@ void RecordedDFSEntryTree::endEntry(const PrintableEntryEnd& aEntry) {



TreeWriter::TreeWriter(std::ostream& aOS) :
EntryWriter(aOS), tree() { }
TreeWriter::TreeWriter(
std::ostream& aOS, double time_threshold, uint64_t memory_threshold) :
EntryWriter(aOS),
time_threshold_(time_threshold),
memory_threshold_(memory_threshold) { }

TreeWriter::~TreeWriter() { }

Expand Down