Loading cmds/statsd/Android.bp +2 −0 Original line number Original line Diff line number Diff line Loading @@ -332,6 +332,8 @@ java_library { "src/stats_log.proto", "src/stats_log.proto", "src/statsd_config.proto", "src/statsd_config.proto", "src/atoms.proto", "src/atoms.proto", "src/shell/shell_config.proto", "src/shell/shell_data.proto", ], ], static_libs: [ static_libs: [ Loading cmds/statsd/src/StatsService.cpp +5 −1 Original line number Original line Diff line number Diff line Loading @@ -360,7 +360,11 @@ status_t StatsService::command(int in, int out, int err, Vector<String8>& args, if (mShellSubscriber == nullptr) { if (mShellSubscriber == nullptr) { mShellSubscriber = new ShellSubscriber(mUidMap, mPullerManager); mShellSubscriber = new ShellSubscriber(mUidMap, mPullerManager); } } mShellSubscriber->startNewSubscription(in, out, resultReceiver); int timeoutSec = -1; if (argCount >= 2) { timeoutSec = atoi(args[1].c_str()); } mShellSubscriber->startNewSubscription(in, out, resultReceiver, timeoutSec); return NO_ERROR; return NO_ERROR; } } } } Loading cmds/statsd/src/shell/ShellSubscriber.cpp +10 −2 Original line number Original line Diff line number Diff line Loading @@ -30,7 +30,8 @@ namespace statsd { const static int FIELD_ID_ATOM = 1; const static int FIELD_ID_ATOM = 1; void ShellSubscriber::startNewSubscription(int in, int out, sp<IResultReceiver> resultReceiver) { void ShellSubscriber::startNewSubscription(int in, int out, sp<IResultReceiver> resultReceiver, int timeoutSec) { VLOG("start new shell subscription"); VLOG("start new shell subscription"); { { std::lock_guard<std::mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex); Loading @@ -50,12 +51,19 @@ void ShellSubscriber::startNewSubscription(int in, int out, sp<IResultReceiver> // Read config forever until EOF is reached. Clients may send multiple configs -- each new // Read config forever until EOF is reached. Clients may send multiple configs -- each new // config replace the previous one. // config replace the previous one. readConfig(in); readConfig(in); VLOG("timeout : %d", timeoutSec); // Now we have read an EOF we now wait for the semaphore until the client exits. // Now we have read an EOF we now wait for the semaphore until the client exits. VLOG("Now wait for client to exit"); VLOG("Now wait for client to exit"); std::unique_lock<std::mutex> lk(mMutex); std::unique_lock<std::mutex> lk(mMutex); if (timeoutSec > 0) { mShellDied.wait_for(lk, timeoutSec * 1s, [this, resultReceiver] { return mResultReceiver != resultReceiver; }); } else { mShellDied.wait(lk, [this, resultReceiver] { return mResultReceiver != resultReceiver; }); mShellDied.wait(lk, [this, resultReceiver] { return mResultReceiver != resultReceiver; }); } } } void ShellSubscriber::updateConfig(const ShellSubscription& config) { void ShellSubscriber::updateConfig(const ShellSubscription& config) { std::lock_guard<std::mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex); Loading cmds/statsd/src/shell/ShellSubscriber.h +2 −1 Original line number Original line Diff line number Diff line Loading @@ -65,7 +65,8 @@ public: /** /** * Start a new subscription. * Start a new subscription. */ */ void startNewSubscription(int inFd, int outFd, sp<IResultReceiver> resultReceiver); void startNewSubscription(int inFd, int outFd, sp<IResultReceiver> resultReceiver, int timeoutSec); void binderDied(const wp<IBinder>& who); void binderDied(const wp<IBinder>& who); Loading cmds/statsd/tests/shell/ShellSubscriber_test.cpp +1 −1 Original line number Original line Diff line number Diff line Loading @@ -83,7 +83,7 @@ void runShellTest(ShellSubscription config, sp<MockUidMap> uidMap, // mimic a binder thread that a shell subscriber runs on. it would block. // mimic a binder thread that a shell subscriber runs on. it would block. std::thread reader([&resultReceiver, &fds_config, &fds_data, &shellClient] { std::thread reader([&resultReceiver, &fds_config, &fds_data, &shellClient] { shellClient->startNewSubscription(fds_config[0], fds_data[1], resultReceiver); shellClient->startNewSubscription(fds_config[0], fds_data[1], resultReceiver, -1); }); }); reader.detach(); reader.detach(); Loading Loading
cmds/statsd/Android.bp +2 −0 Original line number Original line Diff line number Diff line Loading @@ -332,6 +332,8 @@ java_library { "src/stats_log.proto", "src/stats_log.proto", "src/statsd_config.proto", "src/statsd_config.proto", "src/atoms.proto", "src/atoms.proto", "src/shell/shell_config.proto", "src/shell/shell_data.proto", ], ], static_libs: [ static_libs: [ Loading
cmds/statsd/src/StatsService.cpp +5 −1 Original line number Original line Diff line number Diff line Loading @@ -360,7 +360,11 @@ status_t StatsService::command(int in, int out, int err, Vector<String8>& args, if (mShellSubscriber == nullptr) { if (mShellSubscriber == nullptr) { mShellSubscriber = new ShellSubscriber(mUidMap, mPullerManager); mShellSubscriber = new ShellSubscriber(mUidMap, mPullerManager); } } mShellSubscriber->startNewSubscription(in, out, resultReceiver); int timeoutSec = -1; if (argCount >= 2) { timeoutSec = atoi(args[1].c_str()); } mShellSubscriber->startNewSubscription(in, out, resultReceiver, timeoutSec); return NO_ERROR; return NO_ERROR; } } } } Loading
cmds/statsd/src/shell/ShellSubscriber.cpp +10 −2 Original line number Original line Diff line number Diff line Loading @@ -30,7 +30,8 @@ namespace statsd { const static int FIELD_ID_ATOM = 1; const static int FIELD_ID_ATOM = 1; void ShellSubscriber::startNewSubscription(int in, int out, sp<IResultReceiver> resultReceiver) { void ShellSubscriber::startNewSubscription(int in, int out, sp<IResultReceiver> resultReceiver, int timeoutSec) { VLOG("start new shell subscription"); VLOG("start new shell subscription"); { { std::lock_guard<std::mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex); Loading @@ -50,12 +51,19 @@ void ShellSubscriber::startNewSubscription(int in, int out, sp<IResultReceiver> // Read config forever until EOF is reached. Clients may send multiple configs -- each new // Read config forever until EOF is reached. Clients may send multiple configs -- each new // config replace the previous one. // config replace the previous one. readConfig(in); readConfig(in); VLOG("timeout : %d", timeoutSec); // Now we have read an EOF we now wait for the semaphore until the client exits. // Now we have read an EOF we now wait for the semaphore until the client exits. VLOG("Now wait for client to exit"); VLOG("Now wait for client to exit"); std::unique_lock<std::mutex> lk(mMutex); std::unique_lock<std::mutex> lk(mMutex); if (timeoutSec > 0) { mShellDied.wait_for(lk, timeoutSec * 1s, [this, resultReceiver] { return mResultReceiver != resultReceiver; }); } else { mShellDied.wait(lk, [this, resultReceiver] { return mResultReceiver != resultReceiver; }); mShellDied.wait(lk, [this, resultReceiver] { return mResultReceiver != resultReceiver; }); } } } void ShellSubscriber::updateConfig(const ShellSubscription& config) { void ShellSubscriber::updateConfig(const ShellSubscription& config) { std::lock_guard<std::mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex); Loading
cmds/statsd/src/shell/ShellSubscriber.h +2 −1 Original line number Original line Diff line number Diff line Loading @@ -65,7 +65,8 @@ public: /** /** * Start a new subscription. * Start a new subscription. */ */ void startNewSubscription(int inFd, int outFd, sp<IResultReceiver> resultReceiver); void startNewSubscription(int inFd, int outFd, sp<IResultReceiver> resultReceiver, int timeoutSec); void binderDied(const wp<IBinder>& who); void binderDied(const wp<IBinder>& who); Loading
cmds/statsd/tests/shell/ShellSubscriber_test.cpp +1 −1 Original line number Original line Diff line number Diff line Loading @@ -83,7 +83,7 @@ void runShellTest(ShellSubscription config, sp<MockUidMap> uidMap, // mimic a binder thread that a shell subscriber runs on. it would block. // mimic a binder thread that a shell subscriber runs on. it would block. std::thread reader([&resultReceiver, &fds_config, &fds_data, &shellClient] { std::thread reader([&resultReceiver, &fds_config, &fds_data, &shellClient] { shellClient->startNewSubscription(fds_config[0], fds_data[1], resultReceiver); shellClient->startNewSubscription(fds_config[0], fds_data[1], resultReceiver, -1); }); }); reader.detach(); reader.detach(); Loading