1 /*
2  * Copyright (C) 2023 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 SHARD_OFFSET_PROVIDER_H
18 #define SHARD_OFFSET_PROVIDER_H
19 
20 #include <gtest/gtest_prod.h>
21 #include <stdlib.h>
22 
23 namespace android {
24 namespace os {
25 namespace statsd {
26 
27 /*
28  * Class is not guarded by any mutex. It is currently thread safe.
29  * Thread safety needs to be considered on all future changes to this class.
30  */
31 class ShardOffsetProvider final {
32 public:
~ShardOffsetProvider()33     ~ShardOffsetProvider(){};
34 
getShardOffset()35     uint32_t getShardOffset() const {
36         return mShardOffset;
37     }
38 
39     static ShardOffsetProvider& getInstance();
40 
41 private:
42     ShardOffsetProvider(const uint32_t shardOffset);
43 
44     // Only used for testing.
setShardOffset(const uint32_t shardOffset)45     void setShardOffset(const uint32_t shardOffset) {
46         mShardOffset = shardOffset;
47     }
48 
49     uint32_t mShardOffset;
50 
51     FRIEND_TEST(CountMetricE2eTest, TestDimensionalSampling);
52     FRIEND_TEST(DurationMetricE2eTest, TestDimensionalSampling);
53     FRIEND_TEST(GaugeMetricE2ePushedTest, TestDimensionalSampling);
54     FRIEND_TEST(GaugeMetricE2ePushedTest, TestPushedGaugeMetricSamplingWithDimensionalSampling);
55     FRIEND_TEST(GaugeMetricProducerTest, TestPullDimensionalSampling);
56     FRIEND_TEST(KllMetricE2eTest, TestDimensionalSampling);
57     FRIEND_TEST(NumericValueMetricProducerTest, TestDimensionalSampling);
58     FRIEND_TEST(StatsdStatsTest, TestShardOffsetProvider);
59 };
60 
61 }  // namespace statsd
62 }  // namespace os
63 }  // namespace android
64 #endif  // METRIC_PRODUCER_H