I’m trying to get the performance counters of a program (C application) running on the SiFive board with a Python script and then write it into a text file, but I get a lot of wrong data. The program running on the board is:
struct metal_cpu *cpu;
cpu = metal_cpu_get(metal_cpu_get_current_hartid());
if (metal_hpm_init(cpu) != 0) {
return 1;
}
// a lot of stuff
// .
// .
// .
cnt = metal_hpm_read_counter(cpu, METAL_HPM_CYCLE);
printf("pc %d", cnt);
And I’m doing this on Python:
flag = 1
while flag:
temp = ser.readline()
temp_decode = temp.decode(encoding="UTF-8")
if temp_decode == "\n":
flag = 0
f = open("results.txt", "a")
f.write(temp_decode)
f.close()
And when I run the program I get this on the results.txt:
How can I get the correct data? e.g. pc 43000 into the text file.