aboutsummaryrefslogtreecommitdiffstats
path: root/resources/tools
diff options
context:
space:
mode:
authorViliam Luc <vluc@cisco.com>2022-10-03 14:45:48 +0200
committerPeter Mikus <peter.mikus@protonmail.ch>2022-11-07 11:05:36 +0000
commit5cd951da85f1d57451c1043c38162dccbb67a3e9 (patch)
tree2d5d7644d4380ed33e6752429681c1327f5b9add /resources/tools
parenteaae3a718185987a554ecb4e476da357346c03ee (diff)
telemetry: small fixes
- removed remnant debugging code + fix compatibility with Metric naming convention + fix failures when perf-stat command returns wrong data + better handling when perf-stat command fails Signed-off-by: Viliam Luc <vluc@cisco.com> Change-Id: I23a064ed09c8cf0394abb5306fb04f4e33c20aa4
Diffstat (limited to 'resources/tools')
-rw-r--r--resources/tools/telemetry/bundle_perf_stat.py69
-rw-r--r--resources/tools/telemetry/metrics.py4
2 files changed, 35 insertions, 38 deletions
diff --git a/resources/tools/telemetry/bundle_perf_stat.py b/resources/tools/telemetry/bundle_perf_stat.py
index 038e86e7a0..f76149f476 100644
--- a/resources/tools/telemetry/bundle_perf_stat.py
+++ b/resources/tools/telemetry/bundle_perf_stat.py
@@ -50,49 +50,46 @@ class BundlePerfStat:
:param duration: Time how long perf stat is collecting data (in
seconds). Default value is 1 second.
:type duration: int
- EventCode, UMask, EdgeDetect, AnyThread, Invert, CounterMask
"""
try:
self.serializer.create(metrics=self.metrics)
- for event in self.events:
- text = subprocess.getoutput(
- f"""sudo perf stat -x\; -e\
- '{{cpu/event={hex(event[u"EventCode"])},\
- umask={hex(event[u"UMask"])}/u}}'\
- -a --per-thread\
- sleep {duration}"""
- )
-
- if text == u"":
- getLogger("console_stdout").info(event[u"name"])
- continue
- if u";" not in text:
- getLogger("console_stdout").info(
- f"Could not get counters for event \"{event[u'name']}\""
- f". Is it supported by CPU?"
- )
- continue
-
- for line in text.splitlines():
- item = dict()
- labels = dict()
- item[u"name"] = event[u"name"]
- item[u"value"] = line.split(";")[1]
- labels["thread"] = u"-".join(
- line.split(";")[0].split("-")[0:-1]
- )
- labels["pid"] = line.split(";")[0].split("-")[-1]
- labels["name"] = item[u"name"]
- item[u"labels"] = labels
-
- getLogger("console_stdout").info(item)
- self.api_replies_list.append(item)
-
- except AttributeError:
+ event = self.events[0]
+ text = subprocess.getoutput(
+ f"""sudo perf stat -x\; -e\
+ '{{cpu/event={hex(event[u"eventcode"])},\
+ umask={hex(event[u"umask"])}/u}}'\
+ -a --per-thread\
+ sleep {duration}"""
+ )
+ except subprocess.CalledProcessError:
getLogger("console_stderr").error(f"Could not successfully run "
f"perf stat command.")
sys.exit(Constants.err_linux_perf_stat)
+ if text == u"":
+ getLogger("console_stdout").info(event[u"eventcode"])
+ elif text.count(u";") < 6:
+ getLogger("console_stdout").info(
+ f"Could not get counters for event "\
+ f"{event[u'eventcode']}. "\
+ f"Is it supported by CPU?"
+ )
+ else:
+ for line in text.splitlines():
+ item = dict()
+ labels = dict()
+ item[u"name"] = self.metrics['counter'][0]['name']
+ item[u"value"] = line.split(";")[1]
+ labels["thread"] = u"-".join(
+ line.split(";")[0].split("-")[0:-1]
+ )
+ labels["pid"] = line.split(";")[0].split("-")[-1]
+ item[u"labels"] = labels
+
+ getLogger("console_stdout").info(item)
+ self.api_replies_list.append(item)
+
+
def detach(self):
pass
diff --git a/resources/tools/telemetry/metrics.py b/resources/tools/telemetry/metrics.py
index ba6bae5e70..7a22acfd1b 100644
--- a/resources/tools/telemetry/metrics.py
+++ b/resources/tools/telemetry/metrics.py
@@ -104,7 +104,7 @@ class Metric:
u"Sample", [u"name", u"labels", u"value", u"timestamp"]
)
- if not re.compile(r"^[a-zA-Z_:\-.][a-zA-Z0-9_:\-.]*$").match(name):
+ if not re.compile(r"^[a-zA-Z_:][a-zA-Z0-9_:]*$").match(name):
raise ValueError(f"Invalid metric name: {name}!")
if typ not in self.metric_types:
raise ValueError(f"Invalid metric type: {typ}!")
@@ -214,7 +214,7 @@ class MetricBase:
full_name += f"{subsystem}_" if subsystem else u""
full_name += name
- if not re.compile(r"^[a-zA-Z_:\-.][a-zA-Z0-9_:\-.]*$").match(full_name):
+ if not re.compile(r"^[a-zA-Z_:][a-zA-Z0-9_:]*$").match(full_name):
raise ValueError(
f"Invalid metric name: {full_name}!"
)