• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2020 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 
6 #ifndef CRAS_MAIN_THREAD_LOG_H_
7 #define CRAS_MAIN_THREAD_LOG_H_
8 
9 #include <stdint.h>
10 
11 #include "cras_types.h"
12 
13 #define CRAS_MAIN_THREAD_LOGGING 1
14 
15 #if (CRAS_MAIN_THREAD_LOGGING)
16 #define MAINLOG(log, event, data1, data2, data3)                               \
17 	main_thread_event_log_data(log, event, data1, data2, data3);
18 #else
19 #define MAINLOG(log, event, data1, data2, data3)
20 #endif
21 
22 extern struct main_thread_event_log *main_log;
23 
main_thread_event_log_init()24 static inline struct main_thread_event_log *main_thread_event_log_init()
25 {
26 	struct main_thread_event_log *log;
27 	log = (struct main_thread_event_log *)calloc(
28 		1, sizeof(struct main_thread_event_log));
29 	if (!log)
30 		return NULL;
31 
32 	log->len = MAIN_THREAD_EVENT_LOG_SIZE;
33 	return log;
34 }
35 
36 static inline void
main_thread_event_log_deinit(struct main_thread_event_log * log)37 main_thread_event_log_deinit(struct main_thread_event_log *log)
38 {
39 	if (log)
40 		free(log);
41 }
42 
main_thread_event_log_data(struct main_thread_event_log * log,enum MAIN_THREAD_LOG_EVENTS event,uint32_t data1,uint32_t data2,uint32_t data3)43 static inline void main_thread_event_log_data(struct main_thread_event_log *log,
44 					      enum MAIN_THREAD_LOG_EVENTS event,
45 					      uint32_t data1, uint32_t data2,
46 					      uint32_t data3)
47 {
48 	struct timespec now;
49 
50 	if (!log)
51 		return;
52 
53 	clock_gettime(CLOCK_MONOTONIC_RAW, &now);
54 	log->log[log->write_pos].tag_sec =
55 		(event << 24) | ((now.tv_sec % 86400) & 0x00ffffff);
56 	log->log[log->write_pos].nsec = now.tv_nsec;
57 	log->log[log->write_pos].data1 = data1;
58 	log->log[log->write_pos].data2 = data2;
59 	log->log[log->write_pos].data3 = data3;
60 	log->write_pos++;
61 	log->write_pos %= MAIN_THREAD_EVENT_LOG_SIZE;
62 }
63 
64 #endif /* CRAS_MAIN_THREAD_LOG_H_ */
65