Getting performance counters via Python


I’m new to the HiFive 1 and I need to execute some C scripts through Python and obtain their performance counters, I can execute them through the console line using the freedom-e-sdk and using the metal.h library I can obtain these but within the same script. But I need to do the process via Python. Is there a way to get a result from the board to the code in Python?

I imagine you mean the host Python, not a e.g MicroPython running on the board itself? And you want to communicate with something running on the board?

If so you’d generally communicate through the USB UART as that’s what is available anyway, and define some protocol over it. E.g. for a simple text-based, line-based request-reply protocol:

import serial

# Adapt this as needed-

ser = serial.Serial(port=UART, baudrate=BAUDRATE)
line = ser.readline()
… # parse result line

On the board

while (true) {
    char buffer[BUFFERSIZE];
    fgets(buffer, BUFFERSIZE, stdin);
    … # command dispatch
    printf("stats: %d %d %d %d\n", …); # print values of perf counters

Other options would be raw binary, or SLIP which is fairly common for serial protocols as it’s self-synchronizing. But this is testable using a terminal program.

(Alternatively, I realize, you could periodically report statistics from the program running on the board without any kind of interactive protocol, and parse those; it depends on the kind of synchronization you need between host and board)

1 Like