1 /* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 *
5 * The blow logging funcitons must only be called from the audio thread.
6 */
7
8 #ifndef AUDIO_THREAD_LOG_H_
9 #define AUDIO_THREAD_LOG_H_
10
11 #include <pthread.h>
12 #include <stdint.h>
13
14 #include "cras_types.h"
15
16 #define AUDIO_THREAD_LOGGING 1
17
18 #if (AUDIO_THREAD_LOGGING)
19 #define ATLOG(log,event,data1,data2,data3) \
20 audio_thread_event_log_data(log,event,data1,data2,data3);
21 #else
22 #define ATLOG(log,event,data1,data2,data3)
23 #endif
24
25 extern struct audio_thread_event_log *atlog;
26
27 static inline
audio_thread_event_log_init()28 struct audio_thread_event_log *audio_thread_event_log_init()
29 {
30 struct audio_thread_event_log *log;
31 log = (struct audio_thread_event_log *)
32 calloc(1, sizeof(struct audio_thread_event_log));
33 log->len = AUDIO_THREAD_EVENT_LOG_SIZE;
34
35 return log;
36 }
37
38 static inline
audio_thread_event_log_deinit(struct audio_thread_event_log * log)39 void audio_thread_event_log_deinit(struct audio_thread_event_log *log)
40 {
41 free(log);
42 }
43
44 /* Log a tag and the current time, Uses two words, the first is split
45 * 8 bits for tag and 24 for seconds, second word is micro seconds.
46 */
audio_thread_event_log_data(struct audio_thread_event_log * log,enum AUDIO_THREAD_LOG_EVENTS event,uint32_t data1,uint32_t data2,uint32_t data3)47 static inline void audio_thread_event_log_data(
48 struct audio_thread_event_log *log,
49 enum AUDIO_THREAD_LOG_EVENTS event,
50 uint32_t data1,
51 uint32_t data2,
52 uint32_t data3)
53 {
54 struct timespec now;
55
56 clock_gettime(CLOCK_MONOTONIC_RAW, &now);
57 log->log[log->write_pos].tag_sec =
58 (event << 24) | (now.tv_sec & 0x00ffffff);
59 log->log[log->write_pos].nsec = now.tv_nsec;
60 log->log[log->write_pos].data1 = data1;
61 log->log[log->write_pos].data2 = data2;
62 log->log[log->write_pos].data3 = data3;
63
64 log->write_pos++;
65 log->write_pos %= AUDIO_THREAD_EVENT_LOG_SIZE;
66 }
67
68 #endif /* AUDIO_THREAD_LOG_H_ */
69