Commit Graph

452 Commits

Author SHA1 Message Date
Ruchir Rastogi
0a60d240e5 Merge "Fix ShellSubscriber concurrency issues" into rvc-dev am: ca7fc3be0f
Change-Id: I66e1a0a3500328a037714d8b678081d97c4caaad
2020-05-07 23:36:55 +00:00
Ruchir Rastogi
ca7fc3be0f Merge "Fix ShellSubscriber concurrency issues" into rvc-dev 2020-05-07 23:22:56 +00:00
Ruchir Rastogi
1e24051604 Fix ShellSubscriber concurrency issues
This CL creates a sendHeartbeat thread that ocassionally sends
heartbeats, consisting of a dataSize of 0, to perfd. perfd will discard
those heartbeats, recheck if the user has canceled the subscription, and
if not, wait for more data from statsd. Sending heartbeats solves two
big problems:

(1) Allows statsd to robustly check if writes to the socket fail because
the read end of the pipe has closed. Previously, if no atoms were pushed
or pulled, statsd never attempted to write to perfd, so statsd could
never detect the end of the subscription. However, now, writes are
regularly made regardless of if statsd receives data. Note that even if
atoms were pushed or pulled, there is no guarantee that they would have
matched the atom matchers sent in perfd's config.

(2) Allows perfd to escape a blocking read call and recheck whether the
user has canceled the subscription. If no data is sent to perfd, perfd
will block in this read call and the AndroidStudio UI will freeze up.

Heartbeats are only sent if statsd has not sent any data to perfd within
the last second, so we do not spam perfd with writes.

+ decomposes the startNewSubscription function
+ prevents startPull from holding the lock while sleeping

Test: atest stastd_test
Test: atest CtsStatsdHostTestCases
Test: manually confirm that AndroidStudio is not freezing
Bug: 153595161

