5 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
7 * Contact: Jeesun Kim <iamjs.kim@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
29 #include <sys/types.h>
35 #include "_util_log.h"
37 #define VERINFO_PATH "/etc/info.ini"
38 #define DEBUG_DIR "/opt/share/hidden_storage/SLP_debug"
42 #define FILE_PERMS (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
44 /* lockupinfo launch key combination:
45 * 1. volume side key up
46 * 2. volume side key down
49 * 5. volume side key up
50 * 6. volume side key down
51 * 7. volume side key up
55 /* WARNING : formatted string buffer is limited to 1024 byte */
56 int fprintf_fd(int fd, const char *fmt, ...)
62 n = vsnprintf(buff, 1024 - 1, fmt, args);
68 char *fgets_fd(char *s, int n, int fd)
75 while (--n > 0 && (num = read(fd, &c, 1) > 0)) {
76 if ((*cs++ = c) == '\n')
80 return (num == 0 && cs == s) ? NULL : s;
86 char name[32] = {0, };
87 char size[32] = {0, };
88 char unit[32] = {0, };
94 fprintf(stderr, "[lockupinfo] executed\n");
99 cur_time = time(NULL);
100 localtime_r(&cur_time, &ctime);
102 char nbuf[256] = {0, }; /* name buf */
103 char dbuf[256] = {0, }; /* dir buf */
104 char ibuf[256] = {0, }; /* info buf */
105 char cbuf[256] = {0, }; /* cmd buf */
106 char tbuf[256] = {0, }; /* temp buf */
109 // snprintf(nbuf, sizeof(nbuf), "debuginfo_%02d%02d%02d%02d%02d%02d",
110 // ctime->tm_year, ctime->tm_mon, ctime->tm_mday,
111 // ctime->tm_hour, ctime->tm_min, ctime->tm_sec);
113 strftime(tbuf, sizeof(tbuf), "%Y%m%d%H%M%S", &ctime);
114 snprintf(nbuf, sizeof(nbuf), "debuginfo_%s", tbuf);
116 /* make debug directory if absent */
117 ret = access(DEBUG_DIR, F_OK);
119 if (ret = mkdir(DEBUG_DIR, PERMS) < 0) {
120 _E("Failed to mkdir %s(errno:%d)\n", DEBUG_DIR, ret);
125 snprintf(dbuf, sizeof(dbuf), "%s/%s", DEBUG_DIR, nbuf);
126 ret = mkdir(dbuf, PERMS);
127 retvm_if(ret < 0, -1, "Failed to mkdir %s(errno:%d)\n", dbuf, ret);
129 snprintf(dbuf, sizeof(dbuf), "%s/%s/%s", DEBUG_DIR, nbuf, "files");
130 ret = mkdir(dbuf, PERMS);
131 retvm_if(ret < 0, -1, "Failed to mkdir %s(errno:%d)\n", dbuf, ret);
132 _D("lockupinfo dir [%s]\n", dbuf);
134 snprintf(ibuf, sizeof(ibuf), "%s/%s.info", dbuf, nbuf);
136 /* create .info file */
137 csfd = creat(ibuf, FILE_PERMS);
138 retvm_if(csfd < 0, -1, "Failed to creat %s\n", ibuf);
140 /* print version info */
141 fprintf_fd(csfd, "******************************\n");
142 fprintf_fd(csfd, "s/w version\n");
143 fprintf_fd(csfd, "******************************\n");
145 verinfo = open(VERINFO_PATH, O_RDONLY);
147 _E("Failed to open %s\n", VERINFO_PATH);
150 while (fgets_fd(lbuf, BUF_SIZE, verinfo)) {
151 if (strncmp("Major=", lbuf, 6) == 0) {
152 fprintf_fd(csfd, "%s", lbuf);
154 } else if (strncmp("Minor=", lbuf, 6) == 0) {
155 fprintf_fd(csfd, "%s", lbuf);
157 } else if (strncmp("Date=", lbuf, 5) == 0) {
158 fprintf_fd(csfd, "%s", lbuf);
160 } else if (strncmp("Time=", lbuf, 5) == 0) {
161 fprintf_fd(csfd, "%s", lbuf);
170 meminfo = open("/proc/meminfo", O_RDONLY);
172 _E("Failed to open %s\n", "/proc/meminfo");
175 fprintf_fd(csfd, "*******************************\n");
176 fprintf_fd(csfd, "Mem information\n");
177 fprintf_fd(csfd, "*******************************\n");
179 while (fgets_fd(lbuf, BUF_SIZE, meminfo) != NULL) {
180 sscanf(lbuf, "%s %s %s", name, size, unit);
182 if (strcmp("MemTotal:", name) == 0) {
183 fprintf_fd(csfd, "%s\t%10.0d %s\n", name, atoi(size), unit);
185 } else if (strcmp("MemFree:", name) == 0) {
186 fprintf_fd(csfd, "%s\t%10.0d %s\n", name, atoi(size), unit);
188 } else if (strcmp("Buffers:", name) == 0) {
189 fprintf_fd(csfd, "%s\t%10.0d %s\n", name, atoi(size), unit);
191 } else if (strcmp("Cached:", name) == 0) {
192 fprintf_fd(csfd, "%s\t%10.0d %s\n", name, atoi(size), unit);
200 snprintf(cbuf, sizeof(cbuf), "%s > %s",
201 "ps ax -o pid,tid,ppid,f,stat,pcpu,pmem,wchan,command", "/tmp/ps_tmp.log");
204 tmpfd = open("/tmp/ps_tmp.log", O_RDONLY);
206 _E("Failed to open %s\n", "/tmp/ps_tmp.log");
208 fprintf_fd(csfd, "*******************************\n");
209 fprintf_fd(csfd, "PS information\n");
210 fprintf_fd(csfd, "*******************************\n");
212 while (fgets_fd(lbuf, BUF_SIZE, tmpfd) != NULL) {
213 fprintf_fd(csfd, "%s", lbuf);
216 unlink("/tmp/ps_tmp.log");
220 snprintf(cbuf, sizeof(cbuf), "%s 2> %s",
221 "xinfo -p", "/tmp/ping_tmp.log");
224 if ((tmpfd = open("/tmp/ping_tmp.log", O_RDONLY)) < 0) {
225 fprintf(stderr, "[lockupinfo]can't open %s\n",
226 "/tmp/ping_tmp.log");
228 fprintf_fd(csfd, "*******************************\n");
229 fprintf_fd(csfd, "ping test for all top level windows\n");
230 fprintf_fd(csfd, "*******************************\n");
232 while (fgets_fd(lbuf, BUF_SIZE, tmpfd)) {
233 fprintf_fd(csfd, "%s", lbuf);
236 unlink("/tmp/ping_tmp.log");
240 snprintf(cbuf, sizeof(cbuf), "%s %s",
241 "/usr/bin/xinfo -xwd_topvwins", dbuf);
244 /* close lockupinfoXXXX.info */
247 snprintf(cbuf, sizeof(cbuf), "%s %s/%s.info %s/%s/%s.cs",
248 "cp", dbuf, nbuf, DEBUG_DIR, nbuf, nbuf);
254 snprintf(tbuf, sizeof(tbuf), "%s/%s", dbuf, "main.log");
255 snprintf(cbuf, sizeof(cbuf), "dlogutil -v time -d -f %s *:v", tbuf);
258 snprintf(tbuf, sizeof(tbuf), "%s/radio.log", dbuf);
259 fprintf(stderr, "radio log path = %s\n", tbuf);
260 snprintf(cbuf, sizeof(cbuf), "dlogutil -v time -b radio -d -f %s *:v", tbuf);
264 /* dump window manager info
265 * this code came from window team
267 fprintf(stderr, "[lockupinfo]dump window manager info\n");
268 snprintf(cbuf, sizeof(cbuf), "%s %s/%s",
269 "/usr/bin/e_comp_util -l DUMP_INFO -f", dbuf, "e_comp.log");
272 snprintf(cbuf, sizeof(cbuf), "%s %s/%s",
273 "/usr/bin/border_win_info -p ALL -f", dbuf, "e_illume2.log");
276 system("/usr/bin/keygrab_status 2");
277 snprintf(cbuf, sizeof(cbuf), "%s %s",
278 "cp -af /opt/var/log/keygrab_status.txt", cbuf);
281 snprintf(cbuf, sizeof(cbuf), "%s %s/%s",
282 "/usr/bin/screenshot bmp", cbuf, "slp_screenshot.bmp");
285 snprintf(cbuf, sizeof(cbuf), "%s > %s/%s",
286 "xinfo -topvwins 2", dbuf, "xinfo_topvwins.txt");
289 /* end from window team */
291 /* copy prev xorg log */
292 snprintf(cbuf, sizeof(cbuf), "%s %s",
293 "cp /opt/var/log/prev.Xorg.*", dbuf);
297 snprintf(cbuf, sizeof(cbuf), "%s %s",
298 "cp /opt/var/log/Xorg.*", dbuf);
301 /* dump a list of current tasks and their information */
302 /* requsted by window team */
303 /*snprintf(cbuf, sizeof(cbuf), "echo t > /proc/sysrq-trigger");
307 /* copy syslog messages */
308 snprintf(cbuf, sizeof(cbuf), "%s %s",
309 "cp /opt/var/log/messages*", dbuf);
313 snprintf(cbuf, sizeof(cbuf), "%s %s",
314 "cp /opt/var/log/nandlog_*", dbuf);
317 /* launch bluescreen */
320 if ((bs_pid = fork()) < 0) {
321 fprintf(stderr, "[lockupinfo] fork_error\n");
323 } else if (bs_pid == 0) {
325 ("/usr/bin/blue-screen", "blue-screen", ibuf,
326 "LOCKUPINFO", (char *)0) < 0) {
327 fprintf(stderr, "[lockupinfo] exec_error\n");
329 _exit(1); /*/ shouldn't get here */
332 fprintf(stderr, "[lockupinfo] exit\n");