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 20#include "update_engine/connection_utils.h" 21#include "update_engine/metrics.h" 22 23namespace chromeos_update_engine { 24 25class SystemState; 26 27namespace 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. 33metrics::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. 39metrics::AttemptResult GetAttemptResult(ErrorCode code); 40 41// Calculates the internet connection type given |type| and |tethering|. 42metrics::ConnectionType GetConnectionType(ConnectionType type, 43 ConnectionTethering tethering); 44 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. 51bool 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. 64bool MonotonicDurationHelper(SystemState* system_state, 65 int64_t* storage, 66 base::TimeDelta* out_duration); 67 68} // namespace metrics_utils 69} // namespace chromeos_update_engine 70 71#endif // UPDATE_ENGINE_METRICS_UTILS_H_ 72