739 Commits

Author SHA1 Message Date
Joe Onorato
9319453998 Revert "Start auto-generating the stats log API."
This reverts commit b81d1a7b9a38dcb4d356ae3435a82fb52ba7d585.

Change-Id: I189684d8913ffffca42d9514ac88ea5cc4a44f05
2017-10-16 22:41:28 +00:00
Joe Onorato
b81d1a7b9a Start auto-generating the stats log API.
Both native and java bindings.

TODOs:
- Finish WorkSources.
- Clean up the package names for the protos.
- Put the protos in a more suitable location.

Test: stats-log-api-gen-test
Change-Id: Idf4022225e2be05106dbcf7de8e97a3337fc63e2
2017-10-15 20:25:19 -07:00
David Chen
f12b5c6789 Removes redundant RefBase inheritance.
PackageInfoListener already inherits from RefBase, so the
MetricsProducer doesn't need it also.

Test: Not needed.
Change-Id: I27fc4c214251ba07fefeacf76549a80c8368ffa5
2017-10-13 15:57:48 -07:00
Bookatz
ece5f705d5 AnomalyMonitor can get alarms based on timestamp
When StatsCompanion informs statsd that an anomaly alarm has fired,
statsd will need to check to see whether an anomaly has indeed occurred.
This will require determining which anomaly alarms have times in the
past (since that indicates that the anomaly did indeed occur). This
capability is now added.

Test: adb shell data/nativetest64/statsd_test/statsd_test
Change-Id: I5464c94634df70832d2723d8c4718277776d58aa
2017-10-11 09:26:20 -07:00
TreeHugger Robot
6edd1686e0 Merge "Fix a bug in SimpleConditionTracker." 2017-10-11 00:32:21 +00:00
Yao Chen
4b1468538f Fix a bug in SimpleConditionTracker.
copy-paste bug

Test: manual. Will add unit tests for it.
Change-Id: I9494271a8a407b0f3c5fc0138c1afb4925c69b79
2017-10-10 15:34:42 -07:00
David Chen
de70169109 UID mapping to provide app name and version.
The UID map is updated by StatsCompanionService, which listens to broadcast
updates indicating that an app was updated/installed or removed. Also,
the entire map is updated when statsd first connects to the companion
service. Also, there is a way for metrics producers to subscribe to
updates, so that they can know when an app was upgraded.

Test: Created new unit-test for mapping and manually tested for install
and remove. Did not manually test the app upgrade.

Change-Id: I6676ae5c93b75c72d9badabb36aa9c40006db07d
2017-10-10 14:33:23 -07:00
Yao Chen
caf339d004 More complete implementation for condition and log matchers in statsd.
+ also synced proto from google3 to fix the LogEntryMatcher proto

+ MetricsManager represents StatsdConfig, it's responsible for initializing and managing all
LogEntryMatcher, Condition, and Metrics. Start review from here.

+ Added more complete StatsdConfig initialization, including building the map for:
    LogEntryMatcher -> Metrics
    LogEntryMatcher -> Condition
    Condition       -> Metrics.

    All the maps use index(int). The extra amount of memory for storing mappings help us
    quickly process log events.

  The StatsdConfig initialization process detects malformed config
  - Circle dependency
  - Missing definition
  etc.

 And once we detect ANY error, statsd will reject the config. And the resources related to this
 config will be released.

Test: Added unit tests
Change-Id: I2c4aefdbf3e2aa1701eacbb2fb5e653819ec1fbb
2017-10-10 10:03:46 -07:00
Chenjie Yu
16e9b10aa2 Merge "refactor statspuller" 2017-10-09 21:48:51 +00:00
TreeHugger Robot
4f99ad1e7b Merge "Statsd Anomaly tracking for CountMetricProducer" 2017-10-09 20:54:32 +00:00
Chenjie Yu
1a317baeda refactor statspuller
Test: manual test on device
Change-Id: Ibdec6a821e47cd2b2e7435002219c0b2e3f4c5d2
2017-10-09 12:47:45 -07:00
Bookatz
a4bc9c4a1e Statsd Anomaly tracking for CountMetricProducer
CountMetricProducer now has a CountAnomalyTracker which stores past
bucket information. Anomalies can be determined by seeing if the
information from the past and current buckets exeeds a threshold.

Test: manual
Change-Id: I35103c01dd32dcc31cb155f5685161cbaf969d03
2017-10-04 14:03:02 -07:00
Stefan Lafon
3e595b07c4 Check in new version of stats_events.proto. Rename a field.
Test: The code compiles, and most changes are cosmetic.

Change-Id: Iae06d7bbbe0212067de4302d4004d89d45812176
2017-10-02 20:55:52 -07:00
TreeHugger Robot
6214ad9f5f Merge "Statsd can pull kernel wakelock data" 2017-10-02 18:22:53 +00:00
Bookatz
c68a9d21b4 Statsd can pull kernel wakelock data
When statsd is told that it is time to poll data, it asks
StatsCompanionService to pull kernel wakelock data, receives the result
(as a string), and outputs it to screen.

Still to do:
1. don't use a string; use a parcel instead
2. don't output it to screen; do something useful instead
3. do more than just kernel wakelocks
4. pull data on demand, in addition to just on periodic pulling

Test: added setPollingAlarms to statsd.main and confirmed that kernel
wakelock information was written to screen
Change-Id: I35f5164420699dea1a00c9e530b938904f1d3055
2017-09-29 15:10:47 -07:00
Yao Chen
44cf27c148 Add metric computation skeleton to statsd.
This cl is to let statsd understand statsd_config, and compute metrics
 defined in the config.

+ StatsLogProcessor is given a StatsdConfig (hard coded right now).
  We construct a MetricProducer for each of the metric, and the metrics
  share Condition and LogEntryMatchers

+ Added the CountMetricProducer type for CountMetric.

We can now count times of SCREEN_ON events given a config.

TODO: 1) conditions are not implemented.
      2) slicings are not implemented in CountMetric
      3) move the interaction to dropbox to a separate thread
      4) decide how the in memory metrics would be used by anomaly detection

Test: manual test.

      $ adb shell /system/bin/statsd

      $ cat config_file.dat | adb shell cmd stats config

Change-Id: I38f4059c0dc5a827c338131d4a6fa7d4cbe865db
2017-09-29 12:52:41 -07:00
Stefan Lafon
cdb1a0ed95 Check in new protos and constants.
Test: Started statsd and verified it outputs data. Also ran statsd tests.

Change-Id: I2a438b2ddfcb1576e21acb6159bea607fed7caaa
2017-09-28 14:38:31 -07:00
TreeHugger Robot
353a02a5af Merge "Adds new utility functions for evaluating log entry matching. Includes matching for both simple and compound matchers." 2017-09-27 22:30:09 +00:00
David Chen
dd89694f5e Adds new utility functions for evaluating log entry matching.
Includes matching for both simple and compound matchers.

Change-Id: Id913d2625d205ad9a529019e98ae805f730f4d48
Test: Added new unit-tests and checked on marlin device.
2017-09-27 10:24:01 -07:00
yro
0eee308138 Extract tag ID from log_msg and fill in stats log proto
Test: tested locally

Change-Id: Ic6b88995dc9eec367125d687e4af9277016a30cb
2017-09-26 18:20:19 -07:00
yro
fbeb4cb3af Merge multiple eventMetricData entries into a single StatsLogReport
when writing to dropbox

Test: manual test.

Change-Id: I8ce323002ae1cad62703ece92bd99a5058b16fba
2017-09-24 22:42:44 -07:00
Yao Chen
3f0c1f2368 Fix a timestamp bug.
Test: manual
Change-Id: I8067fa8029c0b5702cae09202f8f9f7e443e902d
2017-09-22 21:25:11 -07:00
Yao Chen
ef99c4fa23 clang-format existing code in statsd.
Added .clang-format, because there isn't an official .clang-format file for Android framework code.

before we upload changes, do:

clang-format -style=file -i [file list]

to format the files that you touched.

Test: formatting only. NO code changes.
Change-Id: I90e87f1ee6618da8ea9bc2221c609c415a4046a8
2017-09-22 16:26:54 -07:00
TreeHugger Robot
4a2fed98c5 Merge "Add missing key for temporary battery process event and missing tag id for process Test: tested locally" 2017-09-21 09:03:05 +00:00
yro
a5c807ae80 Add timestamp pair to stats log
Test: tested locally

Change-Id: I70dfb0856c8410d55ea9cc6eaf1377961139ecd8
2017-09-21 00:06:46 -07:00
yro
e03583e261 Add missing key for temporary battery process event and missing tag id
for process
Test: tested locally

Change-Id: I1ef376ba9478e1e88ff09fb201078d4972d8d51b
2017-09-20 23:34:46 -07:00
Bookatz
906a35c814 Statsd namespace is defined and used
Statsd code now lives in android::os::statsd namespace. Existing files
are largely modified to follow this convention.

Exception: parse_util, since it seems a bit different.

Test: code compiles and existing statsd_tests still pass
Change-Id: Idf92a071b9ed172d01eb3087a4fa3609d67a038c
2017-09-20 16:58:14 -07:00
Bookatz
b487b5533e statsd & statscompanion communication more robust
If statsd or statsdcompanion crashes, or if one loads
before the other, the other will be able to accomodate.

When statsd loads, it will attempt to tell statscompanion that it's
alive, and then get on to its business, while assuming that
statscompanion is not alive. Only when statscompanion tells statsd
that it is alive, statsd will then start to use it.

When statscompanion loads, it will attempt to tell statsd that it's
alive and then do nothing (since it has nothing to do). When statsd
tells statscompanion that statsd is alive, statscompanion will respond,
telling statsd that it is alive and, if that binder call returns, will
get to work.

This way, if statsd loads first, it can work unobstructed until
statscompanion informs statsd that it is alive, at which point they
shake hands and work. Conversely, if statscompanion loads first, it will
do nothing until statsd contacts it, at which point they will shake
hands and work.

Test: manual
Change-Id: I969ad47fb8060e27814d05ad37433a02711cfa6a
2017-09-20 14:13:44 -07:00
Bookatz
1b0b114abc StatsCompanionService sends messages to statsd
StatsCompanionService can now inform statsd that an alarm (for anomaly
alerting and for polling) has fired, so that statsd can act accordingly.

Test: manual created an alarm from statsd.main and checked logcat that
statsd received the broadcast that it fired
Change-Id: I1d33dfbee0d3e213c91dd6973d2622ecacc890c8
2017-09-20 07:51:53 -07:00
Adam Bookatz
43b272e20c Merge changes I82fe220e,Iff324c73,I3bd73acd
* changes:
  indexed priority queue for AnomalyMonitor
  StatsCompanionService connection to Statsd
  Set up StatsCompanionService.java
2017-09-20 14:01:49 +00:00
yro
00698daf3c Translate Android log entries to stats_log proto
Test: tested on local device

Change-Id: If9a779a96d31cefaffb1e4424629c14b08e1fc57
2017-09-18 23:30:14 -07:00
David Chen
0656b7a158 Adding ability to add configs via adb command-line. The input
must be in serialized binary format. Also fixes small issue
in build rule related to proto lib.

Test: Manually tested that ADB command works without crashing.

Change-Id: Iba2e677561ff500adb601a598f73e8a7b32540e5
2017-09-15 14:07:52 -07:00
Bookatz
0e95909ef0 indexed priority queue for AnomalyMonitor
Created a new class, indexed_priority_queue, which is a priority queue
that allows the removal of elements (other than just the top element).
This is required for AnomalyMonitor, which will henceforth use it.

Some tests for this new class are included.

I have only implemented the methods in indexed_priority_queue that are
currently needed. For example, pop_top() has not been written as
AnomalyMonitor does not need it.

Test: adb shell data/nativetest64/statsd_test/statsd_test
Change-Id: I82fe220ee5a879189b0cfa03b551c829cfdd05f0
2017-09-14 13:04:45 -07:00
Bookatz
486d1cf358 StatsCompanionService connection to Statsd
Created AnomalyMonitor in statsd, which can monitor statsd's internal
anomaly alarms and register the soonest one with the
StatsCompanionService.

This cl introduces the AnomalyMonitor and allows it to register alarms.
It does not yet allow for the removal of internal alarms.

Test: manually added alarms and ensured they were correctly registered
in StatsCompanionService
Change-Id: Iff324c73751c4f43b1507dc64649b50ac388adef
2017-09-14 12:56:59 -07:00
Yao Chen
482d272d7c Add a cmd line tool to StatsService to parse log files from Dropbox
Test: adb shell cmd stats all-logs
Change-Id: I7803c9c021a971619f60fbf6bdfabd33d2f476ef
2017-09-13 16:58:41 -07:00
Yao Chen
ab273e2e13 Add a DropboxWriter in statsd.
+ The DropboxWriter keeps data in cache, and flush to files once the
  size exceeds the maximum value.

+ Different components should create their owner DropboxWriter with
  different tags, e.g., anomly detection, experiment metrics, etc.

+ Copied stats_log related protos from g3

Test: run statsd, and adb shell dumpsys dropbox
      Will add unit tests.

Change-Id: If06e9a9953be32082252b340a97124d732656b40
2017-09-13 16:58:40 -07:00
Chenjie Yu
7ca2e823fa rudimentary logging of screen_on and process start/crash via logd to
statsd. The numbers should be replaced with protobuf enums and the
format is subject to changes. But this gets it working for now.

Test: flash with new image, statsd should print out events. toggle
screen on from off state will add a log entry

Change-Id: I733e249965689f00597232c0e3eccfd26e1a958c
2017-09-07 15:18:18 -07:00
Joe Onorato
2cbc2cce80 Add "adb shell cmd stats" support to statsd.
Test: adb shell cmd stats
Change-Id: Idcca995af208153019be5faa1acd573037f931cb
2017-08-30 17:03:50 -07:00
Joe Onorato
5dcbc6c015 Add statsd.
It doesn't start yet by default. When you start it manually, it sets
itself up as a binder system service and starts a thread to read the
event log.

Test: Run statsd, observe output. also run stats_test
Change-Id: If435d6a80fef3c1d957aedb61699bf5e9aae7e56
2017-08-30 12:36:31 -07:00