blob: 253d3dbd8652af2592df5200ed1e45e6e4e6c040 [file] [log] [blame]
Wentong Wu8ccc04d2020-02-06 11:59:54 +08001/*
2 * Copyright (c) 2019 Intel corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#include <tracing_core.h>
8#include <tracing_buffer.h>
9#include <tracing_format_common.h>
10
11void tracing_format_string(const char *str, ...)
12{
Kumar Galaa1b77fd2020-05-27 11:26:57 -050013 uint8_t *data;
Wentong Wu8ccc04d2020-02-06 11:59:54 +080014 va_list args;
15 bool put_success;
Kumar Galaa1b77fd2020-05-27 11:26:57 -050016 uint32_t length, tracing_buffer_size;
Wentong Wu8ccc04d2020-02-06 11:59:54 +080017
18 if (!is_tracing_enabled()) {
19 return;
20 }
21
22 tracing_buffer_size = tracing_buffer_capacity_get();
23
24 va_start(args, str);
25
26 TRACING_LOCK();
27 put_success = tracing_format_string_put(str, args);
28
29 if (put_success) {
30 length = tracing_buffer_get_claim(&data, tracing_buffer_size);
31 tracing_buffer_handle(data, length);
32 tracing_buffer_get_finish(length);
33 } else {
34 tracing_packet_drop_handle();
35 }
36 TRACING_UNLOCK();
37
38 va_end(args);
39}
40
Kumar Galaa1b77fd2020-05-27 11:26:57 -050041void tracing_format_raw_data(uint8_t *data, uint32_t length)
Wentong Wu8ccc04d2020-02-06 11:59:54 +080042{
43 if (!is_tracing_enabled()) {
44 return;
45 }
46
47 TRACING_LOCK();
48 tracing_buffer_handle(data, length);
49 TRACING_UNLOCK();
50}
51
Kumar Galaa1b77fd2020-05-27 11:26:57 -050052void tracing_format_data(tracing_data_t *tracing_data_array, uint32_t count)
Wentong Wu8ccc04d2020-02-06 11:59:54 +080053{
Kumar Galaa1b77fd2020-05-27 11:26:57 -050054 uint8_t *data;
Wentong Wu8ccc04d2020-02-06 11:59:54 +080055 bool put_success;
Kumar Galaa1b77fd2020-05-27 11:26:57 -050056 uint32_t length, tracing_buffer_size;
Wentong Wu8ccc04d2020-02-06 11:59:54 +080057
58 if (!is_tracing_enabled()) {
59 return;
60 }
61
62 tracing_buffer_size = tracing_buffer_capacity_get();
63
64 TRACING_LOCK();
65 put_success = tracing_format_data_put(tracing_data_array, count);
66
67 if (put_success) {
68 length = tracing_buffer_get_claim(&data, tracing_buffer_size);
69 tracing_buffer_handle(data, length);
70 tracing_buffer_get_finish(length);
71 } else {
72 tracing_packet_drop_handle();
73 }
74 TRACING_UNLOCK();
75}