Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8bc88b19 authored by Jack He's avatar Jack He
Browse files

Use same timestamp for on-disk BT Snoop Log and in-memory BT Snooz Log

* Logcat uses gettimeofday for its timestamp, the same as on-disk BT
  Snoop log
* Although in-memory BT Snooz Log uses the same method to get time, it
  is calling it separately, resulting in mismatch between timestamps of
  two snoop logs
* This CL let them uses the same timestamp_us value and put the function
  definition to libosi
* Note that preserved on-disk BT Snoop logs timestamp postfix at
      btsnoop_hci_<timestamp>.log
  will be changed to microsecond since epoch at current device timezone
  instead of the shifted BT Snoop timestamp value
* New unit tests for gettimeofday

Bug: 35113514
Test: Make, unit tests, run BT activities and check both snoop logs
Change-Id: I5b3f87bc523b272ced2c69a4595d0e0cbe29bcb3
parent 983702e6
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -23,8 +23,3 @@
// Debug API

void btif_debug_init(void);

// Debug helpers

// Timestamp in us
uint64_t btif_debug_ts(void);
+0 −7
Original line number Diff line number Diff line
@@ -28,10 +28,3 @@ void btif_debug_init(void) {
  btif_debug_btsnoop_init();
#endif
}

// TODO: Find a better place for this to enable additional re-use
uint64_t btif_debug_ts(void) {
  struct timeval tv;
  gettimeofday(&tv, NULL);
  return (tv.tv_sec * 1000000LL) + tv.tv_usec;
}
+5 −6
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include "hci/include/btsnoop_mem.h"
#include "include/bt_target.h"
#include "osi/include/ringbuffer.h"
#include "osi/include/time.h"

#define REDUCE_HCI_TYPE_TO_SIGNIFICANT_BITS(type) ((type) >> 8)

@@ -50,7 +51,7 @@ static size_t btsnoop_calculate_packet_length(uint16_t type,
                                              size_t length);

static void btsnoop_cb(const uint16_t type, const uint8_t* data,
                       const size_t length) {
                       const size_t length, const uint64_t timestamp_us) {
  btsnooz_header_t header;

  size_t included_length = btsnoop_calculate_packet_length(type, data, length);
@@ -67,14 +68,12 @@ static void btsnoop_cb(const uint16_t type, const uint8_t* data,
  }

  // Insert data

  const uint64_t now = btif_debug_ts();

  header.type = REDUCE_HCI_TYPE_TO_SIGNIFICANT_BITS(type);
  header.length = included_length + 1;  // +1 for type byte
  header.packet_length = length + 1;    // +1 for type byte.
  header.delta_time_ms = last_timestamp_ms ? now - last_timestamp_ms : 0;
  last_timestamp_ms = now;
  header.delta_time_ms =
      last_timestamp_ms ? timestamp_us - last_timestamp_ms : 0;
  last_timestamp_ms = timestamp_us;

  ringbuffer_insert(buffer, (uint8_t*)&header, sizeof(btsnooz_header_t));
  ringbuffer_insert(buffer, data, included_length);
+2 −2
Original line number Diff line number Diff line
@@ -21,8 +21,8 @@
#include <time.h>

#include "btcore/include/bdaddr.h"
#include "btif/include/btif_debug.h"
#include "btif/include/btif_debug_conn.h"
#include "osi/include/time.h"

#define NUM_CONNECTION_EVENTS 16
#define TEMP_BUFFER_SIZE 30
@@ -70,7 +70,7 @@ void btif_debug_conn_state(const bt_bdaddr_t bda,
  next_event();

  conn_event_t* evt = &connection_events[current_event];
  evt->ts = btif_debug_ts();
  evt->ts = time_gettimeofday_us();
  evt->state = state;
  evt->disconnect_reason = disconnect_reason;
  memcpy(&evt->bda, &bda, sizeof(bt_bdaddr_t));
+2 −2
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@
// Callback invoked for each HCI packet.
// Highlander mode - there can be only one...
typedef void (*btsnoop_data_cb)(const uint16_t type, const uint8_t* p_data,
                                const size_t len);
                                const size_t len, const uint64_t timestamp_us);

// This call sets the (one and only) callback that will
// be invoked once for each HCI packet/event.
@@ -34,4 +34,4 @@ void btsnoop_mem_set_callback(btsnoop_data_cb cb);
// This function is invoked every time an HCI packet
// is sent/received. Packets will be filtered  and then
// forwarded to the |btsnoop_data_cb|.
void btsnoop_mem_capture(const BT_HDR* p_buf);
void btsnoop_mem_capture(const BT_HDR* p_buf, const uint64_t timestamp_us);
Loading