317 Commits

Author SHA1 Message Date
Yangster-mac
b142cc8add Statsd config TTL
Roughly check the config every hour to see whether the ttl expired.
If so, read the config from disk and recreate the metric manager.

Test: statsd test

BUG: b/77274363

Change-Id: I16838afe5bbe966c3a0f638869751f9b59a5a259
2018-04-04 15:59:43 +00:00
David Chen
faa1af535b Includes annotations with statsd reports.
It's tricky to determine the source of the metrics on a device
currently since we can take the union of multiple configs and send
only one giant statsd_config into statsd. We will use the int64 field
to track the sub config id's and the int32 field to track the version
for each sub config, but the fields are named more generically as
annotations.

The annotations are available in both the reports and metadata.

Test: Check that all unit-tests pass on marlin-eng
Bug: 77327261
Change-Id: Ic37c549c8b2991676f69948c515156765c9f5108
2018-04-03 18:20:40 -07:00
Yangster-mac
c04feba805 Move forward the alarm timestamp when config is added to statsd.
Test: statsd test
BUG: b/77344187

Change-Id: Ieacffaa29422829b8956f2b3fcb2c647c8c3eed9
2018-04-02 18:12:36 -07:00
TreeHugger Robot
46eef8d049 Merge "E2e test for periodic alarm." into pi-dev 2018-03-31 03:04:59 +00:00
TreeHugger Robot
3b826c6075 Merge "Statsd MAX now obeys refractory periods too" into pi-dev 2018-03-31 01:10:57 +00:00
Bookatz
0dbc7a4343 Statsd MAX now obeys refractory periods too
The logic of where refractory period enforcement was moved out of the
anomaly tracker and into the metric's predictAnomalyTimestamp. It was
done for ORING, but not for MAX. This fixes MAX.

Bug: 74446029
Test: adb sync data && adb shell data/nativetest64/statsd_test/statsd_test
Change-Id: I51e43c7c132f424af8fe20a37f2ad10cc55b5989
2018-03-30 16:21:17 -07:00
TreeHugger Robot
9fef2594f3 Merge "Clean up atoms.proto" into pi-dev 2018-03-30 20:48:09 +00:00
Chenjie Yu
5caaa9d854 Clean up atoms.proto
changes are:
1) for pushed atoms, use attribution node in place of uid when
appropriate
2) name changes to be more consistent

Bug: 73823969
Test: manual test
Change-Id: Iacf7186dbd7a2282f7fe481f43dbbf92e1165b47
2018-03-30 10:11:03 -07:00
Chenjie Yu
6d370f40fe Add unit test ValueMetricProducer on boundary
Mostly to add test to assure the corner cases are covered.
One minor logic change is if two true conditions happen, in the case
when following happen:
(bucket boundary1) -> (condition false) -> (condition true) -> (pull
triggered for the boundary1)
Previously we take the latest. Now we skip the late boundary pull.

Bug: 76384731
Test: unit test
Change-Id: I345c2210a58bf03eb91d65742573073d2668358b
2018-03-29 21:54:54 -07:00
Chenjie Yu
1a0a941c20 Fix StatsCompanionService pull on bucket ends
+ change StatsPullerManager internal time units to be consistent
+ use series of alarms for pullers, instead of use setRepeating

Bug: 76223345
Bug: 75970648
Test: cts test
Change-Id: I9e6ac0ce06541f5ceabd2a8fa444e13d40e36983
2018-03-29 00:11:13 -07:00
Yangster-mac
684d195227 E2e test for periodic alarm.
Test: new test

BUG: b/76281156
Change-Id: I60cb28baaeec6996e946a7cb3358ec8e0aca80e5
2018-03-27 13:26:20 -07:00
TreeHugger Robot
d9afdee26f Merge "Support sliced condition change in GaugeMetric" into pi-dev 2018-03-27 18:27:27 +00:00
Yao Chen
427d372552 Support sliced condition change in GaugeMetric
TODO: We need CTS to verify the behavior.

Bug: 73958484
Test: statsd_test
Change-Id: I56406983ddede12bc6a2e12188693a0c51ccae5c
2018-03-27 09:21:19 -07:00
TreeHugger Robot
cdc9d9008b Merge "Flush the past buckets in anomaly tracker when time jumps forward" into pi-dev 2018-03-27 07:21:21 +00:00
Yangster-mac
be10ddfe46 Flush the past buckets in anomaly tracker when time jumps forward
E2e test for count/duration anomaly trackers.

Test: new statsd tests.

