logcat: test: run 256 simultaneous logcats

For logd daemon, heavy reader stress. For system popen fork and
execute of logcat measure baseline against liblogcat. For liblogcat
local concurrent thread, locking, argument parsing and context scaling
for popen-style pair of android_logcat_run_command_thread* functions.

NB: 1000 logcat executables ran, but did not scale well on time
    blocked for more than a minute. With 343 contexts of
    android_logcat_run_command_thread ran out of local resources
    to even return a file descriptor, and the per-context event tag
    mappings coincidentally ran out at 340 when threads ran, although
    that path was consistently 15% faster than the popen test.

Test: gtest logcat-unit-tests --gtest_filter=*.End_to_End_multitude
Bug: 35326290
Change-Id: I0e1a5d4f8ffbd77fa8db13d53f4d328973731895
This commit is contained in:
Mark Salyzyn 2017-03-24 07:58:10 -07:00
parent ca622b4e78
commit fbc0fe429b

View file

@ -479,6 +479,56 @@ TEST(logcat, End_to_End) {
ASSERT_EQ(1, count);
}
TEST(logcat, End_to_End_multitude) {
pid_t pid = getpid();
log_time ts(CLOCK_MONOTONIC);
ASSERT_LT(0, __android_log_btwrite(0, EVENT_TYPE_LONG, &ts, sizeof(ts)));
FILE* fp[256]; // does this count as a multitude!
memset(fp, 0, sizeof(fp));
logcat_define(ctx[sizeof(fp) / sizeof(fp[0])]);
size_t num = 0;
do {
EXPECT_TRUE(NULL !=
(fp[num] = logcat_popen(
ctx[num], "logcat -v brief -b events -t 100")));
if (!fp[num]) {
fprintf(stderr,
"WARNING: limiting to %zu simultaneous logcat operations\n",
num);
break;
}
} while (++num < sizeof(fp) / sizeof(fp[0]));
char buffer[BIG_BUFFER];
size_t count = 0;
for (size_t idx = 0; idx < sizeof(fp) / sizeof(fp[0]); ++idx) {
if (!fp[idx]) break;
while (fgets(buffer, sizeof(buffer), fp[idx])) {
int p;
unsigned long long t;
if ((2 != sscanf(buffer, "I/[0] ( %d): %llu", &p, &t)) ||
(p != pid)) {
continue;
}
log_time tx((const char*)&t);
if (ts == tx) {
++count;
}
}
logcat_pclose(ctx[idx], fp[idx]);
}
ASSERT_EQ(num, count);
}
static int get_groups(const char* cmd) {
FILE* fp;
logcat_define(ctx);