Created
April 28, 2023 09:58
-
-
Save laohyx/c43fe060bee717f813de7a8fc40ae29b to your computer and use it in GitHub Desktop.
Liux interrupts watcher and list top IRQs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
__doc__ = """This script greps from /proc/interrupts and print the top interrupts of CPU cores and sources. | |
Super useful for 64+ cores machine, whose /proc/interrupts is totally unreadable. | |
""" | |
def get_interrupts_dict(): | |
cpu_count = 0 | |
result = {} | |
with open('/proc/interrupts') as f: | |
for line_num, line in enumerate(f): | |
line = line.strip() | |
arr = line.split(" ") | |
arr = filter(lambda x : x, arr) | |
arr = list(arr) | |
if len(arr) < 4: | |
continue | |
if line_num == 0: | |
cpu_count = len(arr) | |
continue | |
key_arr = arr[0:1] + arr[1 + cpu_count:] | |
key = " ".join(key_arr) | |
values = [int(x) for x in arr[1:1+cpu_count]] | |
result[key] = values | |
return result | |
def show_dict_diff_values(dict1, dict2): | |
diff_array = [] | |
for key, value1 in dict1.items(): | |
if key not in dict2: | |
continue | |
value2 = dict2[key] | |
for i in range(len(value1)): | |
diff = value2[i] - value1[i] | |
if diff > 0: | |
title = "CPU" + str(i) + " - " + key | |
diff_array.append((title, diff)) | |
diff_array = sorted(diff_array, key=lambda x: x[1], reverse=True) | |
for title, value in diff_array[:30]: | |
print(title, value) | |
if __name__ == "__main__": | |
while True: | |
d1 = get_interrupts_dict() | |
time.sleep(2) | |
d2 = get_interrupts_dict() | |
print("=" * 100) | |
show_dict_diff_values(d1, d2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment