tools/power/x86/amd_pstate_tracer/amd_pstate_trace.py

Source file repositories/reference/linux-study-clean/tools/power/x86/amd_pstate_tracer/amd_pstate_trace.py

File Facts

System
Linux kernel
Corpus path
tools/power/x86/amd_pstate_tracer/amd_pstate_trace.py
Extension
.py
Size
11946 bytes
Lines
354
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: GPL-2.0-only
# -*- coding: utf-8 -*-
#
""" This utility can be used to debug and tune the performance of the
AMD P-State driver. It imports intel_pstate_tracer to analyze AMD P-State
trace event.

Prerequisites:
    Python version 2.7.x or higher
    gnuplot 5.0 or higher
    gnuplot-py 1.8 or higher
    (Most of the distributions have these required packages. They may be called
     gnuplot-py, python-gnuplot or python3-gnuplot, gnuplot-nox, ... )

    Kernel config for Linux trace is enabled

    see print_help(): for Usage and Output details

"""
from __future__ import print_function
from datetime import datetime
import subprocess
import os
import time
import re
import signal
import sys
import getopt
import Gnuplot
from numpy import *
from decimal import *
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "intel_pstate_tracer"))
import intel_pstate_tracer as ipt

__license__ = "GPL version 2"

MAX_CPUS = 256
# Define the csv file columns
C_COMM = 15
C_ELAPSED = 14
C_SAMPLE = 13
C_DURATION = 12
C_LOAD = 11
C_TSC = 10
C_APERF = 9
C_MPERF = 8
C_FREQ = 7
C_MAX_PERF = 6
C_DES_PERF = 5
C_MIN_PERF = 4
C_USEC = 3
C_SEC = 2
C_CPU = 1

global sample_num, last_sec_cpu, last_usec_cpu, start_time, test_name, trace_file

getcontext().prec = 11

sample_num =0
last_sec_cpu = [0] * MAX_CPUS
last_usec_cpu = [0] * MAX_CPUS

def plot_per_cpu_freq(cpu_index):
    """ Plot per cpu frequency """

    file_name = 'cpu{:0>3}.csv'.format(cpu_index)
    if os.path.exists(file_name):
        output_png = "cpu%03d_frequency.png" % cpu_index
        g_plot = ipt.common_gnuplot_settings()

Annotation

Implementation Notes