1 /**************************************************************************
5 Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
7 Contact: Boram Park <boram1288.park@samsung.com>
8 Sangjin LEE <lsj119@samsung.com>
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 **************************************************************************/
41 #include <sys/types.h>
43 #include <sys/ioctl.h>
49 #include <X11/Xw32defs.h>
50 #include <xdbg_types.h>
51 #include <xdbg_evlog.h>
53 typedef struct _EvlogOption
57 char command_name[PATH_MAX+1];
58 char path_name[PATH_MAX+1];
65 _printUsage(char* name)
67 fprintf(stderr, "Usage: %s [OPTION]...\n", name);
68 fprintf(stderr, "\n");
69 fprintf(stderr, " Options:\n");
70 fprintf(stderr, " -f [File_Name] File to save information\n");
71 fprintf(stderr, "\n");
72 fprintf(stderr, " -h Command Usage information\n");
73 fprintf(stderr, "\n");
76 static void _xEvlogAnalyzePrint (EvlogOption *eo)
78 int fd = -1, cfd = -1;
82 EvlogInfo evinfo={0,};
86 _printUsage(eo->command_name);
90 if (strlen (eo->path_name) <= 0)
92 printf ("failed: no evlog path\n");
96 fd = open (eo->path_name, O_RDONLY);
99 printf ("failed: open '%s'. (%s)\n", eo->path_name, strerror(errno));
103 snprintf (fd_name, sizeof (fd_name), "/proc/%d/fd/1", eo->pid);
104 cfd = open (fd_name, O_RDWR);
108 printf ("failed: open consol '%s'. (%s)\n", fd_name, strerror(errno));
112 while ((read_len = read (fd, &evlog_len, sizeof (int))) == sizeof (int))
115 int size = sizeof (log);
117 memset (&evinfo, 0, sizeof (EvlogInfo));
121 read_len = read (fd, &evinfo.time, sizeof (CARD32));
122 GOTO_IF_FAIL (read_len == sizeof (CARD32), print_done);
125 read_len = read (fd, &evinfo.type, sizeof (EvlogType));
126 GOTO_IF_FAIL (read_len == sizeof (EvlogType), print_done);
127 GOTO_IF_FAIL (evinfo.type >= EVENT && evinfo.type <= FLUSH, print_done);
130 read_len = read (fd, &evinfo.mask, sizeof (int));
131 GOTO_IF_FAIL (read_len == sizeof (int), print_done);
134 if (evinfo.mask & EVLOG_MASK_CLIENT)
136 read_len = read (fd, &evinfo.client, sizeof (EvlogClient));
137 GOTO_IF_FAIL (read_len == sizeof (EvlogClient), print_done);
141 if (evinfo.mask & EVLOG_MASK_REQUEST)
143 read_len = read (fd, &evinfo.req, sizeof(EvlogRequest));
144 GOTO_IF_FAIL (read_len == sizeof(EvlogRequest), print_done);
147 evinfo.req.ptr = malloc (evinfo.req.length * 4);
148 GOTO_IF_FAIL (evinfo.req.ptr != NULL, print_done);
150 read_len = read (fd, evinfo.req.ptr, (evinfo.req.length * 4));
151 GOTO_IF_FAIL (read_len == (evinfo.req.length * 4), print_done);
155 if (evinfo.mask & EVLOG_MASK_EVENT)
157 read_len = read (fd, &evinfo.evt, sizeof(EvlogEvent));
158 GOTO_IF_FAIL (read_len == sizeof(EvlogEvent), print_done);
161 evinfo.evt.ptr = malloc (sizeof(xEvent));
162 GOTO_IF_FAIL (evinfo.evt.ptr != NULL, print_done);
164 read_len = read (fd, evinfo.evt.ptr, sizeof (xEvent));
165 GOTO_IF_FAIL (read_len == sizeof(xEvent), print_done);
168 GOTO_IF_FAIL (evlog_len == total, print_done);
170 xDbgEvlogFillLog(&evinfo, log, &size);
175 free (evinfo.req.ptr);
176 evinfo.req.ptr = NULL;
181 free (evinfo.evt.ptr);
182 evinfo.evt.ptr = NULL;
189 free (evinfo.req.ptr);
192 free (evinfo.evt.ptr);
202 _checkOption(int argc, char** argv)
206 char* opt_str = NULL;
207 EvlogOption eo = {0,};
209 eo.pid = atoi (argv[0]);
211 strncpy(eo.command_name, argv[1], PATH_MAX);
215 _printUsage( eo.command_name );
219 while ((c = getopt(argc, argv, "f:h")) != EOF)
226 opt_str_len = strlen(opt_str);
231 strncpy (eo.path_name, opt_str, opt_str_len);
236 _printUsage( eo.command_name );
245 _xEvlogAnalyzePrint(&eo);
249 int main(int argc, char** argv)
257 dpy = XOpenDisplay (NULL);
260 fprintf (stderr, "failed: open display\n");
265 new_argv = (char**)malloc (new_argc * sizeof (char*));
268 fprintf (stderr, "failed: malloc new argv\n");
272 snprintf (temp, sizeof(temp), "%d", (int)getpid());
275 for (i = 0; i < argc; i++)
276 new_argv[i+1] = argv[i];
278 _checkOption(new_argc, new_argv);