Skip to content

Commit

Permalink
test-case: add socwatch parsing toool
Browse files Browse the repository at this point in the history
WIP

Signed-off-by: Fred Oh <fred.oh@linux.intel.com>
  • Loading branch information
fredoh9 committed Aug 31, 2023
1 parent 59bc03f commit 6738f06
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions python-deps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pylint
python3-graphviz
python3-construct
python3-pytest
python3-matplotlib
8 changes: 5 additions & 3 deletions test-case/test-socwatch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ socwatch_test_once()
# set up checkpoint for each iteration
setup_kernel_check_point

# load socwatch module, if the module is loaded, go ahead with the testing (-q)
sudo "$SOCWATCH_PATH"/drivers/insmod-socwatch -q
# load socwatch module, if the module is loaded, try to reload it (-r)
sudo "$SOCWATCH_PATH"/drivers/insmod-socwatch -r
check_socwatch_module_loaded || die "socwatch module not loaded"

( set -x
Expand All @@ -73,9 +73,11 @@ socwatch_test_once()
# filter output and copy to log directory
grep "Package C-State Summary: Residency" -B 8 -A 11 "$SOCWATCH_PATH/sofsocwatch-$i.csv" | tee "$SOCWATCH_PATH/socwatch-$i.txt"
grep "Package Power Summary: Average Rate" -B 6 -A 4 "$SOCWATCH_PATH/sofsocwatch-$i.csv" | tee -a "$SOCWATCH_PATH/socwatch-$i.txt"

sof-socwatch-parser.py "$SOCWATCH_PATH/socwatch-$i.txt"
# zip original csv report
gzip "$SOCWATCH_PATH/sofsocwatch-$i.csv"
mv "$SOCWATCH_PATH/socwatch-$i.txt" "$SOCWATCH_PATH/sofsocwatch-$i.csv.gz" "$LOG_ROOT"/
mv "$SOCWATCH_PATH/socwatch-$i.txt" "$SOCWATCH_PATH/socwatch-$i.png" "$SOCWATCH_PATH/sofsocwatch-$i.csv.gz" "$LOG_ROOT"/

dlogi "Check for the kernel log status"
# check kernel log for each iteration to catch issues
Expand Down
52 changes: 52 additions & 0 deletions tools/sof-socwatch-parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python3

import sys
import os
# Fred: Add new dependency
import matplotlib.pyplot as plt

# Define lists to store C-State names and percentages
c_states = []
percentages = []

# Check if the input file parameter is provided
if len(sys.argv) != 2:
print("Usage: python script_name.py input_file.txt")
sys.exit(1)

input_file = sys.argv[1]

# Read the input file and extract relevant data
with open(input_file, "r") as file:
lines = file.readlines()

# Iterate through the lines and extract C-State data
for line in lines:
# When line starts with PC
if line.strip().startswith("PC"):
columns = line.strip().split(',')
c_state = columns[0].strip()
percentage = float(columns[1].strip())
c_states.append(c_state)
percentages.append(percentage)

# Plotting the data
plt.figure(figsize=(10, 6))
plt.bar(c_states, percentages, color='blue')
plt.xlabel('C-State')
plt.ylabel('Residency (%)')
plt.title('Package C-State Residency')
plt.ylim(0, 100) # Set y-axis limit to percentage values
plt.xticks(rotation=45)
plt.tight_layout()

# Get the directory and base filename of the input file
input_dir = os.path.dirname(input_file)
input_filename = os.path.basename(input_file)

# output_file has same path and same base filename but .png extension
output_file = os.path.join(input_dir, os.path.splitext(input_filename)[0] + '.png')
plt.savefig(output_file)

# Display the plot
#plt.show()

0 comments on commit 6738f06

Please sign in to comment.