Skip to content

Commit

Permalink
rg_display: Track the number of spi transfers
Browse files Browse the repository at this point in the history
This is a test, I don't think it's worth adding to the main branch. But maybe...
  • Loading branch information
ducalex committed Mar 15, 2024
1 parent e4ee580 commit c742cae
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions components/retro-go/rg_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ static inline void spi_queue_transaction(const void *data, size_t length, uint32
{
RG_PANIC("display");
}
counters.spiTransfers++;
}

IRAM_ATTR
Expand Down
1 change: 1 addition & 0 deletions components/retro-go/rg_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ typedef struct
int32_t partFrames;
int64_t blockTime;
int64_t busyTime;
int64_t spiTransfers;
} rg_display_counters_t;

typedef struct
Expand Down
8 changes: 6 additions & 2 deletions components/retro-go/rg_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ typedef struct
{
int32_t totalFrames, fullFrames, partFrames, ticks;
int64_t busyTime, updateTime;
int64_t spiTransfers;
} counters_t;

typedef struct
Expand Down Expand Up @@ -140,6 +141,7 @@ static void update_statistics(void)
counters.busyTime = statistics.busyTime;
counters.ticks = statistics.ticks;
counters.updateTime = statistics.lastTick;
counters.spiTransfers = display.spiTransfers;

// We prefer to use the tick time for more accurate FPS
// but if we're not ticking, we need to use current time
Expand All @@ -164,6 +166,7 @@ static void update_statistics(void)
statistics.skippedFPS = (ticks - frames) / totalTimeSecs;
statistics.fullFPS = fullFrames / totalTimeSecs;
statistics.partialFPS = partFrames / totalTimeSecs;
statistics.spiTransfers = counters.spiTransfers - previous.spiTransfers;
}
statistics.uptime = rg_system_timer() / 1000000;

Expand Down Expand Up @@ -194,7 +197,7 @@ static void system_monitor_task(void *arg)
}

// Try to avoid complex conversions that could allocate, prefer rounding/ceiling if necessary.
rg_system_log(RG_LOG_DEBUG, NULL, "STACK:%d, HEAP:%d+%d (%d+%d), BUSY:%d%%, FPS:%d (%d+%d+%d), BATT:%d\n",
rg_system_log(RG_LOG_DEBUG, NULL, "STACK:%d, HEAP:%d+%d (%d+%d), BUSY:%d%%, FPS:%d (%d+%d+%d), BATT:%d SPI:%d\n",
statistics.freeStackMain,
statistics.freeMemoryInt / 1024,
statistics.freeMemoryExt / 1024,
Expand All @@ -205,7 +208,8 @@ static void system_monitor_task(void *arg)
(int)roundf(statistics.skippedFPS),
(int)roundf(statistics.partialFPS),
(int)roundf(statistics.fullFPS),
(int)roundf((battery.volts * 1000) ?: battery.level));
(int)roundf((battery.volts * 1000) ?: battery.level),
statistics.spiTransfers);

// Auto frameskip
if (statistics.ticks > app.tickRate * 2)
Expand Down
1 change: 1 addition & 0 deletions components/retro-go/rg_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ typedef struct
int64_t lastTick;
int ticks;
int uptime;
int spiTransfers;
int totalMemoryInt;
int totalMemoryExt;
int freeMemoryInt;
Expand Down

0 comments on commit c742cae

Please sign in to comment.