Skip to content

Commit

Permalink
remove perf counter
Browse files Browse the repository at this point in the history
  • Loading branch information
bkleiner committed Oct 29, 2023
1 parent 2f9e366 commit 56b98d9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 122 deletions.
96 changes: 3 additions & 93 deletions src/core/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,105 +7,21 @@

#ifdef DEBUG

#define SKIP_LOOPS 20000

perf_counter_t perf_counters[PERF_COUNTER_MAX];

static const char *perf_counter_names[PERF_COUNTER_MAX] = {
"PERF_COUNTER_TOTAL",
"PERF_COUNTER_GYRO",
"PERF_COUNTER_CONTROL",
"PERF_COUNTER_RX",
"PERF_COUNTER_OSD",
"PERF_COUNTER_MISC",
"PERF_COUNTER_BLACKBOX",
"PERF_COUNTER_DEBUG",
};

static uint32_t perf_counter_start_time[PERF_COUNTER_MAX];
static uint32_t loop_counter = 0;

void perf_counter_init() {
for (uint32_t i = 0; i < PERF_COUNTER_MAX; i++) {
perf_counters[i].min = UINT32_MAX;
perf_counters[i].max = 0;
perf_counters[i].current = 0;
}
}

void perf_counter_start(perf_counters_t counter) {
perf_counter_start_time[counter] = time_cycles();
}

void perf_counter_end(perf_counters_t counter) {
if (loop_counter < SKIP_LOOPS) {
return;
}

uint32_t delta = time_cycles() - perf_counter_start_time[counter];

if (delta > perf_counters[counter].max) {
perf_counters[counter].max = delta;
}

if (delta < perf_counters[counter].min) {
perf_counters[counter].min = delta;
}

perf_counters[counter].current = delta;
}

void perf_counter_update() {
loop_counter++;
}

#define ENCODE_CYCLES(val) \
{ \
const uint32_t us = (val) / (SYS_CLOCK_FREQ_HZ / 1000000); \
CBOR_CHECK_ERROR(res = cbor_encode_uint32_t(enc, &us)); \
}

cbor_result_t cbor_encode_perf_counters(cbor_value_t *enc) {
CBOR_CHECK_ERROR(cbor_result_t res = cbor_encode_array_indefinite(enc));

for (uint32_t i = 0; i < PERF_COUNTER_MAX; i++) {
CBOR_CHECK_ERROR(res = cbor_encode_map_indefinite(enc));

CBOR_CHECK_ERROR(res = cbor_encode_str(enc, "name"));
CBOR_CHECK_ERROR(res = cbor_encode_str(enc, perf_counter_names[i]));

CBOR_CHECK_ERROR(res = cbor_encode_str(enc, "min"));
ENCODE_CYCLES(perf_counters[i].min)

CBOR_CHECK_ERROR(res = cbor_encode_str(enc, "max"));
ENCODE_CYCLES(perf_counters[i].max)

CBOR_CHECK_ERROR(res = cbor_encode_str(enc, "current"));
ENCODE_CYCLES(perf_counters[i].current)

CBOR_CHECK_ERROR(res = cbor_encode_end_indefinite(enc));
}

CBOR_CHECK_ERROR(res = cbor_encode_end_indefinite(enc));

return res;
}

void debug_pin_init() {
#if defined(DEBUG_PIN0) || defined(DEBUG_PIN1)
gpio_config_t gpio_init;
gpio_init.mode = GPIO_OUTPUT;
gpio_init.drive =GPIO_DRIVE_HIGH;
gpio_init.drive = GPIO_DRIVE_HIGH;
gpio_init.output = GPIO_PUSHPULL;
gpio_init.pull = GPIO_NO_PULL;
#endif

#ifdef DEBUG_PIN0
gpio_pin_init( DEBUG_PIN0, gpio_init);
gpio_pin_init(DEBUG_PIN0, gpio_init);
#endif

#ifdef DEBUG_PIN1
gpio_pin_init( DEBUG_PIN1, gpio_init);
gpio_pin_init(DEBUG_PIN1, gpio_init);
#endif
}

Expand Down Expand Up @@ -153,12 +69,6 @@ void debug_pin_toggle(uint8_t index) {

#else

void perf_counter_start(perf_counters_t counter) {}
void perf_counter_end(perf_counters_t counter) {}

void perf_counter_init() {}
void perf_counter_update() {}

void debug_pin_init() {}

void debug_pin_enable(uint8_t index) {}
Expand Down
29 changes: 0 additions & 29 deletions src/core/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,6 @@

#include "io/usb_configurator.h"

typedef enum {
PERF_COUNTER_TOTAL,
PERF_COUNTER_GYRO,
PERF_COUNTER_CONTROL,
PERF_COUNTER_RX,
PERF_COUNTER_OSD,
PERF_COUNTER_MISC,
PERF_COUNTER_BLACKBOX,
PERF_COUNTER_DEBUG,

PERF_COUNTER_MAX
} __attribute__((__packed__)) perf_counters_t;

typedef struct {
uint32_t min;
uint32_t max;
uint32_t current;
} perf_counter_t;

extern perf_counter_t perf_counters[PERF_COUNTER_MAX];

void perf_counter_start(perf_counters_t counter);
void perf_counter_end(perf_counters_t counter);

void perf_counter_init();
void perf_counter_update();

cbor_result_t cbor_encode_perf_counters(cbor_value_t *enc);

void debug_pin_init();

void debug_pin_enable(uint8_t index);
Expand Down

0 comments on commit 56b98d9

Please sign in to comment.