|
53 | 53 | extern void *lj_ff_tostring(void);
|
54 | 54 | extern void *lj_fff_res1(void);
|
55 | 55 |
|
56 |
| -/* Sysprof "/dev/null" stream helpers. {{{ */ |
| 56 | +/* Sysprof dummy stream helpers. {{{ */ |
57 | 57 |
|
58 | 58 | /*
|
59 | 59 | * Yep, 8Mb. Tuned in order not to bother the platform with too
|
60 | 60 | * often flushes.
|
61 | 61 | */
|
62 | 62 | #define STREAM_BUFFER_SIZE (8 * 1024 * 1024)
|
63 |
| -#define DEVNULL -1 |
64 | 63 |
|
65 |
| -struct devnull_ctx { |
66 |
| - /* |
67 |
| - * XXX: Dummy file descriptor to be used as "/dev/null" |
68 |
| - * context indicator in writer and on_stop callback. |
69 |
| - */ |
70 |
| - int fd; |
| 64 | +struct dummy_ctx { |
71 | 65 | /* Buffer for data recorded by sysprof. */
|
72 | 66 | uint8_t buf[STREAM_BUFFER_SIZE];
|
73 | 67 | };
|
74 | 68 |
|
| 69 | +static struct dummy_ctx context; |
| 70 | + |
75 | 71 | static int stream_new(struct luam_Sysprof_Options *options)
|
76 | 72 | {
|
77 |
| - struct devnull_ctx *ctx = calloc(1, sizeof(struct devnull_ctx)); |
78 |
| - if (ctx == NULL) |
79 |
| - return PROFILE_ERRIO; |
80 |
| - |
81 |
| - /* Set "/dev/null" context indicator. */ |
82 |
| - ctx->fd = DEVNULL; |
83 |
| - options->ctx = ctx; |
84 |
| - options->buf = ctx->buf; |
| 73 | + /* Set dummy context. */ |
| 74 | + options->ctx = &context; |
| 75 | + options->buf = (uint8_t *)&context.buf; |
85 | 76 | options->len = STREAM_BUFFER_SIZE;
|
86 | 77 |
|
87 | 78 | return PROFILE_SUCCESS;
|
88 | 79 | }
|
89 | 80 |
|
90 | 81 | static int stream_delete(void *rawctx, uint8_t *buf)
|
91 | 82 | {
|
92 |
| - struct devnull_ctx *ctx = rawctx; |
93 |
| - assert(ctx->fd == DEVNULL); |
94 |
| - free(ctx); |
| 83 | + assert(rawctx == &context); |
| 84 | + /* XXX: No need to release context memory. Just return. */ |
95 | 85 | return PROFILE_SUCCESS;
|
96 | 86 | }
|
97 | 87 |
|
98 | 88 | static size_t stream_writer(const void **buf_addr, size_t len, void *rawctx)
|
99 | 89 | {
|
100 |
| - struct devnull_ctx *ctx = rawctx; |
101 |
| - assert(ctx->fd == DEVNULL); |
| 90 | + assert(rawctx == &context); |
102 | 91 | /* Do nothing, just return back to the profiler. */
|
103 | 92 | return STREAM_BUFFER_SIZE;
|
104 | 93 | }
|
105 | 94 |
|
106 |
| -/* }}} Sysprof "/dev/null" stream helpers. */ |
| 95 | +/* }}} Sysprof dummy stream helpers. */ |
107 | 96 |
|
108 | 97 | static int tracee(const char *luacode)
|
109 | 98 | {
|
|
0 commit comments