Logcat中添加kernal log
来源:互联网 发布:图片分类软件 编辑:程序博客网 时间:2024/06/14 11:09
修改的文件:system/core/logcat/logcat.cpp
1、首先先加入头文件
#include <sys/klog.h> //add by
2、定义所使用的TAG
#define KERNEL_TAG "Kernel"
3、替换readLogLines函数
static void readLogLines(log_device_t* devices)
{
log_device_t* dev;
int max = 0;
int ret;
int queued_lines = 0;
bool sleep = true;
char buffer[256] = {0}; //add by zhaofei
int result;
fd_set readset;
for (dev=devices; dev; dev = dev->next) {
if (dev->fd > max) {
max = dev->fd;
}
}
while (1) {
do {
timeval timeout = { 0, 5000 /* 5ms */ }; // If we oversleep it's ok, i.e. ignore EINTR.
FD_ZERO(&readset);
for (dev=devices; dev; dev = dev->next) {
FD_SET(dev->fd, &readset);
}
result = select(max + 1, &readset, NULL, NULL, sleep ? NULL : &timeout);
} while (result == -1 && errno == EINTR);
if (result >= 0) {
for (dev=devices; dev; dev = dev->next) {
if (FD_ISSET(dev->fd, &readset)) {
queued_entry_t* entry = new queued_entry_t();
/* NOTE: driver guarantees we read exactly one full entry */
ret = read(dev->fd, entry->buf, LOGGER_ENTRY_MAX_LEN);
if (ret < 0) {
if (errno == EINTR) {
delete entry;
goto next;
}
if (errno == EAGAIN) {
delete entry;
break;
}
perror("logcat read");
exit(EXIT_FAILURE);
}
else if (!ret) {
fprintf(stderr, "read: Unexpected EOF!\n");
exit(EXIT_FAILURE);
}
entry->entry.msg[entry->entry.len] = '\0';
dev->enqueue(entry);
++queued_lines;
#if 1 //read kernel log
if((ret = klogctl(9, buffer, sizeof(buffer))) > 0) {
if((ret = klogctl(2, buffer, sizeof(buffer))) > 0) {
entry->entry.tid = 0;
entry->entry.pid = getpid();
/*priority*/
entry->entry.msg[0] = Android_LOG_INFO;
/*tag*/
strcpy(entry->entry.msg+1, KERNEL_TAG);
/*message*/
strncpy(entry->entry.msg+1+sizeof(KERNEL_TAG), buffer, ret);
entry->entry.len = 1 + sizeof(KERNEL_TAG) + ret + 1;
entry->entry.msg[entry->entry.len] = '/0';
/*
if (g_printBinary) {
printBinary(dev, entry->entry);
} else {
(void) processBuffer(dev, entry->entry);
}
*/
printNextEntry(dev);
}
}
#endif
}
}
if (result == 0) {
// we did our short timeout trick and there's nothing new
// print everything we have and wait for more data
sleep = true;
while (true) {
chooseFirst(devices, &dev);
if (dev == NULL) {
break;
}
if (g_tail_lines == 0 || queued_lines <= g_tail_lines) {
printNextEntry(dev);
} else {
skipNextEntry(dev);
}
--queued_lines;
}
// the caller requested to just dump the log and exit
if (g_nonblock) {
exit(0);
}
} else {
// print all that aren't the last in their list
sleep = false;
while (g_tail_lines == 0 || queued_lines > g_tail_lines) {
chooseFirst(devices, &dev);
if (dev == NULL || dev->queue->next == NULL) {
break;
}
if (g_tail_lines == 0) {
printNextEntry(dev);
} else {
skipNextEntry(dev);
}
--queued_lines;
}
}
}
next:
;
}
}
然后就可以使用logcat来抓取kernel的log了!
- Logcat中添加kernal log
- Android JNI中增加LOGCAT,LOG
- 解决eclipse中logcat不显示log
- Logcat输出framework 中的LOGV 及kernal信息的输出
- android 6.0 logcat机制(二)logcat从logd中获取log保存到文件中
- android 6.0 logcat机制(二)logcat从logd中获取log保存到文件中
- 解决eclipse中logcat不显示log的问题
- Android中log及logcat命令的使用
- 解决eclipse中logcat不显示log的问题
- 解决eclipse中logcat不显示log的问题
- 代码中读取android控制台Log(通过Logcat读取)
- 解决eclipse中logcat不显示log的问题
- eclipse中logcat偶尔不显示log的问题解决办法
- 解决eclipse中logcat不显示log的问题
- 解决eclipse中logcat不显示log的问题
- 解决Myeclipse中logcat不显示log的问题
- 解决eclipse中logcat不显示log的问题
- 解决eclipse中logcat不显示log的问题
- 线程编译问题(undefined reference to `pthread_create')
- iPhone 应用开发:音频播放
- 天才=99%的汗水+1%天赋
- 关闭linux下的防火墙
- 矩阵的乘法-编程心得
- Logcat中添加kernal log
- linux下配置svn error:failed to load JavaHL library
- <context-param>与<init-param>的区别与作用
- jetty嵌入式发布XFire实现的webservice
- Git使用小结
- default启动图片尺寸
- 软件开发中思考的重要性
- zoj 1221 Risk 最短路 floyd
- Unicode and HTML