tools/perf/pmu-events/metric_test.py
Source file repositories/reference/linux-study-clean/tools/perf/pmu-events/metric_test.py
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/pmu-events/metric_test.py- Extension
.py- Size
- 6127 bytes
- Lines
- 173
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: tools
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
#!/usr/bin/env python3
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
import unittest
from metric import Constant
from metric import Event
from metric import Expression
from metric import ParsePerfJson
from metric import RewriteMetricsInTermsOfOthers
class TestMetricExpressions(unittest.TestCase):
def test_Operators(self):
a = Event('a')
b = Event('b')
self.assertEqual((a | b).ToPerfJson(), 'a | b')
self.assertEqual((a ^ b).ToPerfJson(), 'a ^ b')
self.assertEqual((a & b).ToPerfJson(), 'a & b')
self.assertEqual((a < b).ToPerfJson(), 'a < b')
self.assertEqual((a > b).ToPerfJson(), 'a > b')
self.assertEqual((a + b).ToPerfJson(), 'a + b')
self.assertEqual((a - b).ToPerfJson(), 'a - b')
self.assertEqual((a * b).ToPerfJson(), 'a * b')
self.assertEqual((a / b).ToPerfJson(), 'a / b')
self.assertEqual((a % b).ToPerfJson(), 'a % b')
one = Constant(1)
self.assertEqual((a + one).ToPerfJson(), 'a + 1')
def test_Brackets(self):
a = Event('a')
b = Event('b')
c = Event('c')
self.assertEqual((a * b + c).ToPerfJson(), 'a * b + c')
self.assertEqual((a + b * c).ToPerfJson(), 'a + b * c')
self.assertEqual(((a + a) + a).ToPerfJson(), 'a + a + a')
self.assertEqual(((a + b) * c).ToPerfJson(), '(a + b) * c')
self.assertEqual((a + (b * c)).ToPerfJson(), 'a + b * c')
self.assertEqual(((a / b) * c).ToPerfJson(), 'a / b * c')
self.assertEqual((a / (b * c)).ToPerfJson(), 'a / (b * c)')
def test_ParsePerfJson(self):
# Based on an example of a real metric.
before = '(a + b + c + d) / (2 * e)'
after = before
self.assertEqual(ParsePerfJson(before).ToPerfJson(), after)
# Parsing should handle events with '-' in their name. Note, in
# the json file the '\' are doubled to '\\'.
before = r'topdown\-fe\-bound / topdown\-slots - 1'
after = before
self.assertEqual(ParsePerfJson(before).ToPerfJson(), after)
# Parsing should handle escaped modifiers. Note, in the json file
# the '\' are doubled to '\\'.
before = r'arb@event\=0x81\,umask\=0x1@ + arb@event\=0x84\,umask\=0x1@'
after = before
self.assertEqual(ParsePerfJson(before).ToPerfJson(), after)
# Parsing should handle exponents in numbers.
before = r'a + 1e12 + b'
after = before
self.assertEqual(ParsePerfJson(before).ToPerfJson(), after)
before = r'a + 3e-12 + b'
after = before
self.assertEqual(ParsePerfJson(before).ToPerfJson(), after)
def test_IfElseTests(self):
# if-else needs rewriting to Select and back.
before = r'Event1 if #smt_on else Event2'
Annotation
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.