tools/perf/python/ilist.py

Source file repositories/reference/linux-study-clean/tools/perf/python/ilist.py

File Facts

System
Linux kernel
Corpus path
tools/perf/python/ilist.py
Extension
.py
Size
18166 bytes
Lines
516
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.

Dependency Surface

Detected Declarations

Annotated Snippet

#!/usr/bin/env python3
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
"""Interactive perf list."""

from abc import ABC, abstractmethod
import argparse
from dataclasses import dataclass
import math
from typing import Any, Dict, Optional, Tuple
import perf
from textual import on
from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.containers import Horizontal, HorizontalGroup, Vertical, VerticalScroll
from textual.css.query import NoMatches
from textual.command import SearchIcon
from textual.screen import ModalScreen
from textual.widgets import Button, Footer, Header, Input, Label, Sparkline, Static, Tree
from textual.widgets.tree import TreeNode


def get_info(info: Dict[str, str], key: str):
    return (info[key] + "\n") if key in info else ""


class TreeValue(ABC):
    """Abstraction for the data of value in the tree."""

    @abstractmethod
    def name(self) -> str:
        pass

    @abstractmethod
    def description(self) -> str:
        pass

    @abstractmethod
    def matches(self, query: str) -> bool:
        pass

    @abstractmethod
    def parse(self) -> perf.evlist:
        pass

    @abstractmethod
    def value(self, evlist: perf.evlist, evsel: perf.evsel, cpu: int, thread: int) -> float:
        pass


@dataclass
class Metric(TreeValue):
    """A metric in the tree."""
    metric_name: str
    metric_pmu: str

    def name(self) -> str:
        return self.metric_name

    def description(self) -> str:
        """Find and format metric description."""
        for metric in perf.metrics():
            if metric["MetricName"] != self.metric_name:
                continue
            if self.metric_pmu and metric["PMU"] != self.metric_pmu:
                continue
            desc = get_info(metric, "BriefDescription")
            desc += get_info(metric, "PublicDescription")
            desc += get_info(metric, "MetricExpr")
            desc += get_info(metric, "MetricThreshold")
            return desc

Annotation

Implementation Notes