BUG: b/74446029

Change-Id: Ia9be0240ba5021d44c1e1f096d67563e9138bb59
2018-03-26 18:44:01 -07:00
David Chen
35045cbc34 Fix uidmap in statsd.
Previously tried an optimization that results in corrupted proto
output. This changes to a safer approach of storing the snapshot data
in memory and only converting to proto output when the
ProtoOutputStream is provided.

Also fixes a security issue when trying to invoke triggerUidSnapshot
since we forgot to use SCS' permissions.

Test: Added a unit-test to verify output of StatsLogProcessor.
Bug: 76231867
Change-Id: Id410ce3505fda9d71caa71942ef3068b55872c66
2018-03-24 15:01:04 -07:00
Yao Chen
d50f2ae487 rename neq_all_string to neq_any_string in statsd_config
Bug: 73897465
Test: statsd_test
Change-Id: I1d020de873fc26fbb502f0b3487b85fdb3896753
2018-03-23 11:10:13 -07:00
TreeHugger Robot
8512630f8b Merge "Allow statsd to be given empty config." into pi-dev 2018-03-21 05:34:16 +00:00
Howard Ro
e51af37475 Merge "Fix recovery of stats data from previous input while using ProtoOutputStream" into pi-dev 2018-03-21 00:31:23 +00:00
David Chen
9fdd40302e Allow statsd to be given empty config.
Statsd clients may want to set an empty config temporarily, so it's
more convenient to allow them to set an empty config instead of
having to use the removeConfig and then having to remember to call
StatsManager#setDataFetchOperation.

Test: Added unit-tests and check they pass on marlin-eng.
Bug: 74997752
Change-Id: I2e762e5ec01e5a2c9a3469fb330b53fefbd734d6
2018-03-20 15:56:11 -07:00
yro
4beccbe3de Fix recovery of stats data from previous input while using
ProtoOutputStream

- Specify the length of message to avoid libprotoutil from thinking that
we are trying to write bool
- We only attach the previous dump file to the upload file where config
key matches
- Store ConfigMetricsReport (instead of ConfigMetricsReportList) onto
disk
- Stop use stack after scope in StorageManager
- Migrate UidMap to use ProtoOutputStream and renaming variables to
prevent confusion

Bug: 74021554
Bug: 75968524
Test: manual test, statsd_test, CTS tests
Change-Id: Iedf52633d7f5b985f5a934a3fb5a0c3c3b2e7fd1
2018-03-20 15:00:59 -07:00
TreeHugger Robot
f5de606f51 Merge "Deletes default allowed_log_sources in statsd." into pi-dev 2018-03-19 18:14:18 +00:00
TreeHugger Robot
ad121b9fdc Merge changes I3ffb6e97,I689df136,Ia67a8eb6 into pi-dev
* changes:
  Statsd: remove DurationAnomalyTracker.resetStorage
  Statsd AnomalyDetection stopAlarm also checks old
  Statsd AnomalyDetection improvements
2018-03-19 05:49:27 +00:00
Bookatz
6bf9825b15 Statsd AnomalyDetection improvements
Various fixes and improvements to statsd's anomaly detection.

Bug: 74607818
Test: make statsd_test && adb sync data && adb shell data/nativetest64/statsd_test/statsd_test

Change-Id: Ia67a8eb6da0ea9293f698949e1565f7f024a7cb9
2018-03-16 11:34:21 -07:00
David Chen
8faaa01489 Deletes default allowed_log_sources in statsd.
We should fail right away if someone forgets to set this field
instead of setting default values since this may lead to hard to
explain bugs in the future (eg, why isn't systemui logging an atom
to a config).

Bug: 74608359
Test: Verified unit-tests still pass on marlin-eng.
Change-Id: Ibd8a6ccbc5cc8d2dfb8a1577c64bf9b49822a2c3
2018-03-15 17:45:58 -07:00
David Chen
f384b90049 Removes stats_log proto from uid map in statsd.
We don't need to parse the proto of uid map, so we use the
ProtoOutputStreame class to generate the binary form of the proto
output that's needed for parsing the uid map data.

Test: Verified unit-tests still pass.
Bug: 74010813
Change-Id: Ia2f7572f3b78bb6f7b60e8b14cf5d65428469ab6
2018-03-15 13:33:04 -07:00
TreeHugger Robot
a825c8ee5d Merge "Support slicing by chain." into pi-dev 2018-03-15 02:27:15 +00:00
Yangster-mac
e06cfd777a Support slicing by chain.
BUG: b/73975181

