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 	uint8_t *data;
14 	va_list args;
15 	bool put_success;
16 	uint32_t length, tracing_buffer_size;
17 
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 
tracing_format_raw_data(uint8_t * data,uint32_t length)41 void tracing_format_raw_data(uint8_t *data, uint32_t length)
42 {
43 	if (!is_tracing_enabled()) {
44 		return;
45 	}
46 
47 	TRACING_LOCK();
48 	tracing_buffer_handle(data, length);
49 	TRACING_UNLOCK();
50 }
51 
tracing_format_data(tracing_data_t * tracing_data_array,uint32_t count)52 void tracing_format_data(tracing_data_t *tracing_data_array, uint32_t count)
53 {
54 	uint8_t *data;
55 	bool put_success;
56 	uint32_t length, tracing_buffer_size;
57 
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 }
76