Commit Graph

212 Commits

Author SHA1 Message Date
Tej Singh
61f869e7bb Incident dump does not include current bucket
This is to avoid value metrics skipping buckets due to
DUMP_REPORT_REQUESTED, since if the metric needs to include the current
bucket under time constraints and needs to pull, it will drop the bucket
since it cannot pull.

Test: atest statsd_test
Bug: 158879346
Change-Id: Ia61e69530456ce2b3530add03ec6e068ffb25fb5
2020-06-12 17:25:17 -07:00
Ruchir Rastogi
04c3476986 Inject DeviceIdle atom before boot completes
Test: m
Test: manually verified that DeviceIdleModeStateChanged atom gets logged
before boot completes (using ag/11529814 to log)
Bug: 156913221
Change-Id: I3dbf154083f1cbe660625066dc50b6a8ffd60d7c
2020-05-27 17:43:39 +00:00
Tej Singh
7b975a85db Statsd: pull once per event time
If a pull happens at the same event time, we should reuse the existing
data, regardless of whether or not the cool down has been met. For
example, if an app upgrade happens at time t, and two metrics need to
pull atom a, if metric one pulls at time t, but metric two initiates the
pull at time t+2, we should still reuse the pull from time t since that
is when the app upgrade happened.

Bug: 156294650
Test: atest statsd_test

Change-Id: I4efc49545093f6683bf6dd89ed68c5dfa5b44d8f
2020-05-13 01:50:24 -07:00
Ruchir Rastogi
e92edbaffc Handle race conditions in SCS when statsd dies
This CL aims to fix two race conditions:

1. When statsd restarts after a crash, the ordering of sayHiToStatsd and
binderDied is not guaranteed. However, previously, we assumed that
binderDied would get called first and reset sStatsd to null. To solve,
we don't assume a function ordering and don't throw an error message in
sayHiToStatsd if sStatsd is not null.

2. When statsd was linked to death, the death recipient was not informed
about all broadcast receivers. Thus, the death recipient might have
known only a partial list of receivers when #binderDied was triggered. To
solve, we make sure that the death recipient knows about all receivers
before we link to death.

Test: atest statsd_test
Test: atest CtsStatsdHostTestCases
Bug: 154275510

Change-Id: I11be65ca2135cde200ab8ecb611a363d8f7c2eb6
2020-05-06 11:06:55 -07:00
Tej Singh
affc08a340 Merge "Split buckets on boot complete" into rvc-dev 2020-04-22 01:16:28 +00:00
Tej Singh
e678cb753a Split buckets on boot complete
Also clean up a bit of code on splitting on app upgrades

Piggy-backed off the app upgrade tests, adding parameterized tests to
also test boot complete event.

Refactored some value metric test code to increase code reuse and
assertions.

Fixed a broken value metric test that had assertions commented out.

Refactored NamedLatch into MultiConditionTrigger to avoid creating a
thread before necessary.

Test: atest statsd_test
Test: push a simple test config, reboot, wait, get data. Made sure
the bucket was split
Bug: 144099206
Bug: 154511974

Change-Id: I73858b5db08e8cda762bd8091b30da8738d1fd88
2020-04-21 15:31:14 -07:00
Jeffrey Huang
d8a7f947ba Remove IStatsd reference from StatsLog.java
Also remove sendAppBreadcrumb binder api because it's no longer used.

Bug: 154264326
Test: atest com.google.android.statsd.gts.StatsdHostTestCases
Change-Id: Ic51a057bb01a89a24337521a49c54a52e2073cd1
2020-04-21 15:04:28 -07:00
Tej Singh
769f35fc0f Add NamedLatch to statsd
This is a sychronizing primitive that is similar to a latch, but a
thread must count down with an identifier. It will be used to make sure
the boot complete, uid map, and all pullers signals are received before
triggering the bucket split.

The latch's countDown operation takes in a string identifier, so that if
the same operation happens twice, it is only counted once.

Bug: 144099206
Test: atest statsd_test

