Commit Graph

12 Commits

Author SHA1 Message Date
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
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
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
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
tsaichristine
a3d2ed8cb2 (Part 3) Use new socket schema with statsd tests
Update last set of statsd tests to use new socket schema

Test: bit statsd_test:*
Bug: 149590301
Change-Id: I0fe2c219ad75813db54ff0cfbad50f55e29cb626
2020-03-23 12:23:26 -07:00
Ruchir Rastogi
a5e4bb5aa6 Implement new perfd<->statsd ShellSubscriber comm.
Because we no longer linkToDeath against a binder object to detect if
the cmd process has died, we detect deaths by checking if writes fail.
ag/10476582 proves that writes fail if the cmd process dies.

Test: m statsd
Test: bit statsd_test:ShellSubscriberTest.testPushedSubscription
Test: bit statsd_test:ShellSubscriberTest.testPulledSubscription
Bug: 150619687
Change-Id: I44a777ffff11e5b9298912b2906063c65e9009eb
2020-03-19 09:17:44 -07:00
Jeffrey Huang
1e4368aa43 Comment out Statsd tests
Added todos to make them ues the new schema.

Bug: 145923087
Test: m -j && bit statsd_test:*
Change-Id: I0749760eb3123407b78b9ace9a93967bac727bf5
2020-02-18 18:36:02 -08: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
Yao Chen
35cb8d6537 Add a timeout option in shell subscriber.
Test: cts added
Change-Id: I0fe854fcfd5535ed03e502a4cad3f57079b45381
2019-01-03 17:00:39 -08:00
Chenjie Yu
0bd73dbaac Puller refactor
1) Refactor pullers and add tests.

2) Add timeout to a puller.
mPullTimeoutNs is intrinsic to puller. A pull taking longer than this is
deemed failed and the data discarded.
A metric or StatsPullerManager requesting a pull should monitor the pull
and have deadlineNs. A successful pull may come later than desired due
to statsd processing delays.

3) Add unit tests to puller now that the base puller is more
complicated.

Bug: 118756964
Test: unit test
Change-Id: I0e5d47e2527391f7beef4b2d06bfd5c2f82f1179
2018-12-21 09:46:09 -08:00
Yao Chen
41e606c1fc Add pulled atom subscription for shell.
+ Changed the output format from Atom to ShellData, which is a wrapper for repeated Atom
  This is useful because pulled atoms are usually a list of atoms.

Test: statsd_test added
Bug: 110536553

Change-Id: I0e2f55bdd9015c9bc95b87a630297c6f13e39636
2018-10-12 09:23:25 -07:00
Yao Chen
398dd19f66 Add unit tests for ShellSubscriber and fix a bug
Test: statsd_test
Change-Id: Iaf0558ec2a2dc190bedb240da8019868266ec8f5
2018-10-01 14:49:03 -07:00