blob: fabb7e30200bea920897c51cc41b694dbb58eb2c [file] [log] [blame]
yrob30c5652017-09-15 10:06:40 -07001/*
2 * Copyright (C) 2017 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 */
Yang Lu071ca512017-10-25 19:54:45 -070016
17#pragma once
yrob30c5652017-09-15 10:06:40 -070018
Vova Sharaienko2e672742023-09-13 01:47:53 +000019#include <android-modules-utils/sdk_level.h>
yrob30c5652017-09-15 10:06:40 -070020
Yang Lu071ca512017-10-25 19:54:45 -070021#include <unordered_map>
22
Vova Sharaienko2e672742023-09-13 01:47:53 +000023#include "HashableDimensionKey.h"
24
Yao Chen7f139bf2017-09-14 22:32:50 -070025namespace android {
26namespace os {
27namespace statsd {
yrob30c5652017-09-15 10:06:40 -070028
Tej Singh7802b8f2021-03-01 21:40:37 -080029// Possible update states for a component. PRESERVE means we should keep the existing one.
30// REPLACE means we should create a new one because the existing one changed
31// NEW means we should create a new one because one does not currently exist.
32enum UpdateStatus {
33 UPDATE_UNKNOWN = 0,
34 UPDATE_PRESERVE = 1,
35 UPDATE_REPLACE = 2,
36 UPDATE_NEW = 3,
37};
38
Yangster-mac846d0f62017-12-22 17:19:39 -080039const HashableDimensionKey DEFAULT_DIMENSION_KEY = HashableDimensionKey();
Yangster-macaa194602018-01-22 20:49:31 -080040const MetricDimensionKey DEFAULT_METRIC_DIMENSION_KEY = MetricDimensionKey();
Yao Chenf0e7a4f2017-10-16 10:33:26 -070041
Yangstera4815e92018-03-07 17:30:49 -080042typedef std::map<int64_t, HashableDimensionKey> ConditionKey;
Yao Chen05f58d12017-10-30 22:57:06 -070043
Yangster-macaa194602018-01-22 20:49:31 -080044typedef std::unordered_map<MetricDimensionKey, int64_t> DimToValMap;
Yang Lu071ca512017-10-25 19:54:45 -070045
Muhammad Qureshi78e0c742021-04-30 14:15:01 -070046using ConditionLinks = google::protobuf::RepeatedPtrField<MetricConditionLink>;
47
48using StateLinks = google::protobuf::RepeatedPtrField<MetricStateLink>;
49
Muhammad Qureshib67d7ce2021-06-02 20:44:23 +000050struct Empty {};
51
Vova Sharaienko2e672742023-09-13 01:47:53 +000052inline bool isAtLeastS() {
53 const static bool isAtLeastS = android::modules::sdklevel::IsAtLeastS();
54 return isAtLeastS;
55}
56
57inline bool isAtLeastU() {
58 const static bool isAtLeastU = android::modules::sdklevel::IsAtLeastU();
59 return isAtLeastU;
60}
61
tsaichristine488334a2023-11-06 14:57:04 -080062inline bool shouldKeepRandomSample(int samplingPercentage) {
63 return (rand() % (100) + 1) <= samplingPercentage;
64}
65
Yao Chen7f139bf2017-09-14 22:32:50 -070066} // namespace statsd
67} // namespace os
68} // namespace android