Wentong Wu | 8ccc04d | 2020-02-06 11:59:54 +0800 | [diff] [blame] | 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 | |
| 11 | void tracing_format_string(const char *str, ...) |
| 12 | { |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 13 | uint8_t *data; |
Wentong Wu | 8ccc04d | 2020-02-06 11:59:54 +0800 | [diff] [blame] | 14 | va_list args; |
| 15 | bool put_success; |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 16 | uint32_t length, tracing_buffer_size; |
Wentong Wu | 8ccc04d | 2020-02-06 11:59:54 +0800 | [diff] [blame] | 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 | |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 41 | void tracing_format_raw_data(uint8_t *data, uint32_t length) |
Wentong Wu | 8ccc04d | 2020-02-06 11:59:54 +0800 | [diff] [blame] | 42 | { |
| 43 | if (!is_tracing_enabled()) { |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | TRACING_LOCK(); |
| 48 | tracing_buffer_handle(data, length); |
| 49 | TRACING_UNLOCK(); |
| 50 | } |
| 51 | |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 52 | void tracing_format_data(tracing_data_t *tracing_data_array, uint32_t count) |
Wentong Wu | 8ccc04d | 2020-02-06 11:59:54 +0800 | [diff] [blame] | 53 | { |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 54 | uint8_t *data; |
Wentong Wu | 8ccc04d | 2020-02-06 11:59:54 +0800 | [diff] [blame] | 55 | bool put_success; |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 56 | uint32_t length, tracing_buffer_size; |
Wentong Wu | 8ccc04d | 2020-02-06 11:59:54 +0800 | [diff] [blame] | 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 | } |