1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "bundle_active_stats_combiner.h"
17 #include "bundle_active_log.h"
18
19 namespace OHOS {
20 namespace DeviceUsageStats {
combine(const std::shared_ptr<BundleActivePeriodStats> & stats,std::vector<BundleActivePackageStats> & accumulatedResult,int64_t beginTime)21 void BundleActiveStatsCombiner<BundleActivePackageStats>::combine(
22 const std::shared_ptr<BundleActivePeriodStats>& stats, std::vector<BundleActivePackageStats>& accumulatedResult,
23 int64_t beginTime)
24 {
25 BUNDLE_ACTIVE_LOGI("BundleActivePackageStats combine called");
26 for (auto it : stats->bundleStats_) {
27 if (it.second != nullptr) {
28 accumulatedResult.push_back(*(it.second));
29 }
30 }
31 }
32
combine(const std::shared_ptr<BundleActivePeriodStats> & stats,std::vector<BundleActiveEvent> & accumulatedResult,int64_t beginTime)33 void BundleActiveStatsCombiner<BundleActiveEvent>::combine(const std::shared_ptr<BundleActivePeriodStats>& stats,
34 std::vector<BundleActiveEvent>& accumulatedResult, int64_t beginTime)
35 {
36 BUNDLE_ACTIVE_LOGI("BundleActiveEvent combine called");
37 int32_t startIndex = stats->events_.FindBestIndex(beginTime);
38 int32_t size = static_cast<int32_t>(stats->events_.events_.size());
39 for (int32_t i = startIndex; i < size; i++) {
40 accumulatedResult.push_back(stats->events_.events_[i]);
41 }
42 }
43 } // namespace DeviceUsageStats
44 } // namespace OHOS
45
46