blob: 2d62dc07770c02cf80fedd2e977a5b270d422e46 [file] [log] [blame]
Alex Deymo38429cf2015-11-11 18:27:22 -08001//
2// Copyright (C) 2015 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17#ifndef UPDATE_ENGINE_METRICS_UTILS_H_
18#define UPDATE_ENGINE_METRICS_UTILS_H_
19
Tianjie Xu282aa1f2017-09-05 13:42:45 -070020#include <base/time/time.h>
21
22#include "update_engine/common/error_code.h"
Sen Jiang255e22b2016-05-20 16:15:29 -070023#include "update_engine/connection_utils.h"
Tianjie Xu282aa1f2017-09-05 13:42:45 -070024#include "update_engine/metrics_constants.h"
Alex Deymo38429cf2015-11-11 18:27:22 -080025
26namespace chromeos_update_engine {
Alex Deymoa2591792015-11-17 00:39:40 -030027
28class SystemState;
29
Alex Deymo38429cf2015-11-11 18:27:22 -080030namespace metrics_utils {
31
32// Transforms a ErrorCode value into a metrics::DownloadErrorCode.
33// This obviously only works for errors related to downloading so if |code|
34// is e.g. |ErrorCode::kFilesystemCopierError| then
35// |kDownloadErrorCodeInputMalformed| is returned.
36metrics::DownloadErrorCode GetDownloadErrorCode(ErrorCode code);
37
38// Transforms a ErrorCode value into a metrics::AttemptResult.
39//
40// If metrics::AttemptResult::kPayloadDownloadError is returned, you
41// can use utils::GetDownloadError() to get more detail.
42metrics::AttemptResult GetAttemptResult(ErrorCode code);
43
44// Calculates the internet connection type given |type| and |tethering|.
Sen Jiang255e22b2016-05-20 16:15:29 -070045metrics::ConnectionType GetConnectionType(ConnectionType type,
46 ConnectionTethering tethering);
Alex Deymo38429cf2015-11-11 18:27:22 -080047
Alex Deymoa2591792015-11-17 00:39:40 -030048// This function returns the duration on the wallclock since the last
49// time it was called for the same |state_variable_key| value.
50//
51// If the function returns |true|, the duration (always non-negative)
52// is returned in |out_duration|. If the function returns |false|
53// something went wrong or there was no previous measurement.
54bool WallclockDurationHelper(SystemState* system_state,
55 const std::string& state_variable_key,
56 base::TimeDelta* out_duration);
57
58// This function returns the duration on the monotonic clock since the
59// last time it was called for the same |storage| pointer.
60//
61// You should pass a pointer to a 64-bit integer in |storage| which
62// should be initialized to 0.
63//
64// If the function returns |true|, the duration (always non-negative)
65// is returned in |out_duration|. If the function returns |false|
66// something went wrong or there was no previous measurement.
67bool MonotonicDurationHelper(SystemState* system_state,
68 int64_t* storage,
69 base::TimeDelta* out_duration);
70
Alex Deymo38429cf2015-11-11 18:27:22 -080071} // namespace metrics_utils
72} // namespace chromeos_update_engine
73
74#endif // UPDATE_ENGINE_METRICS_UTILS_H_