Add TickCounter for measuring performance
This commit is contained in:
parent
97d01a7325
commit
991eb2357b
@ -3,6 +3,7 @@
|
|||||||
* @brief OS related stuff.
|
* @brief OS related stuff.
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "svc.h"
|
||||||
|
|
||||||
/// Packs a system version from its components.
|
/// Packs a system version from its components.
|
||||||
#define SYSTEM_VERSION(major, minor, revision) \
|
#define SYSTEM_VERSION(major, minor, revision) \
|
||||||
@ -26,6 +27,13 @@ typedef enum
|
|||||||
MEMREGION_BASE = 3, ///< BASE memory.
|
MEMREGION_BASE = 3, ///< BASE memory.
|
||||||
} MemRegion;
|
} MemRegion;
|
||||||
|
|
||||||
|
/// Tick counter.
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u64 elapsed; ///< Elapsed CPU ticks between measurements.
|
||||||
|
u64 reference; ///< Point in time used as reference.
|
||||||
|
} TickCounter;
|
||||||
|
|
||||||
/// OS_VersionBin. Format of the system version: "<major>.<minor>.<build>-<nupver><region>"
|
/// OS_VersionBin. Format of the system version: "<major>.<minor>.<build>-<nupver><region>"
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@ -124,6 +132,33 @@ static inline s64 osGetMemRegionFree(MemRegion region)
|
|||||||
*/
|
*/
|
||||||
u64 osGetTime(void);
|
u64 osGetTime(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Starts a tick counter.
|
||||||
|
* @param cnt The tick counter.
|
||||||
|
*/
|
||||||
|
static inline void osTickCounterStart(TickCounter* cnt)
|
||||||
|
{
|
||||||
|
cnt->reference = svcGetSystemTick();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Updates the elapsed time in a tick counter.
|
||||||
|
* @param cnt The tick counter.
|
||||||
|
*/
|
||||||
|
static inline void osTickCounterUpdate(TickCounter* cnt)
|
||||||
|
{
|
||||||
|
u64 now = svcGetSystemTick();
|
||||||
|
cnt->elapsed = now - cnt->reference;
|
||||||
|
cnt->reference = now;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reads the elapsed time in a tick counter.
|
||||||
|
* @param cnt The tick counter.
|
||||||
|
* @return The number of milliseconds elapsed.
|
||||||
|
*/
|
||||||
|
double osTickCounterRead(TickCounter* cnt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gets the current Wifi signal strength.
|
* @brief Gets the current Wifi signal strength.
|
||||||
* @return The current Wifi signal strength.
|
* @return The current Wifi signal strength.
|
||||||
|
@ -115,6 +115,12 @@ u64 osGetTime(void) {
|
|||||||
return dt.date_time + (u32)(u64_to_double(delta)/TICKS_PER_MSEC);
|
return dt.date_time + (u32)(u64_to_double(delta)/TICKS_PER_MSEC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
double osTickCounterRead(TickCounter* cnt) {
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
return u64_to_double(cnt->elapsed) / TICKS_PER_MSEC;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
const char* osStrError(u32 error) {
|
const char* osStrError(u32 error) {
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user