Change-Id: I261a3e50eabbc4998ca30ddf2d67a9a1e788911e
2020-04-14 16:50:12 -07:00
Jeffrey Huang
d8f533060d Send boot completed to statsd
Bug: 153384066
Test: m -j
Change-Id: I3f91241851a93d0869dad210bc278b3a1ba6b762
2020-04-09 17:29:19 -07:00
Jeffrey Huang
d7fda53855 Send puller registration signal to statsd
Bug: 153384066
Test: m -j
Change-Id: Idd2465d52e6720d7bce26ecc7998721b9d9790e3
2020-04-08 22:20:41 -07:00
Jeffrey Huang
898dda3919 Merge changes Icd1b1e57,Ib9c6b9b4 into rvc-dev
* changes:
  Load Metadata from Disk
  Save metadata to Disk
2020-04-01 18:56:26 +00:00
Jeffrey Huang
475677e771 Load Metadata from Disk
Bug: 148280505
Test: bit statsd_test:*
Test: Manual - Added Config, Tested System Server Crash
Test: Manual - Added Config, Tested Device restart
Change-Id: Icd1b1e57bbf24e4a5676820a2b955f2034d4b37d
2020-03-31 19:10:58 -07:00
Jeffrey Huang
b8f5403d17 Save metadata to Disk
Bug: 148280505
Test: bit statsd_test:*
Change-Id: Ib9c6b9b4f22e7380717b480c7ae4a37bb3364619
2020-03-31 19:10:58 -07:00
Tej Singh
3be093b518 Uid Sandboxing of Pullers
Overall flow of implementation:
1. parsing the config in MetricsManager to store the uids per atom. It
follows the mAllowedLogSources logic very closely
2. MetricsManager register itself as a PullUidProvider with the
PullerManager.
3. Metrics pass the config key when pulling (for both registering
receivers and normal pulls) , and the puller manager gets
the allowed uids from the PullUidProvider for that config.
4. PullerManager keys receivers by <atomId, configKey> so that it can
look up the uids for that atom using the PullUidProvider as well.
5. Added shell subscriber support. Hardcode a default of AID_SYSTEM for
them and also allow packages per atom. This involved adding a second
interface to Pull that simply accepts the uids, since I didnt want to
make the ShellSubscriber a PullUidProvider as well.
6. Change adb shell cmd stats pull-source to allow users to specify a
package. Default to AID_SYSTEM as well.

Notes:
The feature is flagged off right now, since configs do not pass in the
desired package. Another approach could be to hardcode in the current
mapping, but that doesn't work for OEM pulled atoms.

Test: m statsd
Test: bit statsd_test:* with useUids = false
Test: bit statsd_test:* with useUids = true
Bug: 144099783
Bug: 151978258

Change-Id: I4a7481d7402a52b9beb4ea28b102803f9e50e79f
2020-03-27 18:07:24 -07:00
Tej Singh
73597dcb9a Statsd update for native puller api feedback
Update statsd to take in times in milliseconds instead of nanoseconds.

Also make appropriate updates for graphics stats, odpm, subsystem sleep
state, and LibStatsPullTests

Test: atest LibStatsPullTests
Test: bit statsd_test:*
Bug: 150788562
Change-Id: I593552d6c50bb4dcb89ca9cc1c737781653e7cc5
2020-03-20 11:16:18 -07:00
Tej Singh
10458eca11 Enforce permission on native puller API
Test: m
Test: no security exceptions on boot
Test: atest LibStatsPullTests
Bug: 148955001
Change-Id: I4b06bfc41be2925270eaddd717f1499d98739dae
2020-03-19 11:54:11 -07:00
Jeffrey Huang
75274ad0fa Merge "Remove apex_available from libstatslog" into rvc-dev 2020-03-11 05:26:32 +00:00
Jeffrey Huang
74fc4354b5 Remove apex_available from libstatslog
Test: m -j
Bug: 149781190
Change-Id: I765852b1719a3056c06a0965ea6a05a8e8410693
2020-03-10 15:14:27 -07:00
Ruchir Rastogi
1497e8fdca Fix TODOs made during migration to libbinder_ndk
Test: atest GtsStatsdHostTestCases
Bug: 149254662
Change-Id: I50a1998e693f9a0c447cd655f8efa11afa28803b
2020-03-08 18:47:40 -07:00
Tej Singh
72a70a8a3c Address Puller API Feedback
1. Rename registerPullAtomCallback to setPullAtomCallback
2. Rename unregisterPullAtomCallback to clearPullAtomCallback
3. Add getters to PullAtomMetadata
4. Change Ns to Millis (when I tried to make it Nanos, I received a
built time error saying to prefer millis unless we need the precision.
We do not need the precision, so I changed it).
5. Fix out of order params.

