Skip to content

Commit

Permalink
Add max_column_width option for runtime-report (LLNL#260)
Browse files Browse the repository at this point in the history
* Add max_column_width option for runtime-report

* Fix option name

* Fix typo
  • Loading branch information
daboehme authored Apr 2, 2020
1 parent 62ed72a commit 3ab45e9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 24 deletions.
19 changes: 17 additions & 2 deletions src/caliper/controllers/RuntimeReportController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ class RuntimeReportController : public cali::ChannelController
pmetric = "inclusive_percent_total(sum#sum#time.duration)";
}

std::string formatarg;

if (opts.is_set("max_column_width")) {
formatarg = "(prop:nested,";
formatarg.append(opts.get("max_column_width").to_string());
formatarg.append(")");
}

// Config for second aggregation step in MPI mode (cross-process aggregation)
std::string cross_select =
std::string(" min(") + tmetric + ") as \"Min time/rank\""
Expand All @@ -71,7 +79,8 @@ class RuntimeReportController : public cali::ChannelController
+ opts.query_select("cross", cross_select)
+ " group by "
+ opts.query_groupby("cross", "prop:nested")
+ " format tree";
+ " format tree"
+ formatarg;
} else {
config()["CALI_SERVICES_ENABLE" ].append(",report");
config()["CALI_REPORT_FILENAME" ] = opts.get("output", "stderr").to_string();
Expand All @@ -80,7 +89,8 @@ class RuntimeReportController : public cali::ChannelController
+ opts.query_select("serial", serial_select)
+ " group by "
+ opts.query_groupby("serial", "prop:nested")
+ " format tree";
+ " format tree"
+ formatarg;
}

opts.update_channel_config(config());
Expand Down Expand Up @@ -133,6 +143,11 @@ const char* runtime_report_spec =
" \"name\": \"aggregate_across_ranks\","
" \"type\": \"bool\","
" \"description\": \"Aggregate results across MPI ranks\""
" },"
" {"
" \"name\": \"max_column_width\","
" \"type\": \"int\","
" \"description\": \"Maximum column width in the tree display\""
" }"
" ]"
"}";
Expand Down
58 changes: 36 additions & 22 deletions src/reader/TreeFormatter.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2019, Lawrence Livermore National Security, LLC.
// See top-level LICENSE file for details.

// Pretty-print tree-organized snapshots
// Pretty-print tree-organized snapshots

#include "caliper/reader/TreeFormatter.h"

Expand Down Expand Up @@ -38,14 +38,16 @@ struct TreeFormatter::TreeFormatterImpl
std::string display_name;
int width;
};

std::map<Attribute, ColumnInfo> m_column_info;

int m_path_column_width;
int m_max_column_width;

std::map<std::string, std::string> m_aliases;

bool m_use_nested;

std::vector<std::string> m_path_key_names;
std::vector<Attribute> m_path_keys;

Expand All @@ -61,23 +63,34 @@ struct TreeFormatter::TreeFormatterImpl
// set max column width
if (spec.format.args.size() > 1) {
bool ok = false;

m_max_column_width = StringConverter(spec.format.args[1]).to_int(&ok);

if (!ok) {
Log(0).stream() << "TreeFormatter: invalid column width argument \""
Log(0).stream() << "TreeFormatter: invalid column width argument \""
<< spec.format.args[1] << "\""
<< std::endl;

m_max_column_width = -1;
}
}


{
auto it = std::find(m_path_key_names.begin(), m_path_key_names.end(),
"prop:nested");

if (it != m_path_key_names.end()) {
m_use_nested = true;
m_path_key_names.erase(it);
} else if (!m_path_key_names.empty())
m_use_nested = false;
}

m_path_keys.assign(m_path_key_names.size(), Attribute::invalid);
m_attribute_columns = spec.attribute_selection;
m_aliases = spec.aliases;
}

std::vector<Attribute> get_path_keys(const CaliperMetadataAccessInterface& db) {
std::vector<Attribute> path_keys;

Expand All @@ -88,7 +101,7 @@ struct TreeFormatter::TreeFormatterImpl
path_keys = m_path_keys;
}

for (std::vector<Attribute>::size_type i = 0; i < path_keys.size(); ++i)
for (std::vector<Attribute>::size_type i = 0; i < path_keys.size(); ++i)
if (path_keys[i] == Attribute::invalid) {
Attribute attr = db.get_attribute(m_path_key_names[i]);

Expand All @@ -97,7 +110,7 @@ struct TreeFormatter::TreeFormatterImpl
std::lock_guard<std::mutex>
g(m_path_key_lock);
m_path_keys[i] = attr;
}
}
}

return path_keys;
Expand All @@ -106,19 +119,19 @@ struct TreeFormatter::TreeFormatterImpl
void add(const CaliperMetadataAccessInterface& db, const EntryList& list) {
const SnapshotTreeNode* node = nullptr;

if (m_path_key_names.empty()) {
if (m_use_nested) {
node = m_tree.add_snapshot(db, list, [](const Attribute& attr,const Variant&){
return attr.is_nested();
});
} else {
} else {
auto path_keys = get_path_keys(db);

node = m_tree.add_snapshot(db, list, [&path_keys](const Attribute& attr, const Variant&){
return (std::find(std::begin(path_keys), std::end(path_keys),
return (std::find(std::begin(path_keys), std::end(path_keys),
attr) != std::end(path_keys));
});
}

if (!node)
return;

Expand All @@ -139,7 +152,7 @@ struct TreeFormatter::TreeFormatterImpl

if (it == m_column_info.end()) {
std::string name = p.first.name();

auto ait = m_aliases.find(name);
if (ait != m_aliases.end())
name = ait->second;
Expand All @@ -152,18 +165,18 @@ struct TreeFormatter::TreeFormatterImpl
}
}

void recursive_print_nodes(const SnapshotTreeNode* node,
int level,
const std::vector<Attribute>& attributes,
void recursive_print_nodes(const SnapshotTreeNode* node,
int level,
const std::vector<Attribute>& attributes,
std::ostream& os)
{
//
//
// print this node
//

std::string path_str;
path_str.append(std::min(2*level, m_path_column_width-2), ' ');

if (2*level >= m_path_column_width)
path_str.append("..");
else
Expand Down Expand Up @@ -196,7 +209,7 @@ struct TreeFormatter::TreeFormatterImpl

os << std::endl;

//
//
// recursively descend
//

Expand All @@ -209,7 +222,7 @@ struct TreeFormatter::TreeFormatterImpl

if (m_max_column_width > 0)
m_path_column_width = std::min(m_path_column_width, std::max(4, m_max_column_width));

//
// establish order of attribute columns
//
Expand Down Expand Up @@ -272,7 +285,8 @@ struct TreeFormatter::TreeFormatterImpl

TreeFormatterImpl()
: m_path_column_width(0),
m_max_column_width(48)
m_max_column_width(48),
m_use_nested(true)
{ }
};

Expand Down

0 comments on commit 3ab45e9

Please sign in to comment.