update to upcoming timer API of gint 2.1

This commit is contained in:
Lephenixnoir 2020-06-20 23:20:20 +02:00
parent f79e6d2cc6
commit 8b074a4e58
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
3 changed files with 23 additions and 21 deletions

View File

@ -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
*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
of timers 0, 1 and 2, which are the only one precise enough to do this job. You
can use any timer which you are not already using for something else.
libprof also needs one of gint's timer to actually measure time; it selects one
of TMU0, TMU1 and TMU2 which are the only ones suited for this precise job. The
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
/* Initialize libprof for 13 contexts using timer 0 */
prof_init(13, 0);
/* Initialize libprof for 13 contexts (automatically selects a timer) */
prof_init(13);
```
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:
```c
prof_init(PROFCTX_COUNT, 0);
prof_init(PROFCTX_COUNT);
```
Then you can use context names instead of numbers:

View File

@ -17,16 +17,19 @@ uint32_t volatile *prof_tcnt = NULL;
static int prof_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);
prof_elapsed = malloc(n * sizeof *prof_elapsed);
/* Get a TMU with the exact constant 0xffffffff */
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 || status < 0)
if(!prof_rec || !prof_elapsed || timer == -1)
{
prof_quit();
return 1;

View File

@ -17,14 +17,13 @@
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.
Also starts a timer to count time. The timer ID must be set to 0, 1 or 2 as
the standard TMU is the most tweakable and precise. libprof automatically
selects an accurate timer configuration.
Also starts a timer to count time. libprof automatically selects a TMU and
tries to use TMU2 before TMU1 before TMU0 so that high-priority interrupts
remain available, and sets an accurate clock configuration.
@n Number of different contexts (functions) that will be measured
@timer Timer ID, see <gint/timer.h> to select one
Returns non-zero if a setup error occurs. */
int prof_init(int n, int timer);
@context_count Number of different contexts that will be measured
Returns non-zero if a setup error occurs or no timer is available. */
int prof_init(int context_count);
/* prof_quit(): Free the profiler's data and timer */
void prof_quit(void);