138429cf76aaac8c499004b6f537229a26b381602Alex Deymo// 238429cf76aaac8c499004b6f537229a26b381602Alex Deymo// Copyright (C) 2015 The Android Open Source Project 338429cf76aaac8c499004b6f537229a26b381602Alex Deymo// 438429cf76aaac8c499004b6f537229a26b381602Alex Deymo// Licensed under the Apache License, Version 2.0 (the "License"); 538429cf76aaac8c499004b6f537229a26b381602Alex Deymo// you may not use this file except in compliance with the License. 638429cf76aaac8c499004b6f537229a26b381602Alex Deymo// You may obtain a copy of the License at 738429cf76aaac8c499004b6f537229a26b381602Alex Deymo// 838429cf76aaac8c499004b6f537229a26b381602Alex Deymo// http://www.apache.org/licenses/LICENSE-2.0 938429cf76aaac8c499004b6f537229a26b381602Alex Deymo// 1038429cf76aaac8c499004b6f537229a26b381602Alex Deymo// Unless required by applicable law or agreed to in writing, software 1138429cf76aaac8c499004b6f537229a26b381602Alex Deymo// distributed under the License is distributed on an "AS IS" BASIS, 1238429cf76aaac8c499004b6f537229a26b381602Alex Deymo// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1338429cf76aaac8c499004b6f537229a26b381602Alex Deymo// See the License for the specific language governing permissions and 1438429cf76aaac8c499004b6f537229a26b381602Alex Deymo// limitations under the License. 1538429cf76aaac8c499004b6f537229a26b381602Alex Deymo// 1638429cf76aaac8c499004b6f537229a26b381602Alex Deymo 1738429cf76aaac8c499004b6f537229a26b381602Alex Deymo#ifndef UPDATE_ENGINE_METRICS_UTILS_H_ 1838429cf76aaac8c499004b6f537229a26b381602Alex Deymo#define UPDATE_ENGINE_METRICS_UTILS_H_ 1938429cf76aaac8c499004b6f537229a26b381602Alex Deymo 20255e22b82af3a52218eaea66acc734ec25cfeab6Sen Jiang#include "update_engine/connection_utils.h" 2138429cf76aaac8c499004b6f537229a26b381602Alex Deymo#include "update_engine/metrics.h" 2238429cf76aaac8c499004b6f537229a26b381602Alex Deymo 2338429cf76aaac8c499004b6f537229a26b381602Alex Deymonamespace chromeos_update_engine { 24a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo 25a2591795edb1a4f4c751347daab16c70daad1274Alex Deymoclass SystemState; 26a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo 2738429cf76aaac8c499004b6f537229a26b381602Alex Deymonamespace metrics_utils { 2838429cf76aaac8c499004b6f537229a26b381602Alex Deymo 2938429cf76aaac8c499004b6f537229a26b381602Alex Deymo// Transforms a ErrorCode value into a metrics::DownloadErrorCode. 3038429cf76aaac8c499004b6f537229a26b381602Alex Deymo// This obviously only works for errors related to downloading so if |code| 3138429cf76aaac8c499004b6f537229a26b381602Alex Deymo// is e.g. |ErrorCode::kFilesystemCopierError| then 3238429cf76aaac8c499004b6f537229a26b381602Alex Deymo// |kDownloadErrorCodeInputMalformed| is returned. 3338429cf76aaac8c499004b6f537229a26b381602Alex Deymometrics::DownloadErrorCode GetDownloadErrorCode(ErrorCode code); 3438429cf76aaac8c499004b6f537229a26b381602Alex Deymo 3538429cf76aaac8c499004b6f537229a26b381602Alex Deymo// Transforms a ErrorCode value into a metrics::AttemptResult. 3638429cf76aaac8c499004b6f537229a26b381602Alex Deymo// 3738429cf76aaac8c499004b6f537229a26b381602Alex Deymo// If metrics::AttemptResult::kPayloadDownloadError is returned, you 3838429cf76aaac8c499004b6f537229a26b381602Alex Deymo// can use utils::GetDownloadError() to get more detail. 3938429cf76aaac8c499004b6f537229a26b381602Alex Deymometrics::AttemptResult GetAttemptResult(ErrorCode code); 4038429cf76aaac8c499004b6f537229a26b381602Alex Deymo 4138429cf76aaac8c499004b6f537229a26b381602Alex Deymo// Calculates the internet connection type given |type| and |tethering|. 42255e22b82af3a52218eaea66acc734ec25cfeab6Sen Jiangmetrics::ConnectionType GetConnectionType(ConnectionType type, 43255e22b82af3a52218eaea66acc734ec25cfeab6Sen Jiang ConnectionTethering tethering); 4438429cf76aaac8c499004b6f537229a26b381602Alex Deymo 45a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo// This function returns the duration on the wallclock since the last 46a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo// time it was called for the same |state_variable_key| value. 47a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo// 48a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo// If the function returns |true|, the duration (always non-negative) 49a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo// is returned in |out_duration|. If the function returns |false| 50a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo// something went wrong or there was no previous measurement. 51a2591795edb1a4f4c751347daab16c70daad1274Alex Deymobool WallclockDurationHelper(SystemState* system_state, 52a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo const std::string& state_variable_key, 53a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo base::TimeDelta* out_duration); 54a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo 55a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo// This function returns the duration on the monotonic clock since the 56a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo// last time it was called for the same |storage| pointer. 57a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo// 58a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo// You should pass a pointer to a 64-bit integer in |storage| which 59a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo// should be initialized to 0. 60a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo// 61a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo// If the function returns |true|, the duration (always non-negative) 62a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo// is returned in |out_duration|. If the function returns |false| 63a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo// something went wrong or there was no previous measurement. 64a2591795edb1a4f4c751347daab16c70daad1274Alex Deymobool MonotonicDurationHelper(SystemState* system_state, 65a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo int64_t* storage, 66a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo base::TimeDelta* out_duration); 67a2591795edb1a4f4c751347daab16c70daad1274Alex Deymo 6838429cf76aaac8c499004b6f537229a26b381602Alex Deymo} // namespace metrics_utils 6938429cf76aaac8c499004b6f537229a26b381602Alex Deymo} // namespace chromeos_update_engine 7038429cf76aaac8c499004b6f537229a26b381602Alex Deymo 7138429cf76aaac8c499004b6f537229a26b381602Alex Deymo#endif // UPDATE_ENGINE_METRICS_UTILS_H_ 72