Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 1 | // |
| 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 | |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame^] | 20 | #include "update_engine/connection_utils.h" |
Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 21 | #include "update_engine/metrics.h" |
| 22 | |
| 23 | namespace chromeos_update_engine { |
Alex Deymo | a259179 | 2015-11-17 00:39:40 -0300 | [diff] [blame] | 24 | |
| 25 | class SystemState; |
| 26 | |
Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 27 | namespace metrics_utils { |
| 28 | |
| 29 | // Transforms a ErrorCode value into a metrics::DownloadErrorCode. |
| 30 | // This obviously only works for errors related to downloading so if |code| |
| 31 | // is e.g. |ErrorCode::kFilesystemCopierError| then |
| 32 | // |kDownloadErrorCodeInputMalformed| is returned. |
| 33 | metrics::DownloadErrorCode GetDownloadErrorCode(ErrorCode code); |
| 34 | |
| 35 | // Transforms a ErrorCode value into a metrics::AttemptResult. |
| 36 | // |
| 37 | // If metrics::AttemptResult::kPayloadDownloadError is returned, you |
| 38 | // can use utils::GetDownloadError() to get more detail. |
| 39 | metrics::AttemptResult GetAttemptResult(ErrorCode code); |
| 40 | |
| 41 | // Calculates the internet connection type given |type| and |tethering|. |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame^] | 42 | metrics::ConnectionType GetConnectionType(ConnectionType type, |
| 43 | ConnectionTethering tethering); |
Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 44 | |
Alex Deymo | a259179 | 2015-11-17 00:39:40 -0300 | [diff] [blame] | 45 | // This function returns the duration on the wallclock since the last |
| 46 | // time it was called for the same |state_variable_key| value. |
| 47 | // |
| 48 | // If the function returns |true|, the duration (always non-negative) |
| 49 | // is returned in |out_duration|. If the function returns |false| |
| 50 | // something went wrong or there was no previous measurement. |
| 51 | bool WallclockDurationHelper(SystemState* system_state, |
| 52 | const std::string& state_variable_key, |
| 53 | base::TimeDelta* out_duration); |
| 54 | |
| 55 | // This function returns the duration on the monotonic clock since the |
| 56 | // last time it was called for the same |storage| pointer. |
| 57 | // |
| 58 | // You should pass a pointer to a 64-bit integer in |storage| which |
| 59 | // should be initialized to 0. |
| 60 | // |
| 61 | // If the function returns |true|, the duration (always non-negative) |
| 62 | // is returned in |out_duration|. If the function returns |false| |
| 63 | // something went wrong or there was no previous measurement. |
| 64 | bool MonotonicDurationHelper(SystemState* system_state, |
| 65 | int64_t* storage, |
| 66 | base::TimeDelta* out_duration); |
| 67 | |
Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 68 | } // namespace metrics_utils |
| 69 | } // namespace chromeos_update_engine |
| 70 | |
| 71 | #endif // UPDATE_ENGINE_METRICS_UTILS_H_ |