| 1 |
/* |
| 2 |
* The MIT License (MIT) |
| 3 |
* |
| 4 |
* Copyright (c) 2016-2020 Philippe Proulx <[email protected]> |
| 5 |
* |
| 6 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 |
* of this software and associated documentation files (the "Software"), to deal |
| 8 |
* in the Software without restriction, including without limitation the rights |
| 9 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 |
* copies of the Software, and to permit persons to whom the Software is |
| 11 |
* furnished to do so, subject to the following conditions: |
| 12 |
* |
| 13 |
* The above copyright notice and this permission notice shall be included in |
| 14 |
* all copies or substantial portions of the Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 |
* THE SOFTWARE. |
| 23 |
*/ |
| 24 |
|
| 25 |
#include <stdio.h> |
| 26 |
#include <stdint.h> |
| 27 |
#include <stdlib.h> |
| 28 |
#include <time.h> |
| 29 |
|
| 30 |
#include "barectf-platform-linux-fs.h" |
| 31 |
#include "barectf.h" |
| 32 |
|
| 33 |
enum state_t { |
| 34 |
NEW, |
| 35 |
TERMINATED, |
| 36 |
READY, |
| 37 |
RUNNING, |
| 38 |
WAITING, |
| 39 |
}; |
| 40 |
|
| 41 |
static void trace_stuff(struct barectf_default_ctx * const ctx, const int argc, |
| 42 |
const char * const argv[]) |
| 43 |
{ |
| 44 |
int i; |
| 45 |
const char *str; |
| 46 |
|
| 47 |
/* Record 40,000 events */ |
| 48 |
for (i = 0; i < 5000; ++i) { |
| 49 |
barectf_trace_simple_uint32(ctx, i * 1500); |
| 50 |
barectf_trace_simple_int16(ctx, -i * 2); |
| 51 |
barectf_trace_simple_float(ctx, (float) i / 1.23); |
| 52 |
|
| 53 |
if (argc > 0) { |
| 54 |
str = argv[i % argc]; |
| 55 |
} else { |
| 56 |
str = "hello there!"; |
| 57 |
} |
| 58 |
|
| 59 |
barectf_trace_simple_string(ctx, str); |
| 60 |
barectf_trace_context_no_payload(ctx, i, "ctx"); |
| 61 |
barectf_trace_simple_enum(ctx, RUNNING); |
| 62 |
barectf_trace_a_few_fields(ctx, -1, 301, -3.14159, str, NEW); |
| 63 |
barectf_trace_bit_packed_integers(ctx, 1, -1, 3, -2, 2, 7, 23, |
| 64 |
-55, 232); |
| 65 |
barectf_trace_no_context_no_payload(ctx); |
| 66 |
barectf_trace_simple_enum(ctx, TERMINATED); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
int main(const int argc, const char * const argv[]) |
| 71 |
{ |
| 72 |
struct barectf_platform_linux_fs_ctx *platform_ctx; |
| 73 |
int exit_status = 0; |
| 74 |
|
| 75 |
/* Initialize platform */ |
| 76 |
platform_ctx = barectf_platform_linux_fs_init(512, "trace/stream", |
| 77 |
1, 2, 7); |
| 78 |
|
| 79 |
if (!platform_ctx) { |
| 80 |
fprintf(stderr, |
| 81 |
"Error: failed to initialize Linux FS platform.\n"); |
| 82 |
exit_status = 1; |
| 83 |
goto end; |
| 84 |
} |
| 85 |
|
| 86 |
/* Trace stuff (will create/write packets as it executes) */ |
| 87 |
trace_stuff(barectf_platform_linux_fs_get_barectf_ctx(platform_ctx), |
| 88 |
argc, argv); |
| 89 |
|
| 90 |
/* Finalize platform */ |
| 91 |
barectf_platform_linux_fs_fini(platform_ctx); |
| 92 |
|
| 93 |
end: |
| 94 |
return exit_status; |
| 95 |
} |