summaryrefslogtreecommitdiffstats
path: root/logcat/logcat.cpp
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2016-04-11 14:03:48 -0700
committerMark Salyzyn <salyzyn@google.com>2016-04-13 11:42:57 -0700
commit45177732966d82a9ee8d558f9b115e061e0c7208 (patch)
tree62a86825f59fd507fcb7a810176a825e5b9c8db4 /logcat/logcat.cpp
parent378f4745a27632f3bb26e7029fe55142001f3d47 (diff)
downloadsystem_core-45177732966d82a9ee8d558f9b115e061e0c7208.tar.gz
system_core-45177732966d82a9ee8d558f9b115e061e0c7208.tar.bz2
system_core-45177732966d82a9ee8d558f9b115e061e0c7208.zip
logcat: allow comma-separate list of buffers
- Add parsing to support comma+ separated list of buffers. - Move get_size test into a standalone get_groups function - add some additional tests for this feature, leveraging get_groups to confirm buffer selection. Bug: 28120456 Change-Id: I0b42736c08cf4b2a435cb74cda540dc163a26bd1
Diffstat (limited to 'logcat/logcat.cpp')
-rw-r--r--logcat/logcat.cpp134
1 files changed, 43 insertions, 91 deletions
diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp
index 04b096f0b..fe5da194c 100644
--- a/logcat/logcat.cpp
+++ b/logcat/logcat.cpp
@@ -315,8 +315,8 @@ static void show_help(const char *cmd)
// kernel (userdebug and eng) buffers undocumented.
" -b <buffer>, --buffer=<buffer> Request alternate ring buffer, 'main',\n"
" 'system', 'radio', 'events', 'crash', 'default' or 'all'.\n"
- " Multiple -b parameters are allowed. Buffers interleaved.\n"
- " Default -b main -b system -b crash.\n"
+ " Multiple -b parameters or comma separated list of buffers are\n"
+ " allowed. Buffers interleaved. Default -b main,system,crash.\n"
" -B, --binary Output the log in binary.\n"
" -S, --statistics Output statistics.\n"
" -p, --prune Print prune white and ~black list. Service is specified as\n"
@@ -762,111 +762,63 @@ int main(int argc, char **argv)
break;
case 'b': {
- if (strcmp(optarg, "default") == 0) {
- for (int i = LOG_ID_MIN; i < LOG_ID_MAX; ++i) {
- switch (i) {
- case LOG_ID_SECURITY:
- case LOG_ID_EVENTS:
- continue;
- case LOG_ID_MAIN:
- case LOG_ID_SYSTEM:
- case LOG_ID_CRASH:
- break;
- default:
- continue;
- }
-
- const char *name = android_log_id_to_name((log_id_t)i);
- log_id_t log_id = android_name_to_log_id(name);
-
- if (log_id != (log_id_t)i) {
- continue;
- }
-
- bool found = false;
- for (dev = devices; dev; dev = dev->next) {
- if (!strcmp(optarg, dev->device)) {
- found = true;
- break;
- }
- if (!dev->next) {
- break;
- }
- }
- if (found) {
- break;
- }
-
- log_device_t* d = new log_device_t(name, false);
+ unsigned idMask = 0;
+ while ((optarg = strtok(optarg, ",:; \t\n\r\f")) != NULL) {
+ if (strcmp(optarg, "default") == 0) {
+ idMask |= (1 << LOG_ID_MAIN) |
+ (1 << LOG_ID_SYSTEM) |
+ (1 << LOG_ID_CRASH);
+ } else if (strcmp(optarg, "all") == 0) {
+ idMask = (unsigned)-1;
+ } else {
+ log_id_t log_id = android_name_to_log_id(optarg);
+ const char *name = android_log_id_to_name(log_id);
- if (dev) {
- dev->next = d;
- dev = d;
- } else {
- devices = dev = d;
+ if (strcmp(name, optarg) != 0) {
+ logcat_panic(true, "unknown buffer %s\n", optarg);
}
- g_devCount++;
+ idMask |= (1 << log_id);
}
- break;
+ optarg = NULL;
}
- if (strcmp(optarg, "all") == 0) {
- for (int i = LOG_ID_MIN; i < LOG_ID_MAX; ++i) {
- const char *name = android_log_id_to_name((log_id_t)i);
- log_id_t log_id = android_name_to_log_id(name);
+ for (int i = LOG_ID_MIN; i < LOG_ID_MAX; ++i) {
+ const char *name = android_log_id_to_name((log_id_t)i);
+ log_id_t log_id = android_name_to_log_id(name);
- if (log_id != (log_id_t)i) {
- continue;
- }
+ if (log_id != (log_id_t)i) {
+ continue;
+ }
+ if ((idMask & (1 << i)) == 0) {
+ continue;
+ }
- bool found = false;
- for (dev = devices; dev; dev = dev->next) {
- if (!strcmp(optarg, dev->device)) {
- found = true;
- break;
- }
- if (!dev->next) {
- break;
- }
- }
- if (found) {
+ bool found = false;
+ for (dev = devices; dev; dev = dev->next) {
+ if (!strcmp(name, dev->device)) {
+ found = true;
break;
}
-
- bool binary = !strcmp(name, "events") ||
- !strcmp(name, "security");
- log_device_t* d = new log_device_t(name, binary);
-
- if (dev) {
- dev->next = d;
- dev = d;
- } else {
- devices = dev = d;
+ if (!dev->next) {
+ break;
}
- g_devCount++;
}
- break;
- }
+ if (found) {
+ continue;
+ }
- bool binary = !(strcmp(optarg, "events") &&
- strcmp(optarg, "security"));
+ bool binary = !strcmp(name, "events") ||
+ !strcmp(name, "security");
+ log_device_t* d = new log_device_t(name, binary);
- if (devices) {
- dev = devices;
- while (dev->next) {
- if (!strcmp(optarg, dev->device)) {
- dev = NULL;
- break;
- }
- dev = dev->next;
- }
if (dev) {
- dev->next = new log_device_t(optarg, binary);
+ dev->next = d;
+ dev = d;
+ } else {
+ devices = dev = d;
}
- } else {
- devices = new log_device_t(optarg, binary);
+ g_devCount++;
}
- g_devCount++;
}
break;