I did not change usePooledBuffer to setPooledBuffer because I think use
is more appropriate for our use case.

Test: make
Test: atest PullAtomMetadataTest
Test: atest GtsStatsdHostTestCases
Bug: 149475498

Change-Id: Ib07aa57a6e02c77917fe0e65a3d4a77c00ce8565
2020-03-05 16:43:02 -08:00
Stanislav Zholnin
d7674c2be5 Fix bug in StatsService which prevents any shell command from execution.
Bug: 149691126
Test: adb shell cmd stats
Change-Id: I71befdd02e61de0f39cdff9694d4ab07abb1799c
2020-02-17 17:48:12 +00:00
Ruchir Rastogi
e449b0c185 Move statsd (and tests) to libbinder_ndk
Major changes include:
    - Removing unused permission checks within StatsService. These
      include ENFORCE_DUMP_AND_USAGE_STATS, checkDumpAndUsageStats,
      kOpUsage, and kPermissionUsage.
    - Converting from sp to shared_ptr
    - Using libbinder_ndk functions instead of libbinder functions
      (e.g. for installing death recipients, getting calling uids, etc.)
        - New death recipients were added in StatsService,
          ConfigManager, and SubscriberReporter.
    - Using a unique token (timestamp) to identify shell subscribers
      instead of IResultReceiver because IResultReceiver is not exposed by
      libbinder_ndk. Currently, statsd cannot detect if perfd dies; we
      will fix that later.

Bug: 145232107
Bug: 148609603
Test: m statsd
Test: m statsd_test
Test: bit stastd_test:*
Test: atest GtsStatsdHostTestCases
Change-Id: Ia1fda7280c22320bc4ebc8371acaadbe8eabcbd2
2020-02-14 18:07:37 -08:00
Jonathan Nguyen
703c42f695 Add support for multi train logging
Test: atest GtsStatsdHostTestCases
Change-Id: I4ca7089347d6dfab8a33c07acd5ef9c252413ec9
2020-02-07 16:03:05 -08:00
Jeffrey Huang
0e0313c399 Migrate StatsHal
Test: bit VtsHalStatsV1_0TargetTest:*
Bug: 148794952
Change-Id: I19ff6edf78bd84a95d8c0ae3a1adda99d4232aa5
2020-02-06 10:03:29 -08:00
Jonathan Nguyen
a0e6de15df Update StatsLogProcessor to handle BinaryPushStateChanged
Also changed StatsLog to call write() instead of the hard coded function
in StatsService.

Test: gts-tradefed run gts-dev --module GtsStatsdHostTestCases
Change-Id: I26171fa4cfc877e1e179b74ec8076d964aff8548
2020-02-04 20:09:26 -08:00
Jeffrey Huang
88b313eb4a Merge "Delete unused imports in Statsd" 2020-02-03 17:42:39 +00:00
Jeffrey Huang
cabd127c19 Delete unused imports in Statsd
Delete libplatformprotos since its not used.

Test: m -j
Bug: 147599928
Change-Id: I80203756d714bf123978d26bbe81351a1abdc967
2020-02-01 10:41:43 -08:00
Ruchir Rastogi
0563e3b1f4 statsd checks permissions using SCS
The checkCallingPermission function is not supported by libbinder_ndk.
To circumvent this issue, statsd will now ask StatsCompanionService
(SCS) to do that check using a synchronous Binder call. Once
libbinder_ndk does support checkCallingPermission, this workaround will
be unnecessary.

Test: m -j
Test: atest GtsStatsdHostTestCases
Bug: 145566180
Change-Id: I11f0e82f88aa5921cf531fd041b0a18d3a26a0a0
2020-01-30 18:18:33 -08:00
Jeffrey Huang
67ad2e7a55 Delete References to Statsd in StatsManager
Test: adb shell cmd stats pull-source 10000 (chosen randomly)
Change-Id: I9578f84213e6c2787da60ae7e2c20157087d5b6a
2020-01-17 13:28:27 -08:00
Tej Singh
8f3586051b Unregister native pull atom callback
Statsd changes to unregister a native puller.

