shill: fix Network.Shill.Wifi.TimeToJoin metric
The Network.Shill.Wifi.TimeToJoin metric was not being collected, due
to subtleties of how it was supposed to be hooked in to Metrics. So
fix it.
More specifically, What's supposed to happen is this:
Metrics::RegisterService
-> WiFiService::InitializeCustomMetrics // overrides base class impl
-> Metrics::AddServiceStateTransitionTimer(...)
The problem was that Metrics::RegisterService is called from
Service::Service. Thus, at the time that Metrics::RegisterService is called,
we only have a Service object, not a WiFiService object. Consequently, the
virtual method call from Manager::RegisterService resolves to the base class
implementation of InitializeCustomMetrics, which has an empty body.
To fix this, we make InitializeCustomMetrics a non-virtual method (it
only had a meaningful implementation in WiFiService, anyway), and call
it explicitly from the WiFiService ctor, rather than implicitly via
Metrics::RegisterService.
While there:
- Remove RegisterService calls in MetricsTests. These are both
unnecessary, and actively harmful. The harm comes from the fact
that the explicit call to RegisterService in the unit tests overrides
the effect of the RegisterService in the Service.
In the case of WiFiService, this meant calling the derived-class
implementation of InitializeCustomMetrics. That meant the test passed,
but only because it did not reflect actual program behavior.
- Log a WARNING if a Service is re-registered with Metrics (without an
intervening call to DeregisterService).
- Remove unused |service| field of ServiceMetrics.
- Add parenthesis to ctor invocation in Metrics::RegisterService. I
believe the fields are non-POD, and initialized either way (with or
without parentheses). But it seems clearer to use the parentheses,
since we want the fields initialized.
- Fix whitespace issue in WiFiService::InitializeCustomMetrics.
- Tweak log message in service.cc.
BUG=chromium:268058
TEST=new unit test, manual
Manual testing
--------------
1. boot system
2. connect to wifi
3. open chrome://histograms
4. find that Network.Shill.Wifi.TimeToJoin exists, and has at least one sample
Change-Id: Icd925148415ea30fb63709bf034e63b8930c179c
Reviewed-on: https://gerrit.chromium.org/gerrit/65739
Tested-by: mukesh agrawal <quiche@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: mukesh agrawal <quiche@chromium.org>
9 files changed