Change-Id: I78f0818e8ed29bdadd02c151444ee7c9555623a4
2020-05-06 19:52:16 -07:00
Tej Singh
7c0e804554 Merge "Improve statsdstats logging for pulled atoms" into rvc-dev am: c9dad09ad3
Change-Id: Ic4bca19eaaa7e12b24969572bbfc901440035fa3
2020-05-06 22:30:25 +00:00
Tej Singh
873e91a117 Improve statsdstats logging for pulled atoms
1. remove old statscompanion counters
2. add outgoing binder call fail counts
3. Add additional pull failure cases
 a. No pull uid provider (If a config doesn't register properly)
 b. Puller not found - either because it was not registered or because
the client did not specify the correct uids
4. Make metrics own logging pull delays - these were getting overcounted
since both the PullerManager and ValueMetricProducer were logging pull
delays.
5. Move noteEmptyPull to StatsPuller for more uniform logging, instead
of it just being logged in value metric producer.

Test: m statsd
Bug: 154056912
Change-Id: Ia373003905ee44d3b7b37b2bfa1e1d6268250070
2020-05-05 19:03:52 -07:00
TreeHugger Robot
9ea0c17a4f Merge "Add tests for mapIsolatedUidToHostUid methods" into rvc-dev am: a8ba45dd80
Change-Id: Ic6442cce133a6d0dc1ed0c85c817c136ee3cf5eb
2020-04-29 19:28:58 +00:00
Muhammad Qureshi
b635b3a2eb Add tests for mapIsolatedUidToHostUid methods
- Remove unneeded dependency on atoms.proto
- Remove extractIntoVector function. Assert on actual output directly.
- Use a helper method for creating UidMap mock for all tests.
- Add AttributionChain variants of existing tests in puller_util_tests.
- Add tests in StatsLogProcessor_test to test mapIsolatedUidToHostUid()
    in StatsLogProcessor.

Bug: 154285085
Test: bit statsd_test:*

Change-Id: I6d0822be9f0fbca23bd2f441dc63b97110567307
2020-04-29 09:58:03 -07:00
Muhammad Qureshi
fe9900ae2a Merge "Add LogEvent::hasAttributionChain()" into rvc-dev am: 59602e5342
Change-Id: Ia791cf9f6f729f87007df8e83aff4e00a2d6898e
2020-04-23 21:13:56 +00:00
Muhammad Qureshi
59602e5342 Merge "Add LogEvent::hasAttributionChain()" into rvc-dev 2020-04-23 21:12:56 +00:00
Muhammad Qureshi
83aaa66b46 Add LogEvent::hasAttributionChain()
Optionally, accept a std::pair<int, int>* that is populated with the
starting and ending indices of attribution nodes in FieldValues vector.

Bug: 154286011
Test: bit statsd_test:*
Change-Id: I6f19abea7fbb27712b6c2d5a7679aa4f428c191d
2020-04-22 10:17:14 -07:00
Tej Singh
94fefce9e7 Merge "Fix PullUidProvider unregistering on config update" into rvc-dev am: 7df1a94f78
Change-Id: Ib9c690672a42993dbaf429551621e67119420894
2020-04-22 05:46:17 +00:00
Tej Singh
3eb9cede0b Fix PullUidProvider unregistering on config update
Previously, MetricsManagers would unregister themselves as a
PullUidProvider for a given ConfigKey in the destructor. This caused all
pulls to fail after a config update because the new MetricsManager would
register itself before the old MetricsManager was destructed and
unregistered. This resulted in the old MetricsManager removing the new
config since they shared the same config key. The fix is for the
PullerManager to check that the PullUidProviders are equal in the
unregister function before actually erasing it.

Test: bit statsd_test:* (wrote a failing test that now passes).
Test: statsd_localdrive to manually update a config, ensured pulls still
worked.
Bug: 154544328

Change-Id: Id7af3b3b407e24bee74fc34bd1c2b9e0575e9c9e
2020-04-21 20:24:26 -07:00
Tej Singh
5bd209a9c2 Merge "Split buckets on boot complete" into rvc-dev am: affc08a340
Change-Id: Ie2727d557afa8f602fc2045a849ec0f8f09ef62d
2020-04-22 01:35:27 +00: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
Ruchir Rastogi
17bc49e4a9 Merge "Handle errors within LogEvent" into rvc-dev am: 3360c54cd6
Change-Id: I9bd7230cedf4ccee8e9940a29f073e55cefcdce8
2020-04-21 17:08:41 +00:00
Ruchir Rastogi
3360c54cd6 Merge "Handle errors within LogEvent" into rvc-dev 2020-04-21 17:07:18 +00:00
Ruchir Rastogi
f9bfc10128 Merge "Move resetState from FieldValue to LogEvent" into rvc-dev am: b639065e0a
Change-Id: I85c434673efabaf9532c4087e5c57b1fe28f7f11
2020-04-21 17:06:36 +00:00
Ruchir Rastogi
48dbf835ce Move resetState from FieldValue to LogEvent
This helps save memory because FieldValues are copied around much more
than LogEvents.

+ removed unused variables from LogEvent

Test: bit statsd_test:*
Bug: 154267590
Change-Id: If444ef79c85a45526fce183b67d9d8a2e74fa10d
2020-04-20 17:43:56 -07:00
Ruchir Rastogi
07f7adb47e Handle errors within LogEvent
Errors are recorded within StatsdStats. The associated CL to change
stats_log.proto within google3 is at cr/306795778.

Test: adb shell dumpsys stats --metadata
Test: bit statsd_test:*
Bug: 144373276
Change-Id: Id80cace9350f77d64a2d401f7fac7b12501e82ee
2020-04-19 14:42:02 -07:00
Muhammad Qureshi
b7cee13a26 Merge "Remove kMaxPushedAtomId from atoms_info." into rvc-dev am: e3ef95cf13
Change-Id: Iff16f161dccbe653331d378660730a268c6c50fb
2020-04-18 00:24:01 +00:00
Muhammad Qureshi
cdf291d297 Remove kMaxPushedAtomId from atoms_info.
Hardcode kMaxPushedAtomId in StatsdStats.

Bug: 154164020
Test: bit statsd_test:*
Change-Id: Ibca731d9783686a9e3caf0ad580e1d62038d68e2
2020-04-17 10:10:17 -07:00
Muhammad Qureshi
c5e48b53b3 Merge "Remove kStateAtomsInfo from atoms_info." into rvc-dev am: 1f976bf634
Change-Id: Idcb6b9e407c99d76579ce8184df800f4fd9cb575
2020-04-16 13:16:50 +00:00
Muhammad Qureshi
1f976bf634 Merge "Remove kStateAtomsInfo from atoms_info." into rvc-dev 2020-04-16 13:01:52 +00:00
TreeHugger Robot
76921f8385 Merge "Add NamedLatch to statsd" into rvc-dev am: 259e20acec
Change-Id: I94fed053d5d785413989d532fd7f60a8adde4320
2020-04-15 17:02:05 +00:00
Muhammad Qureshi
bfc4bdb594 Remove kStateAtomsInfo from atoms_info.
Use the annotation information in LogEvent/FieldValue instead.

- Initialize nested to true in FieldValue.mAnnotations

- Add filterPrimaryKey function to HashableDimensionKey for populating a
HashableDimensionKey with all FieldValues that have the primary key
annotation set.

- Create StateTrackers without checking if atom is a state atom. (We
  can't do this check anymore)

- Remove mAtomId, mStateField, mNested, mPrimaryFields, mDefaultState,
    mResetState members from StateTracker. Use the information passed in
    LogEvent in onLogEvent instead.

- Update tests to log annotations when logging events.

- Remote kStateAtomsFieldOptions from atoms_info.

- Make MetricProducer::mStateGroupMap const

- Rename handlePartialReset to clearStateForPrimaryKey

- Store "default" states in mStateMap. An entry in mStateMap means the
state is not kStateUnknown. Before, an entry in mStateMap meant the
state is not the "default" state.

- Consolidate all state change logic in updateStateForPrimaryKey()
    - remote StateTracker::updateState
    - handleReset and clearStateForPrimaryKey call
    updateStateForPrimaryKey for resetting and clearing of states
    respectively.

- Create a helper method for notifying StateTracker listeners

- Make StateManager::registerListener void

Bug: 151110842
Test: bit statsd_test:*
Change-Id: Ifb8371b213a178fcccaa484086fbdd283dbaec49
2020-04-14 17:22:15 -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
Tej Singh
87ec853fc5 Merge "Statsd test mapping" into rvc-dev am: e715d2f0e7
Change-Id: Ifc878609b5c2af658014e6391434b7c0e8c0c02b
2020-04-11 04:08:55 +00:00
Tej Singh
e715d2f0e7 Merge "Statsd test mapping" into rvc-dev 2020-04-11 03:49:17 +00:00
Tej Singh
5d823b30fa Statsd test mapping
Makes a test mapping for statsd so that unit tests run on presubmit.

Changes to make the tests pass:
1. Require root. This is needed to write to disk, since the tests don't
run as statsd's uid

2. Remove AndroidTest.xml file in favor of the autogenerated one.

3. Remove a check in StatsService.test for getUidFromArgs. The test
checked a failure case where we passed a number bigger than INT32_MAX.
However, on a 32 bit device, strtol will return INT32_MAX when an
overflow happens, since it returns a 32 bit number on a 32 bit device.

4. Refactor a lot of e2e tests to sort dimensions, ensuring that the
dimensions are always in order, instead of relying on implicit ordering
of hashing, which can change.

5. Change a long to an int64 in TestActivationsPersistAcrossSystemServerRestart

Test: statsd_test
Bug: 129613474
Change-Id: I80dfa3bfd50ebe6d2c8c0c3ba201f3ad06b68910
2020-04-09 22:20:59 -07:00
TreeHugger Robot
52131232ec Merge "Remove kAtomsWithUidField from atoms_info" into rvc-dev am: 04d2f143cd
Change-Id: I5963ad3025035ccae82a558783dcd27f1bd4592f
2020-04-09 06:06:26 +00:00
Ruchir Rastogi
ffa34f05cf Remove kAtomsWithUidField from atoms_info
Instead of using the map from atoms_info, we now receive uid information
in the form of StatsEvent annotations. The isUid annotation is exposed
from both LogEvent and FieldValue.

Test: bit statsd_test:*
Test: atest GtsStatsdHostTestCases
Bug: 150414601
Change-Id: Iebbe4ce5668de1ab91485daa1be9197cde6e8309
2020-04-08 19:09:33 -07:00
Christine Tsai
3b6305f27d Merge "statsd unit test and benchmark refactor" into rvc-dev am: 5205e14500
Change-Id: I20716e10a5addf86afa3fc83af37bc63e13771d0
2020-04-08 23:24:20 +00:00
Christine Tsai
5205e14500 Merge "statsd unit test and benchmark refactor" into rvc-dev 2020-04-08 23:09:17 +00:00
TreeHugger Robot
8c2b42dda8 Merge "Fix AIBinder_linkToDeath cookies" into rvc-dev am: 7284bf15da
Change-Id: Icd015d4f3d92a2f908e470e4d30cf1c4ab578d9c
2020-04-08 19:06:32 +00:00
tsaichristine
8dca82ed94 statsd unit test and benchmark refactor
Abstract test utilities into two new functions: writeAttribution and
parseStatsEventToLogEvent

Bug: 149590301
Test: bit statsd_test:*
&& bit statsd_benchmark:*

Change-Id: I5f77646b6d2d828344b8b6de8777a60d98f96d58
2020-04-08 11:48:09 -07:00
Ruchir Rastogi
e20c53e5b1 Fix AIBinder_linkToDeath cookies
StatsPullerManager should be declared on the heap because wp's can only
point to objects on the heap.

Test: bit statsd_test:*
Test: atest GtsStatsdHostTestCases
Test: atest CtsStatsdHostTestCases
Bug: 153237308
Change-Id: I579375f5bd2db9557f108f39916d69f368865478
2020-04-08 10:07:48 -07:00
TreeHugger Robot
38950a11a4 Merge "Make state_option top-level boolean annotations" into rvc-dev am: 4e83de27c2
Change-Id: Ib507bb59dbb29e10e41bf4a5fa95dd69cdc3d45e
2020-04-04 05:29:30 +00:00
Muhammad Qureshi
3f9c330eef Make state_option top-level boolean annotations
- Add AnnotationId enum stats-log-api-gen
- Rename RESET_STATE annotation to TRIGGER_STATE_RESET. Also rename the proto annotation.

Bug: 152412767
Test: stats-log-api-gen-test
Test: m statslog-framework-java-gen
Change-Id: I2c12ea0b9222ef28b8cc11ea36b272e518a96259
2020-04-03 17:00:55 -07:00
Christine Tsai
9219793158 Merge "Clean up unused LogEvent constructors" into rvc-dev am: f3d5e7329b
Change-Id: I2450c2ff6c35018fcc36937adff5be376076c13a
2020-04-03 21:20:20 +00:00
Christine Tsai
f3d5e7329b Merge "Clean up unused LogEvent constructors" into rvc-dev 2020-04-03 21:03:57 +00:00
tsaichristine
c7911dd000 Clean up unused LogEvent constructors
After switching to the new socket schema, we can remove certain LogEvent
constructors. AttributionNodeInternal was only used in tests and can be
removed as well.

Bug: 14959031
Test: bit statsd_test:*
Change-Id: Ib5cb6acc50cc4d37a46a076d41face452a0a87d8
2020-04-03 12:12:24 -07:00
Christine Tsai
79ece503f4 Merge "Remove StateConditionTracker from statsd" into rvc-dev am: d4abb2f9ff
Change-Id: Id010582069e9a0d389e522ccb38b653e1c6f8fa9
2020-04-03 18:20:05 +00:00
Christine Tsai
d4abb2f9ff Merge "Remove StateConditionTracker from statsd" into rvc-dev 2020-04-03 18:13:06 +00:00
tsaichristine
3d8e12a5ef Remove StateConditionTracker from statsd
StateConditionTracker was previously used as a way to slice by state
through a specific SimplePredicate definition. It is currently being
replaced by StateTracker, and no metrics use StateConditionTracker at
this time.

Bug: 136566566
Test: bit statsd_test:*
Change-Id: I1a14747907c23482a1b7500c6d7f07cd2f1d4aed
2020-04-03 09:41:52 -07:00
Christine Tsai
b5bfcffbb1 Merge "Slice by state in DurationMetricProducer" into rvc-dev am: 8ad7c0ec42
Change-Id: I7c77e56f533b42dbffb4a55138523d2340a19554
2020-04-03 00:48:35 +00:00
tsaichristine
1449fa4661 Slice by state in DurationMetricProducer
- Added #onStateChanged logic to DurationMetricProducer
- Only SUM aggregation type supports state slicing.
OringDurationTrackers now track durations keyed by different state
values.
- Added unit tests for DurationMetricProducer state changes

Test: bit statsd_test:*
Bug: 145838038
Bug: 136566566
Change-Id: I87dcc21bb904ef0fa76ea196d60dadae00f310fa
Merged-In: I735c7deee96639c32cad4b907e59b354dfd98d77
2020-04-02 14:53:40 -07:00
Ruchir Rastogi
4d27d3629a Merge "Store annotation info in LogEvent/FieldValue" into rvc-dev am: c0a892456b
Change-Id: I83ea7be93892f2c5f6a704c0beb63f2e8db66a6f
2020-04-02 16:05:49 +00:00
Ruchir Rastogi
c0a892456b Merge "Store annotation info in LogEvent/FieldValue" into rvc-dev 2020-04-02 15:49:22 +00:00
Jeffrey Huang
d6960d80f1 Merge changes Icd1b1e57,Ib9c6b9b4 into rvc-dev am: 898dda3919
Change-Id: Iedf25e62f53ef2d72d0a9f7eda9379e2bb5cc4a7
2020-04-01 19:02:48 +00:00