tracing_format_sync.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) 2019 Intel corporation
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <tracing_core.h>
  7. #include <tracing_buffer.h>
  8. #include <tracing_format_common.h>
  9. void tracing_format_string(const char *str, ...)
  10. {
  11. uint8_t *data;
  12. va_list args;
  13. bool put_success;
  14. uint32_t length, tracing_buffer_size;
  15. if (!is_tracing_enabled()) {
  16. return;
  17. }
  18. tracing_buffer_size = tracing_buffer_capacity_get();
  19. va_start(args, str);
  20. TRACING_LOCK();
  21. put_success = tracing_format_string_put(str, args);
  22. if (put_success) {
  23. length = tracing_buffer_get_claim(&data, tracing_buffer_size);
  24. tracing_buffer_handle(data, length);
  25. tracing_buffer_get_finish(length);
  26. } else {
  27. tracing_packet_drop_handle();
  28. }
  29. TRACING_UNLOCK();
  30. va_end(args);
  31. }
  32. void tracing_format_raw_data(uint8_t *data, uint32_t length)
  33. {
  34. if (!is_tracing_enabled()) {
  35. return;
  36. }
  37. TRACING_LOCK();
  38. tracing_buffer_handle(data, length);
  39. TRACING_UNLOCK();
  40. }
  41. void tracing_format_data(tracing_data_t *tracing_data_array, uint32_t count)
  42. {
  43. uint8_t *data;
  44. bool put_success;
  45. uint32_t length, tracing_buffer_size;
  46. if (!is_tracing_enabled()) {
  47. return;
  48. }
  49. tracing_buffer_size = tracing_buffer_capacity_get();
  50. TRACING_LOCK();
  51. put_success = tracing_format_data_put(tracing_data_array, count);
  52. if (put_success) {
  53. length = tracing_buffer_get_claim(&data, tracing_buffer_size);
  54. tracing_buffer_handle(data, length);
  55. tracing_buffer_get_finish(length);
  56. } else {
  57. tracing_packet_drop_handle();
  58. }
  59. TRACING_UNLOCK();
  60. }