Bug:14437325
Test: builds, boots
Change-Id: I1a1841de6e913f681c51919fcb9b18e30eb37801
2020-01-15 16:20:48 -08:00
Jeffrey Huang
2f18c0a548 Keep subscibers when configs are deleted
Test: GTS Tests
Bug: 146383400
Change-Id: I1e92a5233dbdceff88b18ab394e6b6dc06be9023
2020-01-08 13:20:32 -08:00
Jeffrey Huang
94eafe74a3 Update Add/Remove Configuration
Test: GTS Tests
Bug: 146383400
Change-Id: Ibcd6802468fa3be3ffde4357b37060711deff9b3
2020-01-08 10:52:25 -08:00
Jeffrey Huang
04f948b450 Update getReports
Test: GTS Tests
Bug: 146383638
Change-Id: Id640e568d41c5f30e7c42a06addfba644061c706
2020-01-07 17:15:52 -08:00
Jeffrey Huang
9613a973a2 Update getStatsMetadata
Test: GTS Tests
Bug: 146384074
Change-Id: I263489874616d4ed5d16f2796fa74c740059a35a
2020-01-07 17:15:52 -08:00
Jeffrey Huang
80c9a975d7 Update getRegisteredExperimentIds
Bug: 146384076
Test: GTS Tests
Change-Id: I9da3526d97d5adef423c69366f50fac59a1d6247
2020-01-07 17:15:51 -08:00
Jeffrey Huang
4f2e6bd68d Update setBroadcastSubscriber
change #setBroadcastSubscriber and #unsetBroadcastSubscriber
to avoid using intentsender

Bug: 146074295
Test: Ran GTS Tests
Change-Id: I1510e44bcdf49b579fd49f51081c6a40618039fa
2020-01-06 16:25:41 -08:00
Jeffrey Huang
47537a1c58 Update activeConfigsChangedBroadcast
avoid using intentsender in #sendActiveConfigsChangedBroadcast
and #removeActiveConfigsChangedBroadcast.

Bug: 146074295
Test: Ran GTS Tests
Change-Id: I9313299ea0bc89f092b1c62fbfc34e06a127eaa9
2020-01-06 16:25:41 -08:00
Jeffrey Huang
ad21374842 Creating PendingIntentRef
Update #setDataFetchOperation to avoid using intentsender.

Bug: 146074295
Test: Ran GTS Tests
Change-Id: I7df5c6441725aa4e46fac18925664c9455f50fb9
2020-01-06 16:25:41 -08:00
Tej Singh
fa1c137d66 Allow pullAtomCallbacks to be unregistered in Java
Adds an API to unregister pullAtomCallbacks.
Fixes bug where the StatsEventParcels are null.
Makes onPullAtom a oneway call.
OnPullAtom returns an int code instead of a boolean
Made the APIs return RuntimeExceptions

Test: make, boots
Test: atest GtsStatsdHostTestCases
Bug: 146385842
Bug: 146385173
Bug: 144373250
Change-Id: I107a705a9024240c5c9f9e276293de8410e2b6f3
2019-12-18 18:52:10 -08:00
Jeffrey Huang
161c075d99 Rename IStatsManager to IStatsd
Bug: 146075178
Test: CTS/GTS tests
Change-Id: I235944758b8cc24a0df85b54d7441e7e8d0a8bbc
2019-12-11 15:49:03 -08:00
Gavin Corkery
dd1dabaef7 Log watchdog-initiated rollback reason
To help with monitoring Mainline releases, log the reason
for a watchdog-initiated rollback. This may be due to
native crashes, app crashes, ANRs or explicit health check
failures.

Add a mapping from PackageWatchdog failure reason to the
new metrics.

Bug: 138782888
Test: atest PackageWatchdogTest
Test: atest StatsdHostTestCases
Change-Id: Ia3e73d955508297004591eac762555665c557b8a
2019-12-09 10:40:01 +00:00
TreeHugger Robot
addd10c6d2 Merge "Binder API for native pulled atoms" 2019-12-06 18:30:36 +00:00
Jeff Sharkey
6bd2157b55 Add statistics logging for MediaProvider.
As part of becoming a Mainline module, we need to understand basic
information about the health of our module in the wild.  For the
MediaProvider module, we're interested in identifying these cases:

