Skip to content

Commit 51ad45b

Browse files
author
Maximilian Sander
committed
Remove the location from the Score-P metric name
1 parent e82e3f3 commit 51ad45b

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ cmake -DMETRICQ_METRIC_PER_HOST=ON ...
9292
```
9393

9494
When using `per_host` mode, it is critical to ensure that only the rank(s) associated with a given node request metrics from MetricQ.
95+
This is controlled via the variable `SCOREP_METRIC_METRICQ_PLUGIN_PER_HOST_LOCATION`, which specifies the location of the metric.
96+
97+
The value of `SCOREP_METRIC_METRICQ_PLUGIN_PER_HOST_LOCATION` must equal the prefix of the metrics listed in `SCOREP_METRIC_METRICQ_PLUGIN`.
98+
This design allows the metric location to be specified explicitly without requiring any modification of the metric string passed to `SCOREP_METRIC_METRICQ_PLUGIN`.
99+
In effect, location and metric name are separated while remaining consistent.
100+
95101
On ZIH systems, this can be achieved by constructing node-specific metric names using SLURM environment variables.
96102
For example:
97103

@@ -101,6 +107,7 @@ METRIC=power
101107
102108
srun bash -c '
103109
export SCOREP_METRIC_METRICQ_PLUGIN=$SLURM_CLUSTER_NAME.$SLURMD_NODENAME.'"$METRIC"'
110+
export SCOREP_METRIC_METRICQ_PLUGIN_PER_HOST_LOCATION=$SLURM_CLUSTER_NAME.$SLURMD_NODENAME
104111
exec '"$EXE"'
105112
'
106113
```

src/main.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <vector>
2121

2222
#include <cstdint>
23+
#include <cstdlib>
2324

2425
using namespace scorep::plugin::policy;
2526

@@ -57,6 +58,18 @@ void replace_all(std::string& str, const std::string& from, const std::string& t
5758
}
5859
}
5960

61+
std::string remove_prefix(std::string name, const std::string& prefix)
62+
{
63+
if (name.rfind(prefix, 0) == 0) { // prefix at position 0
64+
name.erase(0, prefix.size());
65+
if (!name.empty() && name[0] == '.') {
66+
name.erase(0, 1); // remove separator
67+
}
68+
}
69+
return name;
70+
}
71+
72+
6073
template <typename T, typename Policies>
6174
using handle_oid_policy = object_id<Metric, T, Policies>;
6275

@@ -104,6 +117,7 @@ class metricq_plugin : public scorep::plugin::base<metricq_plugin,
104117
public:
105118
std::vector<scorep::plugin::metric_property> get_metric_properties(const std::string& s)
106119
{
120+
//
107121
auto metadata = get_metadata(s);
108122
std::vector<scorep::plugin::metric_property> result;
109123
for (const auto& elem : metadata)
@@ -118,11 +132,21 @@ class metricq_plugin : public scorep::plugin::base<metricq_plugin,
118132
}
119133
#endif
120134
auto use_average = use_timesync && average_;
135+
#ifdef METRICQ_METRIC_PER_HOST
136+
std::string metric_prefix = "metricq_";
137+
std::string per_host_location_env = scorep::environment_variable::get("PER_HOST_LOCATION", "");
138+
139+
std::string metric_name = metric_prefix + remove_prefix(name, std::string( per_host_location_env ));
140+
141+
make_handle(metric_name, Metric{ name, use_timesync, use_average });
142+
auto property = scorep::plugin::metric_property(metric_name, meta.description(), meta.unit())
143+
.value_double();
144+
#else
121145
make_handle(name, Metric{ name, use_timesync, use_average });
122146

123147
auto property = scorep::plugin::metric_property(name, meta.description(), meta.unit())
124148
.value_double();
125-
149+
#endif
126150
if (use_average)
127151
{
128152
property.absolute_last();

0 commit comments

Comments
 (0)