Commit graph

40 commits

Author SHA1 Message Date
Chih-hung Hsieh
6dc68cb5f9 Merge "Fix google-explicit-constructor warnings in system/core." 2016-07-29 16:57:17 +00:00
Chih-Hung Hsieh
d506e782b8 Fix clang-tidy performance warnings in metricsd/uploader.
* Use const reference type for parameters to avoid unnecessary copy.

Bug: 30407689
Change-Id: I5e6bfd1cd3bcf54666316573281b79573cd8a780
Test: build with WITH_TIDY=1
2016-07-27 15:57:24 -07:00
Chih-Hung Hsieh
034c475931 Fix google-explicit-constructor warnings in system/core.
* Declare explicit conversion constructors.
* Add NOLINT for implicit conversion constructors.
* Fix also some misaligned indendations.

Bug: 28341362
Change-Id: Idf911f35923b408d92285cc1a053f382ba08c63e
Test: build with clang-tidy
2016-07-26 11:26:01 -07:00
Luis Hector Chavez
623ce74c83 core: Update libchrome APIs to r395517
The new libchrome has been ported from Chromium and some APIs have
changed. Make necessary changes at call sites.

Change-Id: I0a0e0441b6a7486ff0b42d11136254d8a536788f
2016-05-26 11:29:53 -07:00
Alex Vakulenko
3d979292d8 metricsd: Fix upload service to compile with new libchrome version
libmetric's HistogramSnapshotManager::PrepareDeltas now takes the
iterators for the histogram collection to work on, instead of getting
a global one.

Change-Id: I3997ea7d2c330431379d055b0cb876069bddf395
2016-03-18 15:36:20 -07:00
Alex Deymo
de4497ef3d Fix UploadService unittests.
The unittest was creating a brillo::Daemon in a smart pointer and then
resetting it to a newly created different brillo::Daemon instance. This
creates two brillo::Daemon instances for a short period of time, which
both setup global context (the default message loop).

This patch fixes this situation by deleting the service before creating
a new one.

Bug: 27121855
TEST=`/data/nativetest/metricsd_tests/metricsd_tests` on edison-eng

Change-Id: I3b60cbfcdba77febbfa6104aa0ecad60a29afec5
2016-02-10 11:57:55 -08:00
Alex Deymo
f1bf9e5fc9 metricsd: Create a brillo::MessageLoop.
brillo::BinderWatcher now requires a brillo::MessageLoop, so this patch
creates a brillo::BaseMessageLoop and passes it when creating the
brillo::BinderWatcher.

Bug: 26356682
TEST=Deployed metricsd to edison-eng.

Change-Id: I6a9e592623faf231205ae44e479bec2b873b8898
2016-02-04 13:56:38 -08:00
Bertrand SIMONNET
f1aa372f77 metricsd: Add more assert clause.
This CL adds two more checks:
* When populating a closed log with the metadata, make sure the
  SystemProfileSetter is not null.
* When using the update engine client library, check if the update
  engine client object was created correctly. The returning object can
  be null if update engine's binder service is not running.

Bug: 26731548

Change-Id: I8a615c87f33e15a163d56ccfa3a932a0908aac5f
2016-01-22 13:16:30 -08:00
Alex Vakulenko
ea05ff9229 crash_reporter/metricsd: Update libchrome APIs to r369476
The new libchrome has been ported from Chromium and some APIs have
changed. Make necessary changes at call sites.

Change-Id: I9e45975cdef43913270b82e3fca2c027e614a464
2016-01-20 13:43:30 -08:00
Bertrand SIMONNET
d6862317a6 metricsd: Persist metrics on shutdown.
When metricsd receives a SIGTERM signal (on system shutdown for
example), save the metrics to disk before exiting.

Bug: 26184202
Test: Start metricsd. Log a metric sample. Stop metricsd. The metric is
saved to disk.

Change-Id: Ib224efa8837130393fac5d06fa80d320263cfc84
2016-01-19 14:04:25 -08:00
Bertrand SIMONNET
0586504e01 metricsd: Persist the metrics to disk periodically.
Every now and then (5 minutes by default), the uploader will persist the
current metrics to disk to avoid losing them in case we exit
unexpectedly (reboot or crash).
When starting up, metricsd will load the previously saved log and resume
the metrics collection from there.

Bug: 25670584
Test: Unit tests.
Test: manual: restart metricsd. The saved log is detected and parsed
correctly.
Test: manual: Send a sample to metricsd, send SIGTERM to metricsd, the
log is saved to disk, metricsd restarts and picks up the log where it
left.

Change-Id: I4cefc62c7ea1fa51333d84d8a7ba0a2e9c7fd58f
2016-01-12 15:54:11 -08:00
Bertrand SIMONNET
b6c77af499 metricsd: Cleanup on TERM signal.
metricsd should shutdown cleanly when receiving a TERM signal:
* stop the binder watcher.
* wait for the thread to quit.
* Exit cleanly.

Note: This is not directly used as we don't send SIGTERM on shutdown or
when stopping services yet.

Bug: 25670584
Change-Id: I878d1e67474c72d24790f3540470e37a23112a95
2016-01-12 10:29:40 -08:00
Bertrand SIMONNET
146360b4a6 Fix documentation.
This fixes the documentation for UploadService and the README file:
* stop mentioning Chrome OS as we forked the code.
* update the histogram declaration workflow. It is not tied to Chrome's
  histograms.xml file anymore.
* update the architecture explanation of metricsd. We split
  metrics_daemon into two daemons and are now using binder to log
  metrics.
* convert README to markdown to make it prettier when viewed in gitiles.

Bug: 26314417

Change-Id: I1e492f1211c1784e65dd4d3e473bb9aacefc3b5d
2016-01-06 17:19:30 -08:00
Bertrand SIMONNET
6c9fbb9a3a metricsd: Replace scoped_ptr with unique_ptr.
scoped_ptr are a chromism. We should use unique_ptr instead.

Bug: 25958769
Test: unit tests.

Change-Id: Ie23ae2ef42f66dcc76f45a9dafa66c8ceb0a2d90
2015-12-22 09:18:04 -08:00
Todd Poynor
2862a7843d metricsd binder: Abort if fail to register service
Assert abort metricsd if binder service registration fails.

If the addService() call fails (for reasons that at least include an SELinux
policy denial), the call to joinThreadPool() apparently processes a stale
pending weak dereference that triggers an abort on a probable double-free:

 F libc    : Invalid address 0xbe8bfa30 passed to free: value not allocated
 F libc    : Fatal signal 6 (SIGABRT), code -6 in tid 609 (metricsd)

Since metricsd is severely hobbled if registration fails, abort and see if
things work better the next time.  If not, the crash loop will hopefully
attract attention to the problem.

Change-Id: I520d0eafb9cb25ee225d589bfd87df4e51f6b181
2015-12-09 13:32:37 -08:00
Bertrand SIMONNET
b13527d14e metricsd: Allows introspecting the metrics.
This CL adds a dump command to metrics_client that will dump the
histograms, aggregated by metricsd since it started, in a human readable
format.
This is useful for developers to ensure that their code uses libmetrics
correctly and the reported values are correct.

Sample output (redacted to fit the commit message):
$ metrics_client -d
Histogram: hello recorded 5 samples, average = 54.8 (flags = 0x1)
0   ...
9   --------O                 (1 = 20.0%) {0.0%}
16  O                         (0 = 0.0%) {20.0%}
29  --------O                 (1 = 20.0%) {20.0%}
54  ------------------------O (3 = 60.0%) {40.0%}
100 O                         (0 = 0.0%) {100.0%}
$

Bug: 25817310
Test: * Send a histogram with metrics_client.
      * `metrics_client -d` shows it.

Change-Id: Id186dc5463403ca9181ee9eef8f46b5e809b8714
2015-12-04 13:14:58 -08:00
Bertrand SIMONNET
6b8629a649 metricsd: Log over binder.
This CL converts metricsd, libmetrics and metrics_collector to use
Binder to pass metrics samples.

Bug: 25670685

Change-Id: I657faecdf4ed1226ab30ce69e062028463437e7b
2015-12-03 17:01:27 -08:00
Bertrand SIMONNET
9d3a4aeae2 metricsd: Use different directories for each daemon.
Instead of using a single directory for both the internal data of
metricsd and metrics_collector and the shared files (metrics samples log
file and the metrics enabled file), we should use separate directory to
allow for a finer access control.

The new structure will be:
* /data/misc/metrics for the files accessible to all daemons reporting
  metrics, metricsd and metrics_collector.
* /data/misc/metricsd for the private files of metricsd.
* /data/misc/metrics_collector for the private files of
  metrics_collector.

Bug: 25886951
Test: Unit tests.
Test: Manual: metricsd and metrics_collector run without errors.

