mirror of
https://git.planet-casio.com/Lephenixnoir/libprof.git
synced 2024-12-28 04:23:41 +01:00
update to upcoming timer API of gint 2.1
This commit is contained in:
parent
f79e6d2cc6
commit
8b074a4e58
3 changed files with 23 additions and 21 deletions
14
README.md
14
README.md
|
@ -47,15 +47,15 @@ For each function you want to time, libprof will create a counter. At the start
|
||||||
of the program, you need to specify how many functions (libprof calls them
|
of the program, you need to specify how many functions (libprof calls them
|
||||||
*contexts*) you will be timing, so that libprof can allocate enough memory.
|
*contexts*) you will be timing, so that libprof can allocate enough memory.
|
||||||
|
|
||||||
libprof also needs one of gint's timer to actually measure time; it must be one
|
libprof also needs one of gint's timer to actually measure time; it selects one
|
||||||
of timers 0, 1 and 2, which are the only one precise enough to do this job. You
|
of TMU0, TMU1 and TMU2 which are the only ones suited for this precise job. The
|
||||||
can use any timer which you are not already using for something else.
|
available timer with the smallest interrupt priority is selected.
|
||||||
|
|
||||||
These settings are specified with the `prof_init()` function.
|
This initialization happens in the `prof_init()` function.
|
||||||
|
|
||||||
```c
|
```c
|
||||||
/* Initialize libprof for 13 contexts using timer 0 */
|
/* Initialize libprof for 13 contexts (automatically selects a timer) */
|
||||||
prof_init(13, 0);
|
prof_init(13);
|
||||||
```
|
```
|
||||||
|
|
||||||
You can then measure the execution time of a function by calling `prof_enter()`
|
You can then measure the execution time of a function by calling `prof_enter()`
|
||||||
|
@ -121,7 +121,7 @@ one each time. So for example here `PROFCTX_FUNCTION2` is equal to `1` and
|
||||||
the number of contexts, which makes it simple to initialize the library:
|
the number of contexts, which makes it simple to initialize the library:
|
||||||
|
|
||||||
```c
|
```c
|
||||||
prof_init(PROFCTX_COUNT, 0);
|
prof_init(PROFCTX_COUNT);
|
||||||
```
|
```
|
||||||
|
|
||||||
Then you can use context names instead of numbers:
|
Then you can use context names instead of numbers:
|
||||||
|
|
17
libprof.c
17
libprof.c
|
@ -17,16 +17,19 @@ uint32_t volatile *prof_tcnt = NULL;
|
||||||
static int prof_timer;
|
static int prof_timer;
|
||||||
|
|
||||||
/* prof_init(): Initialize the profiler's data and timer */
|
/* prof_init(): Initialize the profiler's data and timer */
|
||||||
int prof_init(int n, int timer)
|
int prof_init(int context_count)
|
||||||
{
|
{
|
||||||
if((unsigned)timer >= 3) return 1;
|
prof_rec = malloc(context_count * sizeof *prof_rec);
|
||||||
|
prof_elapsed = malloc(context_count * sizeof *prof_elapsed);
|
||||||
|
|
||||||
prof_rec = malloc(n * sizeof *prof_rec);
|
/* Get a TMU with the exact constant 0xffffffff */
|
||||||
prof_elapsed = malloc(n * sizeof *prof_elapsed);
|
int timer = -1;
|
||||||
|
for(int t = 2; t >= 0 && timer == -1; t--)
|
||||||
|
{
|
||||||
|
timer = timer_setup(t, 0xffffffff, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
int status = timer_setup(timer, 0xffffffff, timer_Po_4, NULL, NULL);
|
if(!prof_rec || !prof_elapsed || timer == -1)
|
||||||
|
|
||||||
if(!prof_rec || !prof_elapsed || status < 0)
|
|
||||||
{
|
{
|
||||||
prof_quit();
|
prof_quit();
|
||||||
return 1;
|
return 1;
|
||||||
|
|
13
libprof.h
13
libprof.h
|
@ -17,14 +17,13 @@
|
||||||
hold all the context IDs. Context IDs should be numbered from 0 to [n-1];
|
hold all the context IDs. Context IDs should be numbered from 0 to [n-1];
|
||||||
due to speed requirements array bounds are not checked so be careful.
|
due to speed requirements array bounds are not checked so be careful.
|
||||||
|
|
||||||
Also starts a timer to count time. The timer ID must be set to 0, 1 or 2 as
|
Also starts a timer to count time. libprof automatically selects a TMU and
|
||||||
the standard TMU is the most tweakable and precise. libprof automatically
|
tries to use TMU2 before TMU1 before TMU0 so that high-priority interrupts
|
||||||
selects an accurate timer configuration.
|
remain available, and sets an accurate clock configuration.
|
||||||
|
|
||||||
@n Number of different contexts (functions) that will be measured
|
@context_count Number of different contexts that will be measured
|
||||||
@timer Timer ID, see <gint/timer.h> to select one
|
Returns non-zero if a setup error occurs or no timer is available. */
|
||||||
Returns non-zero if a setup error occurs. */
|
int prof_init(int context_count);
|
||||||
int prof_init(int n, int timer);
|
|
||||||
|
|
||||||
/* prof_quit(): Free the profiler's data and timer */
|
/* prof_quit(): Free the profiler's data and timer */
|
||||||
void prof_quit(void);
|
void prof_quit(void);
|
||||||
|
|
Loading…
Reference in a new issue