summaryrefslogtreecommitdiff
path: root/cras/src/server/cras_bt_log.h
blob: 26c559a34adfa1933ee49036c5fce5774ad983ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* Copyright 2019 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef CRAS_BT_LOG_H_
#define CRAS_BT_LOG_H_

#include <stdint.h>

#include "cras_types.h"

#define CRAS_BT_LOGGING 1

#if (CRAS_BT_LOGGING)
#define BTLOG(log, event, data1, data2)                                        \
	cras_bt_event_log_data(log, event, data1, data2);
#else
#define BTLOG(log, event, data1, data2)
#endif

extern struct cras_bt_event_log *btlog;

static inline struct cras_bt_event_log *cras_bt_event_log_init()
{
	struct cras_bt_event_log *log;
	log = (struct cras_bt_event_log *)calloc(
		1, sizeof(struct cras_bt_event_log));
	log->len = CRAS_BT_EVENT_LOG_SIZE;

	return log;
}

static inline void cras_bt_event_log_deinit(struct cras_bt_event_log *log)
{
	free(log);
}

static inline void cras_bt_event_log_data(struct cras_bt_event_log *log,
					  enum CRAS_BT_LOG_EVENTS event,
					  uint32_t data1, uint32_t data2)
{
	struct timespec now;

	clock_gettime(CLOCK_MONOTONIC_RAW, &now);
	log->log[log->write_pos].tag_sec =
		(event << 24) | (now.tv_sec & 0x00ffffff);
	log->log[log->write_pos].nsec = now.tv_nsec;
	log->log[log->write_pos].data1 = data1;
	log->log[log->write_pos].data2 = data2;

	log->write_pos++;
	log->write_pos %= CRAS_BT_EVENT_LOG_SIZE;
}

#endif /* CRAS_BT_LOG_H_ */