1 /*
2 * Copyright (C) 2024 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 #define MLOG_TAG "CloudEnhancementDfxGetCount"
17
18 #include "cloud_enhancement_dfx_get_count.h"
19
20 #include <cstdlib>
21
22 #include "media_file_utils.h"
23 #include "media_log.h"
24 #include "post_event_utils.h"
25
26 namespace OHOS {
27 namespace Media {
28 const int64_t REPORT_TIME_INTERVAL = 24 * 60 * 60 * 1000L; // 24 hour in milliseconds
29
CloudEnhancementGetCount()30 CloudEnhancementGetCount::CloudEnhancementGetCount() {}
31
~CloudEnhancementGetCount()32 CloudEnhancementGetCount::~CloudEnhancementGetCount() {}
33
GetInstance()34 CloudEnhancementGetCount& CloudEnhancementGetCount::GetInstance()
35 {
36 static CloudEnhancementGetCount instance;
37 return instance;
38 }
39
AddStartTime(const std::string & photoId)40 void CloudEnhancementGetCount::AddStartTime(const std::string &photoId)
41 {
42 startTimes_.emplace(photoId, MediaFileUtils::UTCTimeMilliSeconds());
43 }
44
RemoveStartTime(const std::string & photoId)45 void CloudEnhancementGetCount::RemoveStartTime(const std::string &photoId)
46 {
47 if (startTimes_.empty() || startTimes_.find(photoId) == startTimes_.end()) {
48 MEDIA_INFO_LOG("RemoveStartTime startTimes_ is empty or photoId is not in startTimes_");
49 return;
50 }
51
52 startTimes_.erase(photoId);
53 }
54
Report(const std::string & completedType,const std::string & photoId,const int32_t finishType)55 void CloudEnhancementGetCount::Report(const std::string &completedType, const std::string &photoId,
56 const int32_t finishType)
57 {
58 if (startTimes_.empty() || startTimes_.find(photoId) == startTimes_.end()) {
59 MEDIA_INFO_LOG("startTimes_ is empty or photoId is not in startTimes_");
60 return;
61 }
62 int64_t startTime = startTimes_[photoId];
63 int64_t totalTime = MediaFileUtils::UTCTimeMilliSeconds() - startTime;
64 startTimes_.erase(photoId);
65 VariantMap map = {
66 {KEY_PHOTO_ID, photoId},
67 {KEY_TOTAL_TIME_COST, totalTime},
68 {KEY_CLOUD_ENHANCEMENT_COMPLETE_TYPE, completedType},
69 {KEY_CLOUD_ENHANCEMENT_FINISH_TYPE, finishType},
70 };
71 PostEventUtils::GetInstance().PostStatProcess(StatType::CLOUD_ENHANCEMENT_GET_COUNT_STAT, map);
72 }
73
GetStartTimes()74 std::unordered_map<std::string, int64_t> CloudEnhancementGetCount::GetStartTimes()
75 {
76 return startTimes_;
77 }
78 } // namespace Media
79 } // namespace OHOS