Loading apex/statsd/tests/libstatspull/src/com/android/internal/os/statsd/libstats/LibStatsPullTests.java +4 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import androidx.test.runner.AndroidJUnit4; import com.android.internal.os.StatsdConfigProto.AtomMatcher; import com.android.internal.os.StatsdConfigProto.FieldFilter; import com.android.internal.os.StatsdConfigProto.GaugeMetric; import com.android.internal.os.StatsdConfigProto.PullAtomPackages; import com.android.internal.os.StatsdConfigProto.SimpleAtomMatcher; import com.android.internal.os.StatsdConfigProto.StatsdConfig; import com.android.internal.os.StatsdConfigProto.TimeUnit; Loading Loading @@ -271,6 +272,9 @@ public class LibStatsPullTests { .setSamplingType(GaugeMetric.SamplingType.FIRST_N_SAMPLES) .setMaxNumGaugeAtomsPerBucket(1000) ) .addPullAtomPackages(PullAtomPackages.newBuilder() .setAtomId(PULL_ATOM_TAG) .addPackages(LibStatsPullTests.class.getPackage().getName())) .build(); statsManager.addConfig(sConfigId, config.toByteArray()); assertThat(StatsConfigUtils.verifyValidConfigExists(statsManager, sConfigId)).isTrue(); Loading cmds/statsd/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -333,6 +333,7 @@ cc_test { "tests/external/puller_util_test.cpp", "tests/external/StatsCallbackPuller_test.cpp", "tests/external/StatsPuller_test.cpp", "tests/external/StatsPullerManager_test.cpp", "tests/FieldValue_test.cpp", "tests/guardrail/StatsdStats_test.cpp", "tests/indexed_priority_queue_test.cpp", Loading cmds/statsd/src/StatsLogProcessor.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -536,6 +536,7 @@ void StatsLogProcessor::OnConfigUpdatedLocked( new MetricsManager(key, config, mTimeBaseNs, timestampNs, mUidMap, mPullerManager, mAnomalyAlarmMonitor, mPeriodicAlarmMonitor); if (newMetricsManager->isConfigValid()) { newMetricsManager->init(); mUidMap->OnConfigUpdated(key); newMetricsManager->refreshTtl(timestampNs); mMetricsManagers[key] = newMetricsManager; Loading cmds/statsd/src/StatsService.cpp +19 −4 Original line number Diff line number Diff line Loading @@ -385,9 +385,11 @@ void StatsService::print_cmd_help(int out) { dprintf(out, " PKG Optional package name to print the uids of the package\n"); dprintf(out, "\n"); dprintf(out, "\n"); dprintf(out, "usage: adb shell cmd stats pull-source [int] \n"); dprintf(out, "usage: adb shell cmd stats pull-source ATOM_TAG [PACKAGE] \n"); dprintf(out, "\n"); dprintf(out, " Prints the output of a pulled metrics source (int indicates source)\n"); dprintf(out, " Prints the output of a pulled atom\n"); dprintf(out, " UID The atom to pull\n"); dprintf(out, " PACKAGE The package to pull from. Default is AID_SYSTEM\n"); dprintf(out, "\n"); dprintf(out, "\n"); dprintf(out, "usage: adb shell cmd stats write-to-disk \n"); Loading Loading @@ -806,8 +808,21 @@ status_t StatsService::cmd_log_binary_push(int out, const Vector<String8>& args) status_t StatsService::cmd_print_pulled_metrics(int out, const Vector<String8>& args) { int s = atoi(args[1].c_str()); vector<int32_t> uids; if (args.size() > 2) { string package = string(args[2].c_str()); auto it = UidMap::sAidToUidMapping.find(package); if (it != UidMap::sAidToUidMapping.end()) { uids.push_back(it->second); } else { set<int32_t> uids_set = mUidMap->getAppUid(package); uids.insert(uids.end(), uids_set.begin(), uids_set.end()); } } else { uids.push_back(AID_SYSTEM); } vector<shared_ptr<LogEvent>> stats; if (mPullerManager->Pull(s, &stats)) { if (mPullerManager->Pull(s, uids, &stats)) { for (const auto& it : stats) { dprintf(out, "Pull from %d: %s\n", s, it->ToString().c_str()); } Loading cmds/statsd/src/external/PullUidProvider.h 0 → 100644 +39 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <utils/RefBase.h> #include "StatsPuller.h" #include "logd/LogEvent.h" namespace android { namespace os { namespace statsd { class PullUidProvider : virtual public RefBase { public: virtual ~PullUidProvider() {} /** * @param atomId The atom for which to get the uids. */ virtual vector<int32_t> getPullAtomUids(int32_t atomId) = 0; }; } // namespace statsd } // namespace os } // namespace android Loading
apex/statsd/tests/libstatspull/src/com/android/internal/os/statsd/libstats/LibStatsPullTests.java +4 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import androidx.test.runner.AndroidJUnit4; import com.android.internal.os.StatsdConfigProto.AtomMatcher; import com.android.internal.os.StatsdConfigProto.FieldFilter; import com.android.internal.os.StatsdConfigProto.GaugeMetric; import com.android.internal.os.StatsdConfigProto.PullAtomPackages; import com.android.internal.os.StatsdConfigProto.SimpleAtomMatcher; import com.android.internal.os.StatsdConfigProto.StatsdConfig; import com.android.internal.os.StatsdConfigProto.TimeUnit; Loading Loading @@ -271,6 +272,9 @@ public class LibStatsPullTests { .setSamplingType(GaugeMetric.SamplingType.FIRST_N_SAMPLES) .setMaxNumGaugeAtomsPerBucket(1000) ) .addPullAtomPackages(PullAtomPackages.newBuilder() .setAtomId(PULL_ATOM_TAG) .addPackages(LibStatsPullTests.class.getPackage().getName())) .build(); statsManager.addConfig(sConfigId, config.toByteArray()); assertThat(StatsConfigUtils.verifyValidConfigExists(statsManager, sConfigId)).isTrue(); Loading
cmds/statsd/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -333,6 +333,7 @@ cc_test { "tests/external/puller_util_test.cpp", "tests/external/StatsCallbackPuller_test.cpp", "tests/external/StatsPuller_test.cpp", "tests/external/StatsPullerManager_test.cpp", "tests/FieldValue_test.cpp", "tests/guardrail/StatsdStats_test.cpp", "tests/indexed_priority_queue_test.cpp", Loading
cmds/statsd/src/StatsLogProcessor.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -536,6 +536,7 @@ void StatsLogProcessor::OnConfigUpdatedLocked( new MetricsManager(key, config, mTimeBaseNs, timestampNs, mUidMap, mPullerManager, mAnomalyAlarmMonitor, mPeriodicAlarmMonitor); if (newMetricsManager->isConfigValid()) { newMetricsManager->init(); mUidMap->OnConfigUpdated(key); newMetricsManager->refreshTtl(timestampNs); mMetricsManagers[key] = newMetricsManager; Loading
cmds/statsd/src/StatsService.cpp +19 −4 Original line number Diff line number Diff line Loading @@ -385,9 +385,11 @@ void StatsService::print_cmd_help(int out) { dprintf(out, " PKG Optional package name to print the uids of the package\n"); dprintf(out, "\n"); dprintf(out, "\n"); dprintf(out, "usage: adb shell cmd stats pull-source [int] \n"); dprintf(out, "usage: adb shell cmd stats pull-source ATOM_TAG [PACKAGE] \n"); dprintf(out, "\n"); dprintf(out, " Prints the output of a pulled metrics source (int indicates source)\n"); dprintf(out, " Prints the output of a pulled atom\n"); dprintf(out, " UID The atom to pull\n"); dprintf(out, " PACKAGE The package to pull from. Default is AID_SYSTEM\n"); dprintf(out, "\n"); dprintf(out, "\n"); dprintf(out, "usage: adb shell cmd stats write-to-disk \n"); Loading Loading @@ -806,8 +808,21 @@ status_t StatsService::cmd_log_binary_push(int out, const Vector<String8>& args) status_t StatsService::cmd_print_pulled_metrics(int out, const Vector<String8>& args) { int s = atoi(args[1].c_str()); vector<int32_t> uids; if (args.size() > 2) { string package = string(args[2].c_str()); auto it = UidMap::sAidToUidMapping.find(package); if (it != UidMap::sAidToUidMapping.end()) { uids.push_back(it->second); } else { set<int32_t> uids_set = mUidMap->getAppUid(package); uids.insert(uids.end(), uids_set.begin(), uids_set.end()); } } else { uids.push_back(AID_SYSTEM); } vector<shared_ptr<LogEvent>> stats; if (mPullerManager->Pull(s, &stats)) { if (mPullerManager->Pull(s, uids, &stats)) { for (const auto& it : stats) { dprintf(out, "Pull from %d: %s\n", s, it->ToString().c_str()); } Loading
cmds/statsd/src/external/PullUidProvider.h 0 → 100644 +39 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <utils/RefBase.h> #include "StatsPuller.h" #include "logd/LogEvent.h" namespace android { namespace os { namespace statsd { class PullUidProvider : virtual public RefBase { public: virtual ~PullUidProvider() {} /** * @param atomId The atom for which to get the uids. */ virtual vector<int32_t> getPullAtomUids(int32_t atomId) = 0; }; } // namespace statsd } // namespace os } // namespace android