diff --git a/python-deps.txt b/python-deps.txt index 4a8ca801..7ef14cc8 100644 --- a/python-deps.txt +++ b/python-deps.txt @@ -4,3 +4,4 @@ pylint python3-graphviz python3-construct python3-pytest +python3-matplotlib diff --git a/test-case/test-socwatch.sh b/test-case/test-socwatch.sh index 47619150..19a179ad 100755 --- a/test-case/test-socwatch.sh +++ b/test-case/test-socwatch.sh @@ -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 @@ -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 diff --git a/tools/sof-socwatch-parser.py b/tools/sof-socwatch-parser.py new file mode 100755 index 00000000..46320ee3 --- /dev/null +++ b/tools/sof-socwatch-parser.py @@ -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()