Skip to content

Commit 663d0e6

Browse files
rewrite documentation for metrics section.
update exmaple for metrics_regex.yml
1 parent 9a63fd5 commit 663d0e6

File tree

2 files changed

+41
-20
lines changed

2 files changed

+41
-20
lines changed

docs/writing_buildspecs/performance_checks.rst

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ Defining Metrics
99
------------------
1010

1111
buildtest provides a method to define test metrics in the buildspecs which can be used to
12-
store arbitrary content from the output/error file into named metric. A metric is
13-
defined using the ``metrics`` property where each element under the **metrics** property
14-
is the name of the metric which must be a unique name. A metric can apply regular expression
15-
on stdout, stderr like in this example below. The metrics are captured in the test report which can
16-
be queried via ``buildtest report`` or ``buildtest inspect``. Shown below is an example
17-
where we define two metrics named ``hpcg_rating`` and ``hpcg_state``.
12+
store arbitrary content from the output/error file or an arbitrary file into named metric. The
13+
``metrics`` property is used to define a list of metric names using regular expression to assign a value
14+
to the metric. In this example, we have two tests that define metrics ``hpcg_rate_stream``, ``hpcg_state_stream``
15+
in the first test and ``hpcg_rate_file``, ``hpcg_state_file`` in the second test. The ``stream`` property is used
16+
to read from stdout/stderr and apply the regular expression defined by ``exp``, whereas ``file`` will read
17+
from an arbitrary file name of your choice.
1818

1919
.. literalinclude:: ../tutorials/metrics_regex.yml
2020
:language: yaml
21-
:emphasize-lines: 8-19
21+
:emphasize-lines: 8-19,27-37
2222

23-
The metrics will not impact behavior of test, it will only impact the test report. By default
24-
a metric will be an empty dictionary if there is no ``metrics`` property. If we fail to match
25-
a regular expression, the metric will be defined as an empty string.
23+
The metrics can be used with :ref:`comparison_operators` for performing more sophisticated status checks.
24+
By default, a metric will be an empty dictionary if there is no ``metrics`` property. If we fail to match
25+
a regular expression, the metric will be defined as an empty string (``''``).
2626

2727
.. Note::
2828
If your regular expression contains an escape character ``\`` you must surround your
@@ -34,7 +34,15 @@ Let's build this test.
3434

3535
.. command-output:: buildtest build -b tutorials/metrics_regex.yml
3636

37-
We can query the metrics via ``buildtest report`` which will display all metrics as a comma separted
37+
The metrics are captured in the test report which can
38+
be queried via ``buildtest report`` or ``buildtest inspect query``. Metrics can be seen in the test metadata,
39+
for instance you can run ``buildtest inspect query`` and you will see metrics shown in table output.
40+
41+
.. dropdown:: ``buildtest inspect query metric_regex_example metric_file_regex
42+
43+
.. command-output:: buildtest inspect query metric_regex_example metric_file_regex
44+
45+
We can query the metrics via ``buildtest report`` which will display all metrics as a comma seperated
3846
**Key/Value** pair. We can use ``buildtest report --format metrics`` to extract all metrics for a test.
3947
Internally, we store the metrics as a dictionary but when we print them out via ``buildtest report`` we
4048
join them together into a single string. Shown below is the metrics for the previous build.
@@ -43,12 +51,7 @@ join them together into a single string. Shown below is the metrics for the prev
4351

4452
.. command-output:: buildtest report --filter buildspec=tutorials/metrics_regex.yml --format name,metrics
4553

46-
You can define a metric based on :ref:`variables <variables>` or :ref:`environment variables <environment_variables>`
47-
which requires you have set ``vars`` or ``env`` property in the buildspec. The ``vars`` and
48-
``env`` is a property under the metric name that can be used to reference name
49-
of variable or environment variable. If you reference an invalid name, buildtest will assign the metric an empty string.
50-
In this next example, we define two metrics ``gflop`` and ``foo`` that are assigned to variable ``GFLOPS`` and
51-
environment variable ``FOO``.
54+
.. _comparison_operators:
5255

5356
Comparison Operators
5457
----------------------

tutorials/metrics_regex.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,32 @@ buildspecs:
66
run: echo "HPCG result is VALID with a GFLOP/s rating of=63.6515"
77
tags: tutorials
88
metrics:
9-
hpcg_rating:
9+
hpcg_rating_stream:
1010
type: float
1111
regex:
1212
exp: '(\d+\.\d+)$'
1313
stream: stdout
1414

15-
hpcg_state:
15+
hpcg_state_stream:
1616
type: str
1717
regex:
1818
exp: '(VALID)'
19-
stream: stdout
19+
stream: stdout
20+
21+
metric_file_regex:
22+
executor: generic.local.sh
23+
type: script
24+
description: capture result metric from output
25+
run: echo "HPCG result is VALID with a GFLOP/s rating of=63.6515" > hpcg.txt
26+
tags: tutorials
27+
metrics:
28+
hpcg_rating_file:
29+
type: float
30+
regex:
31+
exp: '(\d+\.\d+)$'
32+
file: hpcg.txt
33+
hpcg_state_file:
34+
type: str
35+
regex:
36+
exp: '(VALID)'
37+
file: hpcg.txt

0 commit comments

Comments
 (0)