Test: statsd test
Change-Id: I913ae0f68ff21ed0703bb5da9c60d3eaa3bf5981
2018-03-14 15:36:24 -07:00
TreeHugger Robot
c7ce1a0978 Merge "Add wall clock timestamp for ConfigMetricsReport and gauge atoms." into pi-dev 2018-03-14 19:03:06 +00:00
Bookatz
3f5ab3ff1d Statsd: Remove storage of bucketNum
Past buckets had a field mBucketNum, storing the
"bucket number" they represented. Currently, the concept
of bucket number is used by Anomaly Detection (although this
may not be necessary), but these stored values are not used at all,
so removing them will save RAM.

Test: statsd tests still pass
Bug: 74607818
Change-Id: Iacc343bc39c5035f6e2f236c03de1d91606eff4c
2018-03-13 12:18:21 -07:00
Yangster-mac
3fa5d7fb23 Add wall clock timestamp for ConfigMetricsReport and gauge atoms.
Fix the bug when serializing multiple atoms in gauge metric

BUG: b/74159560

Test: new test for ALL_CONDITION_CHANGES sampling method.
Change-Id: I6d33c1efbac92b6e13be2d64c323e090cb1f84aa
2018-03-10 22:25:28 -08:00
Yangster
13fb7e4eea Statsd cpu optimizaton
- cache the changed dimensions in condition tracker.
- avoid query condition wizard when unnecessary.
- avoid copy dimension keys in condition key generation.

Test: statsd tests.

BUG: b/73959649
Change-Id: I17d68e2a82643de3f421309841e75f84c6fd8f43
2018-03-07 17:36:07 -08:00
Chenjie Yu
ec67661bdf Refactor cpu stats pullers
use same cpu stats readers with BatteryStats so that
1) both throttle to avoid too frequent pulls
2) cached value is served within throttle interval to avoid double
pulling by both statsd and BatteryStats

To run unit tests:
bit
FrameworksCoreTests:com.android.internal.os.KernelUidCpuFreqTimeReaderTest
bit
FrameworksCoreTests:com.android.internal.os.KernelUidCpuClusterTimeReaderTest
bit
FrameworksCoreTests:com.android.internal.os.KernelUidCpuActiveTimeReaderTest

make -j56 statsd_test && adb sync data && adb shell
/data/nativetest64/statsd_test/statsd_test

Test: cts test, unit test
Bug: 73745189
Bug: 73780619
Bug: 73360959

Merged-In: I10a9bc91ca67fa812f4cd71c4fbd73c1a5ba580e

Change-Id: I10a9bc91ca67fa812f4cd71c4fbd73c1a5ba580e
2018-03-07 21:43:00 +00:00
TreeHugger Robot
b603fb06ba Merge "Add API to let metrics directly drop data without writing to an output." 2018-03-02 23:38:21 +00:00
TreeHugger Robot
644e15d5bd Merge "Reduce statsd binary size from 730KB-> 664KB" 2018-03-02 19:41:56 +00:00
Yao Chen
06dba5d79c Add API to let metrics directly drop data without writing to an output.
+ Metrics will do flushIfNeeded() to correctly move the clock and informing
  AnomalyTracker the past bucket info, and then clear past buckets.

+ We will still keep the current bucket data for the validity of the future metrics.

Bug: 70571383
Test: statsd_test
Change-Id: Ib13c45574974e7b4e82bd8f305091dc93bda76f5
2018-03-01 15:22:55 -08:00
Yao Chen
580ea321b1 Add StateTracker.
StateTracker is a special condition tracker that's based on a state atom.
State atoms are annotated in atoms.proto.

The rules for StateTracker:
 1. must not have "stop". must have "dimension"
 2. must be based on a state atom.
 3. it must have the all primary fields and the exclusive state field in its dimension.

 For example UidProcessStateTracker, will have output dimension {uid, state}.

Test: unit tests added.
Change-Id: I6b77e58e9fabe61f7326daf929577d8b2cfbf27b
2018-02-28 16:57:03 -08:00
Yao Chen
20e9e6231a Reduce statsd binary size from 730KB-> 664KB
1. StatsdStats does not use the proto object in memory anymore.
2. lite_static -> lite
3. don't use sstream

Bug: 72129300
Test: statsd_test

