Merge "logd: add getEventTag id= command"
am: 3e3aaca4c3
Change-Id: I57671afa8b9a8219fef9f5f690260ecae682d9ca
This commit is contained in:
commit
b7987ce8c4
5 changed files with 42 additions and 0 deletions
|
|
@ -301,6 +301,7 @@ int CommandListener::GetEventTagCmd::runCommand(SocketClient *cli,
|
||||||
|
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
const char *format = NULL;
|
const char *format = NULL;
|
||||||
|
const char *id = NULL;
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
static const char _name[] = "name=";
|
static const char _name[] = "name=";
|
||||||
if (!strncmp(argv[i], _name, strlen(_name))) {
|
if (!strncmp(argv[i], _name, strlen(_name))) {
|
||||||
|
|
@ -313,6 +314,21 @@ int CommandListener::GetEventTagCmd::runCommand(SocketClient *cli,
|
||||||
format = argv[i] + strlen(_format);
|
format = argv[i] + strlen(_format);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char _id[] = "id=";
|
||||||
|
if (!strncmp(argv[i], _id, strlen(_id))) {
|
||||||
|
id = argv[i] + strlen(_id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id) {
|
||||||
|
if (format || name) {
|
||||||
|
cli->sendMsg("can not mix id= with either format= or name=");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
cli->sendMsg(package_string(mBuf.formatEntry(atoi(id), uid)).c_str());
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cli->sendMsg(package_string(mBuf.formatGetEventTag(uid,
|
cli->sendMsg(package_string(mBuf.formatGetEventTag(uid,
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,9 @@ public:
|
||||||
const char *name, const char *format) {
|
const char *name, const char *format) {
|
||||||
return tags.formatGetEventTag(uid, name, format);
|
return tags.formatGetEventTag(uid, name, format);
|
||||||
}
|
}
|
||||||
|
std::string formatEntry(uint32_t tag, uid_t uid) {
|
||||||
|
return tags.formatEntry(tag, uid);
|
||||||
|
}
|
||||||
const char *tagToName(uint32_t tag) { return tags.tagToName(tag); }
|
const char *tagToName(uint32_t tag) { return tags.tagToName(tag); }
|
||||||
|
|
||||||
// helper must be protected directly or implicitly by lock()/unlock()
|
// helper must be protected directly or implicitly by lock()/unlock()
|
||||||
|
|
|
||||||
|
|
@ -836,6 +836,11 @@ std::string LogTags::formatEntry_locked(uint32_t tag, uid_t uid,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string LogTags::formatEntry(uint32_t tag, uid_t uid) {
|
||||||
|
android::RWLock::AutoRLock readLock(rwlock);
|
||||||
|
return formatEntry_locked(tag, uid);
|
||||||
|
}
|
||||||
|
|
||||||
std::string LogTags::formatGetEventTag(uid_t uid,
|
std::string LogTags::formatGetEventTag(uid_t uid,
|
||||||
const char* name, const char* format) {
|
const char* name, const char* format) {
|
||||||
bool all = name && (name[0] == '*') && !name[1];
|
bool all = name && (name[0] == '*') && !name[1];
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,7 @@ public:
|
||||||
// reverse lookup from tag
|
// reverse lookup from tag
|
||||||
const char* tagToName(uint32_t tag) const;
|
const char* tagToName(uint32_t tag) const;
|
||||||
const char* tagToFormat(uint32_t tag) const;
|
const char* tagToFormat(uint32_t tag) const;
|
||||||
|
std::string formatEntry(uint32_t tag, uid_t uid);
|
||||||
// find associated tag
|
// find associated tag
|
||||||
uint32_t nameToTag(const char* name) const;
|
uint32_t nameToTag(const char* name) const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -836,6 +836,23 @@ TEST(logd, getEventTag_list) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(logd, getEventTag_42) {
|
||||||
|
#ifdef __ANDROID__
|
||||||
|
char buffer[256];
|
||||||
|
memset(buffer, 0, sizeof(buffer));
|
||||||
|
snprintf(buffer, sizeof(buffer), "getEventTag id=42");
|
||||||
|
send_to_control(buffer, sizeof(buffer));
|
||||||
|
buffer[sizeof(buffer) - 1] = '\0';
|
||||||
|
char *cp;
|
||||||
|
long ret = strtol(buffer, &cp, 10);
|
||||||
|
EXPECT_GT(ret, 16);
|
||||||
|
EXPECT_TRUE(strstr(buffer, "\t(to life the universe etc|3)") != NULL);
|
||||||
|
EXPECT_TRUE(strstr(buffer, "answer") != NULL);
|
||||||
|
#else
|
||||||
|
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
TEST(logd, getEventTag_newentry) {
|
TEST(logd, getEventTag_newentry) {
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue