-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmem.h
More file actions
48 lines (42 loc) · 1.24 KB
/
Copy pathmem.h
File metadata and controls
48 lines (42 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef CSYNTH_MEM_H
#define CSYNTH_MEM_H
#include <stdio.h>
#include "../../core/func.h"
#include "../../core/gen.h"
#include "../../event/state_event.h"
#include "../../util/error.h"
/** @see mem_create */
typedef struct
{
/** @brief Time since last broadcast. */
double time;
} MemContext;
static double mem_eval(__U size_t count, Gen **args, Eval *eval, __U void *context_)
{
#ifdef ALLOC_TRACE
MemContext *context = (MemContext *)context_;
if (context->time >= 1.0 && eval != NULL)
{
AllocStat stat = alloc_stat();
state_event_broadcast(eval->wall_time, StateEventKeyTypeLabel, "alloc", StateEventValueTypeSize, &stat.alloc_size);
state_event_broadcast(eval->wall_time, StateEventKeyTypeLabel, "free", StateEventValueTypeSize, &stat.free_size);
context->time = 0;
}
context->time += eval->wall_tick;
#endif
return gen_eval(args[0], eval);
}
/**
* @brief Create a function that displays memory usage.
*
* @param input Input signal.
* @return Func* Memory debug function.
*/
Func *mem_create(Func *input)
{
MemContext initial = {
.time = 1.0,
};
return func_create(NULL, mem_eval, NULL, NULL, sizeof(MemContext), &initial, FuncFlagNone, input);
}
#endif // CSYNTH_MEM_H