2 * xserver-xorg-input-evdev-multitouch
4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Sung-Jin Park <sj76.park@samsung.com>
7 * Sangjin LEE <lsj119@samsung.com>
9 * Permission to use, copy, modify, distribute, and sell this software
10 * and its documentation for any purpose is hereby granted without
11 * fee, provided that the above copyright notice appear in all copies
12 * and that both that copyright notice and this permission notice
13 * appear in supporting documentation, and that the name of Red Hat
14 * not be used in advertising or publicity pertaining to distribution
15 * of the software without specific, written prior permission. Red
16 * Hat makes no representations about the suitability of this software
17 * for any purpose. It is provided "as is" without express or implied
20 * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
21 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
22 * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
23 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
24 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
25 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
26 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
33 #include <sys/types.h>
36 #include <sys/ioctl.h>
40 #include <semaphore.h>
43 #define MAY_NOT_BE_USED __attribute__ ((unused))
45 #define MAY_NOT_BE_USED
49 #define SYNC_DEBUG_SHM_KEY 0xDEAD2012
50 #define SHM_MESG_SIZE ( 1024 * 1024 )
52 #ifndef CLOCK_MONOTONIC
53 #define CLOCK_MONOTONIC 1
69 unsigned long tvStart;
76 static volatile VSYNC_DEBUG_INFO * _vsync_debug = NULL;
79 _vsync_debug_init(void)
85 shmid = shmget(SYNC_DEBUG_SHM_KEY, SHM_MESG_SIZE, IPC_CREAT | IPC_RMID);
88 fprintf(stderr, "\tError : shmget size:%d\n", SHM_MESG_SIZE);
92 if (shmctl(shmid, IPC_STAT, &ds) < 0)
94 fprintf(stderr, "\tError : shmctl\n");
98 if (ds.shm_segsz < SHM_MESG_SIZE)
100 fprintf(stderr, "\tError : size check\n");
104 _vsync_debug = shmat(shmid, NULL, 0);
105 if (_vsync_debug == (void *) -1)
107 fprintf(stderr, "\tError : shmat\n");
114 fprintf(stderr, "VSYNC_DEBUG.... Error\n");
116 if (_vsync_debug != NULL && _vsync_debug != (void *) -1)
117 shmdt((void*)_vsync_debug);
123 _vsync_debug_get_time(void)
127 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
128 return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
134 _vsync_debug_lock(void)
136 if (sem_wait((sem_t *) &_vsync_debug->sem) < 0)
137 fprintf(stderr, "sem_wait error\n");
142 _vsync_debug_unlock(void)
144 if (sem_post((sem_t *) &_vsync_debug->sem) < 0)
145 fprintf(stderr, "sem_post error\n");
149 _vsync_debug_set_slot(int isSync, const char * format, va_list args)
151 unsigned long cur_time;
153 if (_vsync_debug == NULL)
156 if (!_vsync_debug->initialized)
159 if (! _vsync_debug->isLogging)
162 if (!_vsync_debug->isPrintEnabled)
165 if (_vsync_debug->cur_pos > SHM_MESG_SIZE - 1024)
168 cur_time = _vsync_debug_get_time();
174 _vsync_debug->count++;
175 _vsync_debug->cur_pos += sprintf((char *) _vsync_debug->debug_msg + _vsync_debug->cur_pos, "
\e[32m");
178 _vsync_debug->cur_pos += sprintf((char *) _vsync_debug->debug_msg + _vsync_debug->cur_pos, "%6ld ", cur_time);
179 _vsync_debug->cur_pos += vsprintf((char *) _vsync_debug->debug_msg + _vsync_debug->cur_pos, format, args);
180 _vsync_debug->debug_msg[_vsync_debug->cur_pos++] = '\n';
181 _vsync_debug->debug_msg[_vsync_debug->cur_pos] = '\0';
184 _vsync_debug->cur_pos += sprintf((char *) _vsync_debug->debug_msg + _vsync_debug->cur_pos, "
\e[0m");
186 _vsync_debug_unlock();
189 static void MAY_NOT_BE_USED
190 vsync_debug_start(void)
192 if (_vsync_debug == NULL)
195 if (!_vsync_debug->initialized)
198 _vsync_debug->isLogging = 1;
199 _vsync_debug->tvStart = _vsync_debug_get_time();
202 static void MAY_NOT_BE_USED
203 vsync_debug_stop(void)
205 unsigned long tvStop;
207 if (_vsync_debug == NULL)
210 if (!_vsync_debug->initialized)
213 _vsync_debug->isLogging = 0;
214 tvStop = _vsync_debug_get_time();
217 if (_vsync_debug->isPrintEnabled)
220 fprintf(stderr, "VSYNC DEBUG: count:%d, start:%6ld, end:%6ld\n", _vsync_debug->count, _vsync_debug->tvStart, tvStop);
221 fprintf(stderr, "%s\n", _vsync_debug->debug_msg);
223 _vsync_debug->cur_pos = 0;
224 _vsync_debug->debug_msg[0] = '\0';
225 _vsync_debug_unlock();
228 static void MAY_NOT_BE_USED
229 vsync_debug_set_sync(const char * format, ...)
233 va_start(args, format);
235 _vsync_debug_set_slot(1, format, args);
240 static void MAY_NOT_BE_USED
241 vsync_debug_set_slot(const char * format, ...)
245 va_start(args, format);
247 _vsync_debug_set_slot(0, format, args);
252 static void MAY_NOT_BE_USED
253 vsync_debug_set_enable(int bEnable)
255 if (_vsync_debug == NULL)
258 if (!_vsync_debug->initialized)
261 _vsync_debug->isPrintEnabled = bEnable;
264 static void MAY_NOT_BE_USED
265 vsync_debug_master_init(void)
267 int shmid = _vsync_debug_init();
269 _vsync_debug->_shmid = shmid;
271 if (sem_init((sem_t *) &_vsync_debug->sem, 1, 1) < 0)
273 fprintf(stderr, "\tError : sem_init\n");
277 _vsync_debug->initialized = 1;
281 fprintf(stderr, "VSYNC_DEBUG.... master Error\n");
284 static void MAY_NOT_BE_USED
285 vsync_debug_master_close(void)
287 if (_vsync_debug == NULL)
290 if (shmctl(_vsync_debug->_shmid, IPC_RMID, NULL) < 0)
292 fprintf(stderr, "\tError : shmctl(IPC_RMID)\n");
294 if (shmdt((void*)_vsync_debug) < 0)
296 fprintf(stderr, "\tError : shmdt\n");
302 #endif /* _SYNC_DEBUG_H */