-- When scan operations result in an unexpectedly large number of
inserts, updates, or deletes in proportion to the total number of
files indexed.  This typically indicates user data loss or a missing
database upgrade step.

-- When the overall duration of scan operations becomes significantly
slower in relation to the number of files indexed.  This typically
indicates an indexing performance regression.

-- When a scan operation skips over an entire directory tree.  This
can indicate an app placing ".nomedia" files in unexpected locations.

-- When a large number of media files are deleted by a specific
app.  This can help identify data loss bugs caused by MediaProvider
directly, or attribute data loss bugs in other apps.

-- When database upgrade/downgrade operations take a substantial
amount of time in proportion to the total number of files.  This
typically indicates a performance regression.

-- When performing idle maintenance, a large number of stale or
expiring media can indicate an invalidation bug.

Bug: 143723019
Test: manual
Change-Id: I89c5b5b51a843a67348a7bb4b8e6ac01fb2b15b9
2019-12-05 11:36:58 -07:00
Tej Singh
b780251111 Binder API for native pulled atoms
Native pullers dont go through statscompanion, so statsd has to get the
calling uid.

Test: make
Change-Id: I21e12fd94a66e700b11dfadcb8b122738873e44c
2019-12-04 17:57:04 -08:00
TreeHugger Robot
339650b132 Merge "Statsd implementation of puller API" 2019-11-20 00:26:50 +00:00
Tej Singh
6a5c94364c Statsd implementation of puller API
Internal implementation of the puller API. Registers pullers by putting
them in the kAllPullAtomInfo map. Implements the actual pull,
with condition variables to timeout.

Lastly, keys the kAllPullAtom info by a PullerKey, which is a uid and
atom id. However, the uid is just set to a default of -1 for now. I will
work the security implementation in a follow up CL.
Test: builds, boots
Test: I will write unit tests in the future. It's very difficult to
write any without StatsEvent being completed.

Change-Id: Id602dd297b6ba7df811e2d5ab2e77efc0684e418
2019-11-19 14:32:49 -08:00
Tej Singh
9ec159ac1f Fix Race Condition
Currently, it is possible for two threads in statsd to concurrently
access/modify memory in ConditionTrackers since they do not have locks.
This happens when one thread is processing LogEvents (lock on
StatsLogProcessor mutex), while the other thread receives uidmap updates
and locks on the mutex in the MetricProducer. This Cl changes uidmap
updates to also go through the mutex in StatsLogProcessor.

Test: bit statsd_test:*
Test: atest CtsStatsdHostTestCases
Test: local test (ag/9725088) that forced the race condition now passes
Bug: 144373785
Change-Id: I04ae2f7ed025f5ce8bc4fdeb7f10717e20d76282
2019-11-18 17:26:57 -08:00
Tej Singh
5918429fa2 Java API for pulled atoms
This creates a java API for registering pullers. Will implement the
statsd side in a follow up CL.

Test: builds, boots
Change-Id: Ib6735984297ce3148839a6370a3c15b2a585baf5
2019-11-13 13:22:27 -08:00
Tej Singh
c9250ceb3d Security Fix: Race Condition + NPE
ShellSubscriber is lazily initialized, and multiple threads can attempt
to write the same pointer since it is not initialized in threadsafe
code. Additionally, there is an NPE that crashes statsd when a null
ResultReceiver is passed in, which allows an attacker to repeatedly
crash statsd until the race condition occurs. More details, including a
proof of concept attack, are in the bug.

Bug: 141243101
Test: repro steps in bug no longer crash statsd
Test: with only the lock on iniitiallizing mShellSubscriber, statsd
still crashed but after ~7 minutes, no race condition occurred.

Change-Id: Ib56f888620497fb41d1627c07867693eb251738e
2019-09-20 19:28:53 -07:00
TreeHugger Robot
585422a5d2 Merge "Fixes the bug that can occur when StatsCompanionService calls StatsService to update UID data and overflows kernel transfer buffer." into qt-dev 2019-05-24 00:26:19 +00:00