OSDN Git Service

Fix double mutex unlock and if() condition
[android-x86/system-bt.git] / btif / src / btif_debug_btsnoop.c
index 95fc4db..511f8a8 100644 (file)
@@ -30,7 +30,7 @@
 
 // Total btsnoop memory log buffer size
 #ifndef BTSNOOP_MEM_BUFFER_SIZE
-static const size_t BTSNOOP_MEM_BUFFER_SIZE = (172 * 1024);
+static const size_t BTSNOOP_MEM_BUFFER_SIZE = (128 * 1024);
 #endif
 
 // Block size for copying buffers (for compression/encoding etc.)
@@ -76,7 +76,7 @@ static void btsnoop_cb(const uint16_t type, const uint8_t *data, const size_t le
   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.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;
@@ -89,7 +89,7 @@ static bool btsnoop_compress(ringbuffer_t *rb_dst, ringbuffer_t *rb_src) {
   assert(rb_dst != NULL);
   assert(rb_src != NULL);
 
-  z_stream zs = {0};
+  z_stream zs = {.zalloc = Z_NULL, .zfree = Z_NULL, .opaque = Z_NULL};
   if (deflateInit(&zs, Z_DEFAULT_COMPRESSION) != Z_OK)
     return false;
 
@@ -128,7 +128,7 @@ void btif_debug_btsnoop_init(void) {
 }
 
 void btif_debug_btsnoop_dump(int fd) {
-  dprintf(fd, "\n--- BEGIN:BTSNOOP_LOG_SUMMARY (%zu bytes in) ---\n", ringbuffer_size(buffer));
+  dprintf(fd, "--- BEGIN:BTSNOOP_LOG_SUMMARY (%zu bytes in) ---\n", ringbuffer_size(buffer));
 
   ringbuffer_t *ringbuffer = ringbuffer_init(BTSNOOP_MEM_BUFFER_SIZE);
   if (ringbuffer == NULL) {
@@ -156,16 +156,18 @@ void btif_debug_btsnoop_dump(int fd) {
   uint8_t b64_in[3] = {0};
   char b64_out[5] = {0};
 
-  size_t i = sizeof(btsnooz_preamble_t);
+  size_t line_length = 0;
   while (ringbuffer_size(ringbuffer) > 0) {
     size_t read = ringbuffer_pop(ringbuffer, b64_in, 3);
-    if (i > 0 && i % MAX_LINE_LENGTH == 0)
+    if (line_length >= MAX_LINE_LENGTH) {
       dprintf(fd, "\n");
-    i += b64_ntop(b64_in, read, b64_out, 5);
+      line_length = 0;
+    }
+    line_length += b64_ntop(b64_in, read, b64_out, 5);
     dprintf(fd, "%s", b64_out);
   }
 
-  dprintf(fd, "\n--- END:BTSNOOP_LOG_SUMMARY (%zu bytes out) ---\n", i);
+  dprintf(fd, "\n--- END:BTSNOOP_LOG_SUMMARY ---\n");
 
 error:
   ringbuffer_free(ringbuffer);