Change-Id: I006d19f45f5f419d2b08744126c2e2a0b899c9fa
2015-11-30 13:34:49 -08:00
Bertrand SIMONNET
a7bc1c14df metricsd: Specify directory for persistent integers.
Instead of using a global directory for persistent integers, specify the
directory to use in the constructor.
This will make changing the backing directory easier.

Bug: 25886951

Change-Id: I590816b195fa81b179a5ec78b9cdf41bc86353dc
2015-11-30 13:34:49 -08:00
Bertrand SIMONNET
608e428006 metricsd: Split into two daemons.
This CL splits metrics_daemon into two independent daemons: metricsd and
metrics_collector.

* metricsd will be responsible for reading the metrics from disk and
  periodically uploading them to the server.
* metrics_collector will be responsible for gathering generic metrics
  from the system and managing the weave state for metrics.

This refactoring is necessary to prepare the migration of metricsd to
log over binder.

Bug: 25670908
Test: Unit tests.
Test: manual: both daemons run. Metrics are logged, uploaded and the
      weave interaction works.

Change-Id: Ib00e1772bb7eec87cbcdcd912c30b555d79d7074
2015-11-18 09:54:16 -08:00
Bertrand SIMONNET
1d15d46e17 metricsd: Don't upload if product id is empty.
If the product id is not set, the product_id file might exist but be
empty. In this case, to try to update the metrics.

Bug: 25745391
Change-Id: I3942afaf38921b44ddb7e5a29d5d0e4fb6d48d94
Test: Unit tests.
2015-11-17 13:22:30 -08:00
Bertrand SIMONNET
dc225c8224 metricsd: Fix the update channel parsing logic.
libupdate_engine_client returns the channel as "stable-channel",
"dev-channel" or "beta-channel". This CL updates the parsing logic to
match this format.

Bug: 25669566
Test: unit tests
Test: manual: The reported channel matches what update_engine_client
  --show_channel reports.

Change-Id: Ic6e52df892ae0b438f58fc05b178d5844d6674d0
2015-11-12 14:08:57 -08:00
Bertrand SIMONNET
e6b96d6d19 metricsd: Report the model manifest id.
When the model manifest id is defined in weave, report it.

Bug: 25386505
Test: the model manifest id is uploaded when defined.
Test: If weaved.conf is not defined, metricsd uploads the default value.

Change-Id: Ic895671621fda9ce5cdeacdbdba58aa73a6887fc
2015-10-30 14:42:55 -07:00
Dan Willemsen
faa566d29f Use GetBuildTime from libchrome instead of __DATE__
So that this daemon doesn't change on every build, use the system build
date from libchrome (which reads ro.build.date). That way we don't have
to update this daemon for every OTA.

Bug: 24204119
Change-Id: I136d53e5e4ebb9430a57dace66198d8d704d7ca3
2015-10-29 13:02:42 -07:00
Alex Vakulenko
26aef373a6 core: Rename libchromeos into libbrillo
BUG: 24872993
Change-Id: Ia47ad51140f7e384822eea9d5de46c9f51ceda11
2015-10-27 11:46:37 -07:00
Bertrand SIMONNET
eb697abf5e metricsd: Read build time values from etc/os-release.d.
This stops relying on system properties to provide build time
configuration.
Product version and id will be stored in /etc/os-release.d.
Channel will be pulled from update engine.

BUG: 24947119
Change-Id: I0972d03cd83ef622846de3cce3dec1992fcc46cd
2015-10-14 15:58:06 -07:00
Alex Vakulenko
74dc62460b system/core: Rename "chromeos" -> "brillo" in include paths and namespaces
libchromeos is transitioning to libbrillo and chromeos namespaces
and include directory is changing to brillo.

Bug: 24872993
Change-Id: I797613a38c7444a113f12e38366a424388477276
2015-10-13 15:29:24 -07:00
Bertrand SIMONNET
7dc7827107 metricsd: Rename build_target_id to product_id.
We use product_id instead of build_target_id, the protobuffer should
rename that field too to be consistent.
The same change was made on the backend.

BUG: 24712895
Change-Id: Id9492e3debab986c9df7d4ec0caef8730eb14240
2015-10-06 15:27:37 -07:00
Bertrand SIMONNET
3598d951a6 metricsd: Fix race condition in the tests.
We cached the enabled status for metrics as a static field in the
metrics library. This field is not reset in between tests which treats
the metrics as enabled if they were enabled previously.

None of the users rely on the caching being static so the cached status
was changed into a field.
Also enabled the metrics in upload_service_test.cc after verifying that
the test failed consistently.

BUG: 24473349
TEST: unit tests.

Change-Id: If05fdca644016d923aa7b1978db5e74ada563c1a
2015-09-28 15:02:00 -07:00
Bertrand SIMONNET
7beaf8924f metricsd: Use product id instead of build target id.
We decided to change the name of this identifier to "product id", the
system property where it is stored will also be named
ro.product.product_id.

BUG: 24302729

Change-Id: I0d2f0867b364de98367f0072d216acec76401c33
2015-09-24 16:23:30 -07:00
Samuel Tan
28a78b7210 metricsd: move timer_mock.h and metrics_library_mock.h into include/metrics/
Move metrics_library_mock.h and timer_mock.h into the include/metrics/
folder since some source files in shill need to include these header files.

Adjust the include paths in metricsd source files accordingly, and add
the -frtti flag to the libmetrics target so that classes including
these mock headers can determine the type information of the underlying
class being mocked at run-time.

BUG: 22956441
Change-Id: I19820c0d3097c9c4c2b93730d1988ccec563db23
TEST: "mma" in metricsd folder succeeds.
2015-09-23 18:12:37 -07:00
Bertrand SIMONNET
4c8a8ad3bf metricsd: Add test case for the upload service.
This test case ensures that we can log a metric with the metrics library
and upload it with the upload service.

BUG: 22879646
TEST: unit tests.

Change-Id: Idf4a1240d41745ebf7835089230608082eed19f5
2015-09-14 13:55:33 -07:00
Bertrand SIMONNET
1df10c43ea metricsd: Persist the report to disk if an upload fails.
If the metrics server is unreachable, we may need to resend a metrics
report later. Instead of keeping the staged report in memory, save it to
disk to avoid loosing data if the system restarts or crashes.

BUG: 23033262
TEST: unit tests.

Change-Id: Idd14964e40f022952469f47d675d8cda9586d7cd
2015-09-14 13:55:33 -07:00
Bertrand SIMONNET
2765d0abcc metricsd: Use the metrics directory everywhere.
Instead of passing different filenames around, only rely on the metrics
directory and infer the filepath from it. This makes testing easier.

BUG: 23939404
TEST: unit tests.

Change-Id: I79086acc3a546464114fa8ec4656ec04e1c43e35
2015-09-14 13:55:28 -07:00
Bertrand SIMONNET
8835c5b56e metricsd: Log the histogram name to hash mapping.
When running the metrics_daemon in verbose mode, log the histogram name
along with the hash name.
This is useful when debugging as the protobuf message only contains the
hash of the name.

Change-Id: Ifea7edce55d62d30994ec7b75bb8728f6a0c40e8
2015-09-02 15:07:10 -07:00
Bertrand SIMONNET
1253186728 metricsd: Make the unit tests pass.
This cleans up the unit tests and update them to pass.

Cleaned up:
* removed the irrelevant bits.
* Used ScopedTempDir for all test specific files (instead of the current
  directory).
* Update some objects to make them more easily testable.
* Group all the test in a single binary and use bionic's test runner.

BUG: 23682444
Change-Id: I289e3a5ff89968fdecd4a156e93bc38bbc25f58b
2015-09-02 13:30:48 -07:00
Bertrand SIMONNET
2699362a57 metricsd: Use system properties to store build time metadata.
Instead of using /etc/lsb-release to store the version, channel and
build_target_id, use the Android system properties.

BUG: 22879642

Change-Id: Ic79e74bd14bf8e2c55549c08963a66700b49b544
2015-08-25 16:23:04 -07:00
Bertrand SIMONNET
1f14655b27 metricsd: Don't crash when some metadata is missing.
Instead of crashing when the build target id is missing, simply print a
useful warning and discard the log.

BUG: 23351227

Change-Id: I3abf3063d6440b07103db29938eec5071ea8f60b
2015-08-20 11:57:50 -07:00
Bertrand SIMONNET
52e5b99983 metricsd: Relicense as Apache 2.
MODULE_LICENSE_BSD and NOTICE were removed as the license is no longer
different from the rest of system/core.

BUG: 23086670
Change-Id: I1e83ef2ecb9c721150f8aab283c9ff960337da8c
2015-08-10 15:57:47 -07:00
Bertrand SIMONNET
da21ac0751 metricsd: Rename metrics to metricsd.
This makes the import path less confusing:
* metrics/metrics_library.h is imported from the exported headers.
* metricsd/* for includes by the metrics daemon itself.

BUG: 22879597
Change-Id: I9f44ea3a548cae39d4546fcd724e8007f6dd4bd0
2015-08-10 15:26:01 -07:00