From c4aba3608f0f699b2df6c3d61e9f7df3aca859a0 Mon Sep 17 00:00:00 2001 From: Paul Colby Date: Sat, 10 May 2014 16:34:34 +1000 Subject: [PATCH] Issue #22 and #23 - Included the default PMID in the exported PMNS data for compatibility with some PCP utilities, when the PMDA is not yet installed. --- include/pcp-cpp/pmda.hpp | 17 ++++++++++++----- .../functional/test_simple_export_pmns.expected | 4 ++++ .../test_simplecpu_export_pmns.expected | 4 ++++ .../functional/test_simplecpu_help_text.command | 9 +++++++++ .../test_simplecpu_help_text.expected | 10 ++++++++++ .../test_trivial_export_pmns.expected | 4 ++++ test/functional/test_trivial_help_text.command | 8 ++++++++ test/functional/test_trivial_help_text.expected | 6 ++++++ 8 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 test/functional/test_simplecpu_help_text.command create mode 100644 test/functional/test_simplecpu_help_text.expected create mode 100644 test/functional/test_trivial_help_text.command create mode 100644 test/functional/test_trivial_help_text.expected diff --git a/include/pcp-cpp/pmda.hpp b/include/pcp-cpp/pmda.hpp index 12ada33..2735fb9 100644 --- a/include/pcp-cpp/pmda.hpp +++ b/include/pcp-cpp/pmda.hpp @@ -1310,6 +1310,11 @@ class pmda { void export_pmns_data(const std::string &filename) const { + // Some basic strings we'll use a couple of times. + const std::string &pmda_name = get_pmda_name(); + std::string upper_name = get_pmda_name(); + std::transform(upper_name.begin(), upper_name.end(), upper_name.begin(), ::toupper); + // Open the output file. std::ofstream file_stream; if (filename != "-") { @@ -1320,6 +1325,13 @@ class pmda { } std::ostream &stream = (filename == "-") ? std::cout : file_stream; + // Define the PMID, if not already. + stream + << std::endl + << "#ifndef " << upper_name << std::endl + << "#define " << upper_name << ' ' << get_default_pmda_domain_number() << std::endl + << "#endif" << std::endl; + // First pass to find the length of the longest metric name. std::string::size_type max_metric_name_size = 0; for (metrics_description::const_iterator metrics_iter = supported_metrics.begin(); @@ -1335,11 +1347,6 @@ class pmda { } } - // Some basic strings we'll use a couple of times. - const std::string &pmda_name = get_pmda_name(); - std::string upper_name = get_pmda_name(); - std::transform(upper_name.begin(), upper_name.end(), upper_name.begin(), ::toupper); - // Second pass to export the group names and ungrouped metrics. stream << std::endl << pmda_name << " {" << std::endl; for (metrics_description::const_iterator metrics_iter = supported_metrics.begin(); diff --git a/test/functional/test_simple_export_pmns.expected b/test/functional/test_simple_export_pmns.expected index 30f4f9d..71ec015 100644 --- a/test/functional/test_simple_export_pmns.expected +++ b/test/functional/test_simple_export_pmns.expected @@ -1,4 +1,8 @@ +#ifndef SIMPLE +#define SIMPLE 253 +#endif + simple { numfetch SIMPLE:0:0 color SIMPLE:0:1 diff --git a/test/functional/test_simplecpu_export_pmns.expected b/test/functional/test_simplecpu_export_pmns.expected index 09c7fd1..1c08cac 100644 --- a/test/functional/test_simplecpu_export_pmns.expected +++ b/test/functional/test_simplecpu_export_pmns.expected @@ -1,4 +1,8 @@ +#ifndef SIMPLECPU +#define SIMPLECPU 129 +#endif + simplecpu { ticks } diff --git a/test/functional/test_simplecpu_help_text.command b/test/functional/test_simplecpu_help_text.command new file mode 100644 index 0000000..b8176e1 --- /dev/null +++ b/test/functional/test_simplecpu_help_text.command @@ -0,0 +1,9 @@ +TEMP_DIR=`mktemp -d -t test_simplecpu_help_text-XXXXXXXXXX` +./pmdasimplecpu --export-all "$TEMP_DIR" +if [ $? -ne 0 ]; then exit; fi +dbpmda -e -n "$TEMP_DIR/root" <