Change-Id: I8a5adaf222d4d5034e8bf115215fb6dd5f042cac
2018-02-28 16:20:54 -08:00
TreeHugger Robot
99e8972919 Merge "Add the option to match a whitelist of strings in FieldValueMatcher." 2018-02-28 04:50:17 +00:00
Yao Chen
9b1140eecd Add the option to match a whitelist of strings in FieldValueMatcher.
+ This is useful when we want to build Anomaly detection on wakelocks, but want to whitelist
wakelocks held by some apps that are whitelisted. It reduces the number of matchers needed
in such a config.

+ Also added the ability to match an AID by string name.

Bug: 73897465
Test: unit tests added.
Change-Id: I19315ae4d7d27fc467655d3a29866049cd8c9a2b
2018-02-27 14:52:31 -08:00
Yangster-mac
932ececa16 Alarm: wakes up statsd and notifies the subscribers.
Test: manually tested it.
Change-Id: Id796a68976aeb1611183023ba4e9c6a8b8c44bb8
2018-02-27 13:30:48 -08:00
TreeHugger Robot
868688ed16 Merge "Add annotation to atoms that represent a state change in atoms.proto" 2018-02-22 05:36:45 +00:00
Yao Chen
9c1debe330 Add annotation to atoms that represent a state change in atoms.proto
+ A state change atom can have one exclusive state field, and any
  number of primary key fields.

  When there is primary key in the atom, it means the state belongs to the primary key.
  For example,
  message UidProcessStateChanged {
    optional int32 uid = 1 [(stateFieldOption).option = PRIMARY];
    optional android.app.ProcessStateEnum state = 2 [(stateFieldOption).option = EXCLUSIVE];
  }

  When there is no primary key fields in the atom, the state is global.
  For example,
  message ScreenStateChanged {
     optional android.view.DisplayStateEnum state = 1 [(stateFieldOption).option = EXCLUSIVE];
  }

+ The annotation is consumed by stats_log_api_gen to generate a static map from the state
  atoms to its primary fields, and exclusive fields

+ stats_log.proto is splitted into 2 proto files, because statsd needs proto lite, and c++
  lite proto library cannot properly ignore the field options which requires full proto.

 This CL doesn't change any logic in the statsd yet. A separate CL will use the field option
 information to correctly track the state.

Test: added unit tests in stats_log_api_gen_test. and statsd_test pases.
Change-Id: I9e8a979fe81ba60efd4d854bb7087ce4b2b147ec
2018-02-21 16:46:56 -08:00
TreeHugger Robot
3d7f2d40d4 Merge "Adds anomaly detection to max duration metrics." 2018-02-20 23:38:00 +00:00
David Chen
2e414b99f4 Adds anomaly detection to max duration metrics.
Statsd supports anomaly detection for max duration, which is
conceptually like asking for an anomaly on the current duration.
There was a bug previously in the logic for max duration since we
recorded a duration every time a dimension went into pause. Now, we
only record a max duration when the dimension goes into stop.

When a dimension inside the MaxDurationTracker leaves the started
state, we need to check if we still need to keep an anomaly alarm
set. It's possible that we just immediately set an alarm with the
same timestamp as what was just deleted.

Test: Added some unit-tests and tested on marlin-eng.
Change-Id: I09c82cd266b4cc6e1c893ad166e602bf08baca0e
2018-02-20 13:45:25 -08:00
Howard Ro
db15052ae2 Merge "Add a guardrail to limit minimum bucket duration to be 5 minutes except when configured through adb command" 2018-02-15 00:18:22 +00:00
TreeHugger Robot
2f5b9c9b03 Merge "Updates statsd atoms.proto with small changes." 2018-02-14 19:18:39 +00:00
Yangster-mac
330af58f2b Use elapsed realtime instead of times based on wall clock, which can jump around and go backwards.
Test: statsd unit test passed

Change-Id: Ib541df99231e171b3be2a24f75632693e36da90e
2018-02-13 23:30:39 -08:00
yro
59cc24dbfd Add a guardrail to limit minimum bucket duration to be 5 minutes except
when configured through adb command

Bug: 73287251
Test: statsd_test
Change-Id: Iee51fedbaabb2c1f534a6edef3c564da88ef658b
2018-02-13 20:26:31 -08:00
David Chen
0b5c90cd8c Updates statsd atoms.proto with small changes.
Renames the apphook atom to be more descriptive. Renames time
suffixes to match more clear convention (ms and msec are ambiguous).

Adds a field to CPU active time that's required for the metrics
to be usable.

Test: Test that statsd can still build.
Change-Id: I94866510738db994e8d757260f30e599ba995dbd
2018-02-13 16:17:25 -08:00