Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmake/aurora_os.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add_library(aurora_os STATIC lib/dolphin/os/OSInit.cpp
lib/dolphin/os/OSAlloc.cpp
lib/dolphin/os/OSAddress.cpp
lib/dolphin/os/OSReport.cpp
lib/dolphin/os/OSStopwatch.cpp
lib/dolphin/AR.cpp)
add_library(aurora::os ALIAS aurora_os)
set_target_properties(aurora_os PROPERTIES FOLDER "aurora")
Expand Down
19 changes: 1 addition & 18 deletions include/dolphin/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extern "C" {
#include <dolphin/os/OSSemaphore.h>
#include <dolphin/os/OSUtf.h>
#include <dolphin/os/OSTimer.h>
#include <dolphin/os/OSStopwatch.h>

// private macro, maybe shouldn't be defined here?
#define OFFSET(addr, align) (((u32)(addr) & ((align)-1)))
Expand Down Expand Up @@ -156,24 +157,6 @@ typedef struct OSBootInfo_s {
u32 FSTMaxLength;
} OSBootInfo;

typedef struct OSStopwatch {
char* name;
u32 hits;
OSTime total;
OSTime min;
OSTime max;
OSTime last;
BOOL running;
u32 _padding;
} OSStopwatch;

void OSInitStopwatch(OSStopwatch* sw, char* name);
void OSStartStopwatch(OSStopwatch* sw);
void OSStopStopwatch(OSStopwatch* sw);
OSTime OSCheckStopwatch(OSStopwatch* sw);
void OSResetStopwatch(OSStopwatch* sw);
void OSDumpStopwatch(OSStopwatch* sw);

OSTick OSGetTick(void);
/**
* Get the current time, in ticks since GCN epoch (2000-01-01 00:00:00 UTC).
Expand Down
33 changes: 33 additions & 0 deletions include/dolphin/os/OSStopwatch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef _DOLPHIN_OSSTOPWATCH_H_
#define _DOLPHIN_OSSTOPWATCH_H_

#include <dolphin/types.h>
#include <dolphin/os/OSTime.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct OSStopwatch {
char* name;
u32 hits;
OSTime total;
OSTime min;
OSTime max;
OSTime last;
BOOL running;
u32 _padding;
} OSStopwatch;

void OSInitStopwatch(OSStopwatch* sw, char* name);
void OSStartStopwatch(OSStopwatch* sw);
void OSStopStopwatch(OSStopwatch* sw);
OSTime OSCheckStopwatch(OSStopwatch* sw);
void OSResetStopwatch(OSStopwatch* sw);
void OSDumpStopwatch(OSStopwatch* sw);

#ifdef __cplusplus
}
#endif

#endif // _DOLPHIN_OSSTOPWATCH_H_
51 changes: 51 additions & 0 deletions lib/dolphin/os/OSStopwatch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <dolphin/os.h>

void OSInitStopwatch(OSStopwatch* sw, char* name) {
sw->name = name;
sw->total = 0;
sw->hits = 0;
sw->min = 0x00000000FFFFFFFF;
sw->max = 0;
}

void OSStartStopwatch(OSStopwatch* sw) {
sw->running = TRUE;
sw->last = OSGetTime();
}

void OSStopStopwatch(OSStopwatch* sw) {
if (!sw->running) {
return;
}

const OSTime interval = OSGetTime() - sw->last;
sw->total += interval;
sw->running = FALSE;
sw->hits++;
if (sw->max < interval) {
sw->max = interval;
}
if (interval < sw->min) {
sw->min = interval;
}
}

OSTime OSCheckStopwatch(OSStopwatch* sw) {
OSTime currTotal = sw->total;
if (sw->running) {
currTotal += OSGetTime() - sw->last;
}
return currTotal;
}

void OSResetStopwatch(OSStopwatch* sw) { OSInitStopwatch(sw, sw->name); }

void OSDumpStopwatch(OSStopwatch* sw) {
OSReport("Stopwatch [%s]\t:\n", sw->name);
OSReport("\tTotal= %lld us\n", static_cast<long long>(OSTicksToMicroseconds(sw->total)));
OSReport("\tHits = %u \n", sw->hits);
OSReport("\tMin = %lld us\n", static_cast<long long>(OSTicksToMicroseconds(sw->min)));
OSReport("\tMax = %lld us\n", static_cast<long long>(OSTicksToMicroseconds(sw->max)));
const OSTime mean = sw->hits != 0 ? sw->total / sw->hits : 0;
OSReport("\tMean = %lld us\n", static_cast<long long>(OSTicksToMicroseconds(mean)));
}
Loading