Skip to content

Commit

Permalink
Issue #22 and #23 - Included the default PMID in the exported PMNS da…
Browse files Browse the repository at this point in the history
…ta for compatibility with some PCP utilities, when the PMDA is not yet installed.
  • Loading branch information
pcolby committed May 10, 2014
1 parent 48a26c7 commit c4aba36
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 5 deletions.
17 changes: 12 additions & 5 deletions include/pcp-cpp/pmda.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "-") {
Expand All @@ -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();
Expand All @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions test/functional/test_simple_export_pmns.expected
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

#ifndef SIMPLE
#define SIMPLE 253
#endif

simple {
numfetch SIMPLE:0:0
color SIMPLE:0:1
Expand Down
4 changes: 4 additions & 0 deletions test/functional/test_simplecpu_export_pmns.expected
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

#ifndef SIMPLECPU
#define SIMPLECPU 129
#endif

simplecpu {
ticks
}
Expand Down
9 changes: 9 additions & 0 deletions test/functional/test_simplecpu_help_text.command
Original file line number Diff line number Diff line change
@@ -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" <<EOF
open pipe pmdasimplecpu
text simplecpu.ticks.total
text simplecpu.ticks.cpu0
EOF
rm -rf "$TEMP_DIR"
10 changes: 10 additions & 0 deletions test/functional/test_simplecpu_help_text.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
open pipe pmdasimplecpu
Start pmdasimplecpu PMDA: ./pmdasimplecpu
text simplecpu.ticks.total
PMID: 129.0.0
[The amount of time spent in various states]
The amount of time spent in various states
text simplecpu.ticks.cpu0
PMID: 129.0.1
[The amount of time spent in various states]
The amount of time spent in various states
4 changes: 4 additions & 0 deletions test/functional/test_trivial_export_pmns.expected
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

#ifndef TRIVIAL
#define TRIVIAL 250
#endif

trivial {
time TRIVIAL:0:0
}
Expand Down
8 changes: 8 additions & 0 deletions test/functional/test_trivial_help_text.command
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
TEMP_DIR=`mktemp -d -t test_trivial_text-XXXXXXXXXX`
./pmdatrivial --export-all "$TEMP_DIR"
if [ $? -ne 0 ]; then exit; fi
dbpmda -e -n "$TEMP_DIR/root" <<EOF
open pipe pmdatrivial
text trivial.time
EOF
rm -rf "$TEMP_DIR"
6 changes: 6 additions & 0 deletions test/functional/test_trivial_help_text.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
open pipe pmdatrivial
Start pmdatrivial PMDA: ./pmdatrivial
text trivial.time
PMID: 250.0.0
[The time in seconds since 1 Jan 1970]
The time in seconds since the 1st of January, 1970.

0 comments on commit c4aba36

Please sign in to comment.