1 /*
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 
tracing_format_string(const char * str,...)11 void tracing_format_string(const char *str, ...)
12 {
13 	va_list args;
14 	bool put_success, before_put_is_empty;
15 
16 	if (!is_tracing_enabled() || is_tracing_thread()) {
17 		return;
18 	}
19 
20 	va_start(args, str);
21 
22 	TRACING_LOCK();
23 	before_put_is_empty = tracing_buffer_is_empty();
24 	put_success = tracing_format_string_put(str, args);
25 	TRACING_UNLOCK();
26 
27 	va_end(args);
28 
29 	if (put_success) {
30 		tracing_trigger_output(before_put_is_empty);
31 	} else {
32 		tracing_packet_drop_handle();
33 	}
34 }
35 
tracing_format_raw_data(uint8_t * data,uint32_t length)36 void tracing_format_raw_data(uint8_t *data, uint32_t length)
37 {
38 	bool put_success, before_put_is_empty;
39 
40 	if (!is_tracing_enabled() || is_tracing_thread()) {
41 		return;
42 	}
43 
44 	TRACING_LOCK();
45 	before_put_is_empty = tracing_buffer_is_empty();
46 	put_success = tracing_format_raw_data_put(data, length);
47 	TRACING_UNLOCK();
48 
49 	if (put_success) {
50 		tracing_trigger_output(before_put_is_empty);
51 	} else {
52 		tracing_packet_drop_handle();
53 	}
54 }
55 
tracing_format_data(tracing_data_t * tracing_data_array,uint32_t count)56 void tracing_format_data(tracing_data_t *tracing_data_array, uint32_t count)
57 {
58 	bool put_success, before_put_is_empty;
59 
60 	if (!is_tracing_enabled() || is_tracing_thread()) {
61 		return;
62 	}
63 
64 	TRACING_LOCK();
65 	before_put_is_empty = tracing_buffer_is_empty();
66 	put_success = tracing_format_data_put(tracing_data_array, count);
67 	TRACING_UNLOCK();
68 
69 	if (put_success) {
70 		tracing_trigger_output(before_put_is_empty);
71 	} else {
72 		tracing_packet_drop_handle();
73 	}
74 }
75