/ tools / scripts / misc / tick_plotter.py
tick_plotter.py
 1  import matplotlib.pyplot as plt
 2  import sys
 3  import os
 4  import numpy as np
 5  from scipy import stats
 6  
 7  def plot_ticks(file_path):
 8    ticks_65 = []
 9    ticks_67 = []
10    line_numbers_65 = []
11    line_numbers_67 = []
12  
13    with open(file_path, 'r') as file:
14      for i, line in enumerate(file):
15        parts_vertical_split = line.split('|')
16        parts = parts_vertical_split[1].split(',')
17  
18        tick = int(parts[0].strip().split(':')[1].strip())
19        addr = int(parts[2].strip().split(':')[1].strip())
20        if addr == 65:
21          ticks_65.append(tick)
22          line_numbers_65.append(i + 1)
23        elif addr == 67:
24          ticks_67.append(tick)
25          line_numbers_67.append(i + 1)
26  
27    # Calculate differences and average difference for addr: 65
28    if ticks_65:
29      plt.figure()  # Create a new figure
30      differences_65 = np.diff(ticks_65)
31  
32      for i in range(1, len(ticks_65)):
33        if abs(differences_65[i - 1]) > 10000:
34            plt.axvline(x=line_numbers_65[i], color='red')
35        plt.plot([line_numbers_65[i - 1], line_numbers_65[i]], [ticks_65[i - 1], ticks_65[i]], color='blue')
36  
37      plt.xlabel('Line Number')
38      plt.ylabel('Tick')
39      plt.title('Tick Plot for ' + file_path + ' (addr: 65)')
40      plt.legend()
41  
42      # Save the plot as a JPEG file in the same directory as the input file
43      dir_name = os.path.dirname(file_path)
44      base_name = os.path.basename(file_path)
45      plot_file_name = os.path.splitext(base_name)[0] + '_ticks_plot_65.jpg'
46      plot_file_path = os.path.join(dir_name, plot_file_name)
47      plt.savefig(plot_file_path)
48  
49    # Calculate differences and mode difference for addr: 67
50    if ticks_67:
51      plt.figure()  # Create a new figure
52      differences_67 = np.diff(ticks_67)
53  
54      for i in range(1, len(ticks_67)):
55        if abs(differences_67[i - 1]) > 10000:
56            plt.axvline(x=line_numbers_67[i], color='red')
57        plt.plot([line_numbers_67[i - 1], line_numbers_67[i]], [ticks_67[i - 1], ticks_67[i]], color='blue')
58  
59      plt.xlabel('Line Number')
60      plt.ylabel('Tick')
61      plt.title('Tick Plot for ' + file_path + ' (addr: 67)')
62      plt.legend()
63  
64      # Save the plot as a JPEG file in the same directory as the input file
65      plot_file_name = os.path.splitext(base_name)[0] + '_ticks_plot_67.jpg'
66      plot_file_path = os.path.join(dir_name, plot_file_name)
67      plt.savefig(plot_file_path)
68  
69  def find_power_logs(directory):
70      power_logs = []
71      for root, dirs, files in os.walk(directory):
72          for file in files:
73              if file == 'power.log':
74                  power_logs.append(os.path.join(root, file))
75      return power_logs
76  
77  # Get directory from command-line arguments
78  directory = sys.argv[1]
79  
80  # Find all power.log files in the directory and its subdirectories
81  power_logs = find_power_logs(directory)
82  
83  # Plot ticks for each power.log file
84  for power_log in power_logs:
85      plot_ticks(power_log)
86  
87  plt.show()  # Show all the plots at once