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 #define MLOG_TAG "DfxReporter"
16
17 #include "dfx_reporter.h"
18
19 #include <vector>
20
21 #include "dfx_const.h"
22 #include "dfx_utils.h"
23 #include "dfx_database_utils.h"
24 #include "medialibrary_errno.h"
25 #include "media_file_utils.h"
26 #include "media_log.h"
27 #include "hisysevent.h"
28 #include "preferences.h"
29 #include "preferences_helper.h"
30 #include "medialibrary_data_manager_utils.h"
31 #include "medialibrary_bundle_manager.h"
32 #include "medialibrary_inotify.h"
33 #include "medialibrary_astc_stat.h"
34 using namespace std;
35 namespace OHOS {
36 namespace Media {
37 static constexpr char MEDIA_LIBRARY[] = "MEDIALIBRARY";
38
DfxReporter()39 DfxReporter::DfxReporter()
40 {
41 }
42
~DfxReporter()43 DfxReporter::~DfxReporter()
44 {
45 }
46
ReportControllerService(uint32_t operationCode,int32_t errorCode)47 void DfxReporter::ReportControllerService(uint32_t operationCode, int32_t errorCode)
48 {
49 std::string bundleName = MediaLibraryBundleManager::GetInstance()->GetClientBundleName();
50 int ret = HiSysEventWrite(
51 MEDIA_LIBRARY,
52 "MEDIALIB_SERVICE_ERROR",
53 HiviewDFX::HiSysEvent::EventType::FAULT,
54 "BUNDLE_NAME", bundleName,
55 "OPERATION_CODE", operationCode,
56 "ERROR_CODE", errorCode);
57 if (ret != 0) {
58 MEDIA_ERR_LOG("ReportControllerService error:%{public}d", ret);
59 }
60 }
61
ReportTimeOutOperation(std::string & bundleName,int32_t type,int32_t object,int32_t time)62 void DfxReporter::ReportTimeOutOperation(std::string &bundleName, int32_t type, int32_t object, int32_t time)
63 {
64 int ret = HiSysEventWrite(
65 MEDIA_LIBRARY,
66 "MEDIALIB_TIMEOUT_ERROR",
67 HiviewDFX::HiSysEvent::EventType::FAULT,
68 "BUNDLE_NAME", bundleName,
69 "OPERATION_TYPE", type,
70 "OPERATION_OBJECT", object,
71 "TIME", time);
72 if (ret != 0) {
73 MEDIA_ERR_LOG("ReportTimeoutOperation error:%{public}d", ret);
74 }
75 }
76
ReportHighMemoryImageThumbnail(std::string & path,std::string & suffix,int32_t width,int32_t height)77 int32_t DfxReporter::ReportHighMemoryImageThumbnail(std::string &path, std::string &suffix, int32_t width,
78 int32_t height)
79 {
80 if (suffix != "jpg" && suffix != "jpeg" && suffix != "jpe") {
81 MEDIA_WARN_LOG("image %{public}s is %{public}s, width: %{public}d, height: %{public}d", path.c_str(),
82 suffix.c_str(), width, height);
83 return OTHER_FORMAT_IMAGE;
84 } else if (width > IMAGE_MIN && height > IMAGE_MIN) {
85 MEDIA_WARN_LOG("image %{public}s is too large, width: %{public}d, height: %{public}d", path.c_str(), width,
86 height);
87 return BIG_IMAGE;
88 }
89 return COMMON_IMAGE;
90 }
91
ReportHighMemoryVideoThumbnail(std::string & path,std::string & suffix,int32_t width,int32_t height)92 int32_t DfxReporter::ReportHighMemoryVideoThumbnail(std::string &path, std::string &suffix, int32_t width,
93 int32_t height)
94 {
95 if (width >= VIDEO_8K_MIN || height >= VIDEO_8K_MIN) {
96 MEDIA_WARN_LOG("video %{public}s is too large, width: %{public}d, height: %{public}d", path.c_str(), width,
97 height);
98 return BIG_VIDEO;
99 }
100 return COMMON_VIDEO;
101 }
102
ReportThumbnailError()103 void DfxReporter::ReportThumbnailError()
104 {
105 int32_t errCode;
106 shared_ptr<NativePreferences::Preferences> prefs =
107 NativePreferences::PreferencesHelper::GetPreferences(THUMBNAIL_ERROR_XML, errCode);
108 if (!prefs) {
109 MEDIA_ERR_LOG("get preferences error: %{public}d", errCode);
110 return;
111 }
112 map<string, NativePreferences::PreferencesValue> errorMap = prefs->GetAll();
113 for (auto &erroInfo : errorMap) {
114 string key = erroInfo.first;
115 string value = erroInfo.second;
116 vector<string> thumbnailInfo = DfxUtils::Split(key, SPLIT_CHAR);
117 if (thumbnailInfo.empty() || thumbnailInfo.size() < 3) { // 3 means length of key
118 continue;
119 }
120 // 0 means index of path
121 string path = thumbnailInfo[0];
122 // 1 means index of method
123 int32_t method = MediaLibraryDataManagerUtils::IsNumber(thumbnailInfo[1]) ? stoi(thumbnailInfo[1]) : 0;
124 // 2 means index of error code
125 int32_t errorCode = MediaLibraryDataManagerUtils::IsNumber(thumbnailInfo[2]) ? stoi(thumbnailInfo[2]) : 0;
126 int64_t time = MediaLibraryDataManagerUtils::IsNumber(value) ? stol(value) : 0;
127 int ret = HiSysEventWrite(
128 MEDIA_LIBRARY,
129 "MEDIALIB_THUMBNAIL_ERROR",
130 HiviewDFX::HiSysEvent::EventType::FAULT,
131 "PATH", path,
132 "METHOD", method,
133 "ERROR_CODE", errorCode,
134 "TIME", time);
135 if (ret != 0) {
136 MEDIA_ERR_LOG("ReportThumbnailError error:%{public}d", ret);
137 }
138 }
139 prefs->Clear();
140 prefs->FlushSync();
141 }
142
ReportCommonBehavior()143 void DfxReporter::ReportCommonBehavior()
144 {
145 int32_t errCode;
146 shared_ptr<NativePreferences::Preferences> prefs =
147 NativePreferences::PreferencesHelper::GetPreferences(COMMON_BEHAVIOR_XML, errCode);
148 if (!prefs) {
149 MEDIA_ERR_LOG("get preferences error: %{public}d", errCode);
150 return;
151 }
152 map<string, NativePreferences::PreferencesValue> errorMap = prefs->GetAll();
153 for (auto &erroInfo : errorMap) {
154 string bundleName = erroInfo.first;
155 int32_t times = static_cast<int32_t>(erroInfo.second);
156 int ret = HiSysEventWrite(
157 MEDIA_LIBRARY,
158 "MEDIALIB_COMMON_STATISTIC",
159 HiviewDFX::HiSysEvent::EventType::STATISTIC,
160 "BUNDLE_NAME", bundleName,
161 "TIMES", times);
162 if (ret != 0) {
163 MEDIA_ERR_LOG("ReportCommonBehavior error:%{public}d", ret);
164 }
165 }
166 prefs->Clear();
167 prefs->FlushSync();
168 }
169
ReportDeleteStatistic()170 void DfxReporter::ReportDeleteStatistic()
171 {
172 int32_t errCode;
173 shared_ptr<NativePreferences::Preferences> prefs =
174 NativePreferences::PreferencesHelper::GetPreferences(DELETE_BEHAVIOR_XML, errCode);
175 if (!prefs) {
176 MEDIA_ERR_LOG("get preferences error: %{public}d", errCode);
177 return;
178 }
179 map<string, NativePreferences::PreferencesValue> deleteMap = prefs->GetAll();
180 for (auto &info : deleteMap) {
181 string key = info.first;
182 vector<string> deleteInfo = DfxUtils::Split(key, SPLIT_CHAR);
183 if (deleteInfo.empty() || deleteInfo.size() < 2) { // 2 means length of key
184 continue;
185 }
186 // 0 means index of bundleName
187 string bundleName = deleteInfo[0];
188 // 1 means index of type
189 int32_t type = MediaLibraryDataManagerUtils::IsNumber(deleteInfo[1]) ? stoi(deleteInfo[1]) : 0;
190 int32_t times = static_cast<int32_t>(info.second);
191 int ret = HiSysEventWrite(
192 MEDIA_LIBRARY,
193 "MEDIALIB_DELETE_STATISTIC",
194 HiviewDFX::HiSysEvent::EventType::STATISTIC,
195 "BUNDLE_NAME", bundleName,
196 "TYPE", type,
197 "TIMES", times);
198 if (ret != 0) {
199 MEDIA_ERR_LOG("ReportDeleteBehavior error:%{public}d", ret);
200 }
201 }
202 prefs->Clear();
203 prefs->FlushSync();
204 }
205
ReportDeleteBehavior(string bundleName,int32_t type,std::string path)206 void DfxReporter::ReportDeleteBehavior(string bundleName, int32_t type, std::string path)
207 {
208 if (bundleName == "" || path == "") {
209 return;
210 }
211 MEDIA_WARN_LOG("%{public}s do %{public}d on %{public}s", bundleName.c_str(), type, path.c_str());
212 int ret = HiSysEventWrite(
213 MEDIA_LIBRARY,
214 "MEDIALIB_DELETE_BEHAVIOR",
215 HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
216 "BUNDLE_NAME", bundleName,
217 "TYPE", type,
218 "PATH", path);
219 if (ret != 0) {
220 MEDIA_ERR_LOG("ReportDeleteBehavior error:%{public}d", ret);
221 }
222 }
223
ReportThumbnailGeneration(const ThumbnailData::GenerateStats & stats)224 void DfxReporter::ReportThumbnailGeneration(const ThumbnailData::GenerateStats &stats)
225 {
226 int ret = HiSysEventWrite(
227 MEDIA_LIBRARY,
228 "MEDIALIB_THUMBNAIL_GENERATION",
229 HiviewDFX::HiSysEvent::EventType::STATISTIC,
230 "URI", stats.uri,
231 "SCENE", static_cast<int32_t>(stats.scene),
232 "OPEN_THUMB_COST", stats.openThumbCost,
233 "OPEN_LCD_COST", stats.openLcdCost,
234 "SOURCE_TYPE", static_cast<int32_t>(stats.sourceType),
235 "SOURCE_WIDTH", stats.sourceWidth,
236 "SOURCE_HEIGHT", stats.sourceHeight,
237 "TOTAL_COST", static_cast<int32_t>(stats.totalCost),
238 "ERROR_CODE", stats.errorCode);
239 if (ret != 0) {
240 MEDIA_ERR_LOG("ReportThumbnailGeneration error:%{public}d", ret);
241 }
242 }
243
ReportPhotoInfo(const PhotoStatistics & stats)244 void DfxReporter::ReportPhotoInfo(const PhotoStatistics& stats)
245 {
246 int ret = HiSysEventWrite(
247 MEDIA_LIBRARY,
248 "MEDIALIB_PHOTO_INFO",
249 HiviewDFX::HiSysEvent::EventType::STATISTIC,
250 "LOCAL_IMAGE_COUNT", stats.localImageCount,
251 "LOCAL_VIDEO_COUNT", stats.localVideoCount,
252 "CLOUD_IMAGE_COUNT", stats.cloudImageCount,
253 "CLOUD_VIDEO_COUNT", stats.cloudVideoCount,
254 "SHARED_IMAGE_COUNT", stats.sharedImageCount,
255 "SHARED_VIDEO_COUNT", stats.sharedVideoCount);
256 if (ret != 0) {
257 MEDIA_ERR_LOG("ReportPhotoInfo error:%{public}d", ret);
258 }
259 }
260
ReportAstcInfo(const LcdAndAstcCount & count)261 void DfxReporter::ReportAstcInfo(const LcdAndAstcCount& count)
262 {
263 int ret = HiSysEventWrite(
264 MEDIA_LIBRARY,
265 "MEDIALIB_ASTC_INFO",
266 HiviewDFX::HiSysEvent::EventType::STATISTIC,
267 "LOCAL_LCD_COUNT", count.localLcdCount,
268 "LOCAL_ASTC_COUNT", count.localAstcCount,
269 "CLOUD_LCD_COUNT", count.cloudLcdCount,
270 "CLOUD_ASTC_COUNT", count.cloudAstcCount,
271 "PHASE_DETAIL", MediaLibraryAstcStat::GetInstance().GetJson());
272 if (ret != 0) {
273 MEDIA_ERR_LOG("ReportAstcInfo error:%{public}d", ret);
274 } else {
275 MediaLibraryAstcStat::GetInstance().ClearOldData();
276 }
277 }
278
ReportAlbumInfo(const std::string & albumName,int32_t albumImageCount,int32_t albumVideoCount,bool isLocal)279 void DfxReporter::ReportAlbumInfo(const std::string &albumName, int32_t albumImageCount, int32_t albumVideoCount,
280 bool isLocal)
281 {
282 int ret = HiSysEventWrite(
283 MEDIA_LIBRARY,
284 "MEDIALIB_ALBUM_INFO",
285 HiviewDFX::HiSysEvent::EventType::STATISTIC,
286 "ALBUM_NAME", albumName,
287 "ALBUM_IMAGE_COUNT", albumImageCount,
288 "ALBUM_VIDEO_COUNT", albumVideoCount,
289 "IS_LOCAL", isLocal);
290 if (ret != 0) {
291 MEDIA_ERR_LOG("ReportAlbumInfo error:%{public}d", ret);
292 }
293 }
294
ReportDirtyCloudPhoto(const std::string & data,int32_t dirty,int32_t cloudVersion)295 void DfxReporter::ReportDirtyCloudPhoto(const std::string &data, int32_t dirty, int32_t cloudVersion)
296 {
297 int ret = HiSysEventWrite(
298 MEDIA_LIBRARY,
299 "MEDIALIB_DIRTY_CLOUD_PHOTO",
300 HiviewDFX::HiSysEvent::EventType::STATISTIC,
301 "PATH", data,
302 "DIRTY", dirty,
303 "CLOUD_VERSION", cloudVersion);
304 if (ret != 0) {
305 MEDIA_ERR_LOG("ReportDirtyCloudPhoto error:%{public}d", ret);
306 }
307 }
308
ReportCommonVersion(int32_t dbVersion)309 void DfxReporter::ReportCommonVersion(int32_t dbVersion)
310 {
311 MEDIA_INFO_LOG("dbVersion: %{public}d, thumbnailVersion: %{public}d", dbVersion, THUMBNAIL_VERSION);
312 int ret = HiSysEventWrite(
313 MEDIA_LIBRARY,
314 "MEDIALIB_COMMON_VERSION",
315 HiviewDFX::HiSysEvent::EventType::STATISTIC,
316 "DB_VERSION", dbVersion,
317 "THUMBNAIL_VERSION", THUMBNAIL_VERSION);
318 if (ret != 0) {
319 MEDIA_ERR_LOG("ReportCommonVersion error:%{public}d", ret);
320 }
321 }
322
ReportAnalysisVersion(const std::string & analysisName,int32_t version)323 void DfxReporter::ReportAnalysisVersion(const std::string &analysisName, int32_t version)
324 {
325 int ret = HiSysEventWrite(
326 MEDIA_LIBRARY,
327 "MEDIALIB_ANALYSIS_VERSION",
328 HiviewDFX::HiSysEvent::EventType::STATISTIC,
329 "NAME", analysisName,
330 "VERSION", version);
331 if (ret != 0) {
332 MEDIA_ERR_LOG("ReportAnalysisVersion error:%{public}d", ret);
333 }
334 }
335
ReportAdaptationToMovingPhoto()336 void DfxReporter::ReportAdaptationToMovingPhoto()
337 {
338 int32_t errCode;
339 shared_ptr<NativePreferences::Preferences> prefs =
340 NativePreferences::PreferencesHelper::GetPreferences(ADAPTATION_TO_MOVING_PHOTO_XML, errCode);
341 if (!prefs) {
342 MEDIA_ERR_LOG("get preferences error: %{public}d", errCode);
343 return;
344 }
345
346 string date = DfxUtils::GetCurrentDate();
347 string unadaptedAppPackages = prefs->GetString(MOVING_PHOTO_KEY_UNADAPTED_PACKAGE);
348 string adaptedAppPackages = prefs->GetString(MOVING_PHOTO_KEY_ADAPTED_PACKAGE);
349 int32_t unadaptedAppNum = prefs->GetInt(MOVING_PHOTO_KEY_UNADAPTED_NUM);
350 int32_t adaptedAppNum = prefs->GetInt(MOVING_PHOTO_KEY_ADAPTED_NUM);
351
352 int ret = HiSysEventWrite(
353 MEDIA_LIBRARY,
354 "MEDIALIB_MOVING_PHOTO_ADAPT",
355 HiviewDFX::HiSysEvent::EventType::STATISTIC,
356 "DATE", date,
357 "UNADAPTED_APP_NUM", unadaptedAppNum,
358 "UNADAPTED_APP_PACKAGE", unadaptedAppPackages,
359 "ADAPTED_APP_NUM", adaptedAppNum,
360 "ADAPTED_APP_PACKAGE", adaptedAppPackages);
361 if (ret != 0) {
362 MEDIA_ERR_LOG("Report adaptation to moving photo error:%{public}d", ret);
363 }
364
365 prefs->Clear();
366 prefs->FlushSync();
367 }
368
ReportStartResult(int32_t scene,int32_t error,int32_t start)369 void DfxReporter::ReportStartResult(int32_t scene, int32_t error, int32_t start)
370 {
371 int32_t cost = static_cast<int32_t>(MediaFileUtils::UTCTimeMilliSeconds() - start);
372 MEDIA_ERR_LOG("SCENE:%{public}d, ERROR:%{public}d, TIME:%{public}d", scene, error, cost);
373 int ret = HiSysEventWrite(
374 MEDIA_LIBRARY,
375 "MEDIALIB_START_RESULT",
376 HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
377 "SCENE", scene,
378 "ERROR", error,
379 "TIME", cost);
380 if (ret != 0) {
381 MEDIA_ERR_LOG("Report startResult error:%{public}d", ret);
382 }
383 }
384
SecondsToTime(const int64_t & seconds)385 std::string SecondsToTime(const int64_t& seconds)
386 {
387 int32_t remain_seconds = seconds;
388 int32_t hour = seconds / ONE_HOUR;
389 remain_seconds = seconds - ONE_HOUR * hour;
390 int32_t minute = remain_seconds / ONE_MINUTE;
391 remain_seconds = remain_seconds - minute * ONE_MINUTE;
392 return std::to_string(hour) + "_h_" + std::to_string(minute) + "_m_" + std::to_string(remain_seconds) + "_s";
393 }
394
ReportCloudSyncThumbGenerationStatus(const int32_t & downloadedThumb,const int32_t & generatedThumb,const int32_t & totalDownload)395 int32_t DfxReporter::ReportCloudSyncThumbGenerationStatus(const int32_t& downloadedThumb,
396 const int32_t& generatedThumb, const int32_t& totalDownload)
397 {
398 if (totalDownload == 0) {
399 return 0;
400 }
401 int32_t errCode;
402 shared_ptr<NativePreferences::Preferences> prefs =
403 NativePreferences::PreferencesHelper::GetPreferences(DFX_COMMON_XML, errCode);
404 if (!prefs) {
405 MEDIA_ERR_LOG("get dfx common preferences error: %{public}d", errCode);
406 return 0;
407 }
408 int64_t start = prefs->GetLong(CLOUD_SYNC_START_TIME, 0);
409 int64_t now = MediaFileUtils::UTCTimeSeconds();
410 int64_t cost = now - start;
411 time_t startTime = start + ONE_HOUR * 8;
412 std::string astcStartTime = asctime(gmtime(&startTime));
413 float total = static_cast<float>(totalDownload);
414 int ret = HiSysEventWrite(
415 MEDIA_LIBRARY,
416 "CLOUD_THUMB_GENERATE_STATISTIC",
417 HiviewDFX::HiSysEvent::EventType::STATISTIC,
418 "CLOUD_DOWN_START", astcStartTime,
419 "DOWNLOADED_THUMB_NUM", downloadedThumb,
420 "DOWNLOADED_THUMB_RATIO", downloadedThumb / total,
421 "GENERATED_THUMB_NUM", generatedThumb,
422 "GENERATED_THUMB_RATIO", generatedThumb / total,
423 "CLOUD_DOWN_TOTAL_DURATION", SecondsToTime(cost));
424 if (ret != 0) {
425 MEDIA_ERR_LOG("Report CloudSyncThumbGenerationStatus error:%{public}d", ret);
426 }
427 return ret;
428 }
429
GetWatchListInfo()430 static string GetWatchListInfo()
431 {
432 auto watch = MediaLibraryInotify::GetInstance();
433 if (watch == nullptr) {
434 MEDIA_ERR_LOG("MediaLibraryInotify GetInstance fail");
435 return "";
436 }
437 return watch->BuildDfxInfo();
438 }
439
ReportPhotoRecordInfo()440 void DfxReporter::ReportPhotoRecordInfo()
441 {
442 PhotoRecordInfo photoRecordInfo;
443 int32_t result = DfxDatabaseUtils::QueryPhotoRecordInfo(photoRecordInfo);
444 if (result != 0) {
445 MEDIA_ERR_LOG("QueryPhotoRecordInfo error:%{public}d", result);
446 return;
447 }
448 int32_t imageCount = photoRecordInfo.imageCount;
449 int32_t videoCount = photoRecordInfo.videoCount;
450 int32_t abnormalSizeCount = photoRecordInfo.abnormalSizeCount;
451 int32_t abnormalWidthOrHeightCount = photoRecordInfo.abnormalWidthOrHeightCount;
452 int32_t abnormalVideoDurationCount = photoRecordInfo.abnormalVideoDurationCount;
453 int32_t toBeUpdatedRecordCount = photoRecordInfo.toBeUpdatedRecordCount;
454 int64_t dbFileSize = photoRecordInfo.dbFileSize;
455 int32_t duplicateLpathCount = photoRecordInfo.duplicateLpathCount;
456 int32_t abnormalLpathCount = photoRecordInfo.abnormalLpathCount;
457 int ret = HiSysEventWrite(
458 MEDIA_LIBRARY,
459 "MEDIALIB_DATABASE_INFO",
460 HiviewDFX::HiSysEvent::EventType::STATISTIC,
461 "DB_FILE_SIZE", dbFileSize,
462 "REPLICA_DB_FILE_SIZE", photoRecordInfo.slaveDbFileSize,
463 "IMAGE_COUNT", imageCount,
464 "VIDEO_COUNT", videoCount,
465 "ABNORMAL_SIZE_COUNT", abnormalSizeCount,
466 "ABNORMAL_WIDTH_OR_HEIGHT_COUNT", abnormalWidthOrHeightCount,
467 "ABNORMAL_VIDEO_DURATION_COUNT", abnormalVideoDurationCount,
468 "ABNORMAL_COUNT_TO_UPDATE", toBeUpdatedRecordCount,
469 "DUPLICATE_LPATH_COUNT", duplicateLpathCount,
470 "ABNORMAL_LPATH_COUNT", abnormalLpathCount,
471 "WATCH_LIST_INFO", GetWatchListInfo());
472 if (ret != 0) {
473 MEDIA_ERR_LOG("ReportPhotoRecordInfo error:%{public}d", ret);
474 }
475 }
476
ReportOperationRecordInfo()477 void DfxReporter::ReportOperationRecordInfo()
478 {
479 OperationRecordInfo operationRecordInfo;
480 int32_t result = DfxDatabaseUtils::QueryOperationRecordInfo(operationRecordInfo);
481 if (result != 0) {
482 MEDIA_ERR_LOG("ReportOperationRecordInfo error:%{public}d", result);
483 return;
484 }
485 int32_t addTotalCount = operationRecordInfo.addTotalCount;
486 int32_t delTotalCount = operationRecordInfo.delTotalCount;
487 int32_t updateTotalCount = operationRecordInfo.updateTotalCount;
488 int32_t totalCount = operationRecordInfo.totalCount;
489 int64_t currentTime = MediaFileUtils::UTCTimeMilliSeconds();
490 int ret = HiSysEventWrite(
491 MEDIA_LIBRARY,
492 "MEDIALIB_OPRN_CURRENT_INFO",
493 HiviewDFX::HiSysEvent::EventType::STATISTIC,
494 "CURRENT_OPT_ADD_COUNT", addTotalCount,
495 "CURRENT_OPT_DELETE_COUNT", delTotalCount,
496 "CURRENT_OPT_UPDATE_COUNT", updateTotalCount,
497 "CURRENT_OPT_TOTAL_COUNT", totalCount,
498 "CURRENT_TIME", currentTime);
499 if (ret != 0) {
500 MEDIA_ERR_LOG("ReportOperationRecordInfo error:%{public}d", ret);
501 }
502
503 static int32_t lastAddTotalCount = 0;
504 static int32_t lastDelTotalCount = 0;
505 static int32_t lastUpdateTotalCount = 0;
506 static int32_t lastTotalCount = 0;
507 static int64_t lastOptQueryTime = 0;
508 ret = HiSysEventWrite(
509 MEDIA_LIBRARY,
510 "MEDIALIB_OPRN_CHANGE_INFO",
511 HiviewDFX::HiSysEvent::EventType::STATISTIC,
512 "OPT_ADD_COUNT", addTotalCount - lastAddTotalCount,
513 "OPT_DELETE_COUNT", delTotalCount - lastDelTotalCount,
514 "OPT_UPDATE_COUNT", updateTotalCount - lastUpdateTotalCount,
515 "OPT_TOTAL_COUNT", totalCount - lastTotalCount,
516 "OPT_START_TIME", lastOptQueryTime,
517 "OPT_END_TIME", currentTime);
518
519 lastAddTotalCount = addTotalCount;
520 lastDelTotalCount = delTotalCount;
521 lastUpdateTotalCount = updateTotalCount;
522 lastTotalCount = totalCount;
523 lastOptQueryTime = currentTime;
524 if (ret != 0) {
525 MEDIA_ERR_LOG("ReportOperationRecordInfo last info error:%{public}d", ret);
526 }
527 }
528
ReportMedialibraryAPI(const string & callerPackage,const string & saveUri)529 int32_t DfxReporter::ReportMedialibraryAPI(const string& callerPackage, const string& saveUri)
530 {
531 string currentDate = DfxUtils::GetCurrentDate();
532 int ret = HiSysEventWrite(
533 MEDIA_LIBRARY,
534 "MEDIALIB_DEPRECATED_API_USAGE",
535 HiviewDFX::HiSysEvent::EventType::STATISTIC,
536 "DATE", currentDate,
537 "CALLER_APP_PACKAGE", callerPackage,
538 "SAVE_URI", saveUri,
539 "READ_URI", "");
540 if (ret != 0) {
541 MEDIA_ERR_LOG("ReportMedialibraryAPI failed, ret: %{public}d", ret);
542 return E_FAIL;
543 }
544 return E_SUCCESS;
545 }
546
ReportAlbumFusion(const AlbumFusionDfxDataPoint & reportData)547 int32_t DfxReporter::ReportAlbumFusion(const AlbumFusionDfxDataPoint& reportData)
548 {
549 int ret = HiSysEventWrite(
550 MEDIA_LIBRARY,
551 "MEDIALIB_ALBUM_FUSION_SINGLE",
552 HiviewDFX::HiSysEvent::EventType::STATISTIC,
553 "ALBUM_FUSION_TAG", reportData.albumFusionTag,
554 "REPORT_TIME_STAMP", reportData.reportTimeStamp,
555 "ALBUM_FUSION_STATE", reportData.albumFusionState,
556 "IMAGE_ASSET_COUNT", reportData.imageAssetCount,
557 "VIDEO_ASSET_COUNT", reportData.videoAssetCount,
558 "NUMBER_OF_SOURCE_ALBUM", reportData.numberOfSourceAlbum,
559 "NUMBER_OF_USER_ALBUM", reportData.numberOfUserAlbum,
560 "TOTAL_ASSETS_IN_SOURCE_ALBUMS", reportData.totalAssetsInSourceAlbums,
561 "TOTAL_ASSETS_IN_USER_ALBUMS", reportData.totalAssetsInUserAlbums,
562 "ALBUM_DETAILS", reportData.albumDetails,
563 "HIDDEN_ASSET_COUNT", reportData.hiddenAssetInfo);
564 if (ret != 0) {
565 MEDIA_ERR_LOG("ALBUM FUSION report data failed, ret: %{public}d", ret);
566 return E_FAIL;
567 }
568 return E_SUCCESS;
569 }
570
ReportCustomRestoreFusion(const CustomRestoreDfxDataPoint & reportData)571 int32_t DfxReporter::ReportCustomRestoreFusion(const CustomRestoreDfxDataPoint& reportData)
572 {
573 int ret = HiSysEventWrite(
574 MEDIA_LIBRARY,
575 "MEDIALIB_CUSTOM_RESTORE",
576 HiviewDFX::HiSysEvent::EventType::STATISTIC,
577 "CUSTOM_RESTORE_PACKAGE_NAME", reportData.customRestorePackageName,
578 "ALBUM_LPATH", reportData.albumLPath,
579 "KEY_PATH", reportData.keyPath,
580 "TOTAL_NUM", reportData.totalNum,
581 "SUCCESS_NUM", reportData.successNum,
582 "FAILED_NUM", reportData.failedNum,
583 "SAME_NUM", reportData.sameNum,
584 "CANCEL_NUM", reportData.cancelNum,
585 "TOTAL_TIME", reportData.totalTime);
586 if (ret != 0) {
587 MEDIA_ERR_LOG("Report CustomRestoreFusion error: %{public}d", ret);
588 }
589 return ret;
590 }
591
ReportPhotoError(const PhotoErrorCount & reportData)592 int32_t DfxReporter::ReportPhotoError(const PhotoErrorCount& reportData)
593 {
594 int ret = HiSysEventWrite(
595 MEDIA_LIBRARY,
596 "MEDIALIB_PHOTO_ERROR_STATISTIC",
597 HiviewDFX::HiSysEvent::EventType::STATISTIC,
598 "PHOTO_ERROR_TYPE", reportData.photoErrorTypes,
599 "PHOTO_ERROR_COUNT", reportData.photoErrorCounts);
600 if (ret != 0) {
601 MEDIA_ERR_LOG("Report ReportPhotoError error: %{public}d", ret);
602 }
603 return ret;
604 }
605
ReportSyncFault(const std::string & taskId,const std::string & position,const SyncFaultEvent & event)606 int32_t DfxReporter::ReportSyncFault(const std::string& taskId, const std::string& position,
607 const SyncFaultEvent& event)
608 {
609 int32_t ret = HiSysEventWrite(
610 MEDIA_LIBRARY,
611 "MEDIALIB_SYNC_FAULT",
612 HiviewDFX::HiSysEvent::EventType::FAULT,
613 "TASK_ID", taskId,
614 "FAULT_SCENARIO", static_cast<uint32_t>(event.scenario),
615 "FAULT_TYPE", static_cast<uint32_t>(event.type),
616 "FAULT_ERROR_CODE", event.errorCode,
617 "FUNCTION_NAME", position,
618 "MESSAGE", event.message);
619 if (ret != E_OK) {
620 MEDIA_ERR_LOG("report ReportSyncFault error %{public}d", ret);
621 }
622 return ret;
623 }
624
ReportSyncStat(const std::string & taskId,const CloudSyncInfo & info,const CloudSyncStat & stat,const std::string & syncInfo)625 int32_t DfxReporter::ReportSyncStat(const std::string& taskId, const CloudSyncInfo& info, const CloudSyncStat& stat,
626 const std::string& syncInfo)
627 {
628 int32_t ret = HiSysEventWrite(
629 MEDIA_LIBRARY,
630 "MEDIALIB_SYNC_STAT",
631 HiviewDFX::HiSysEvent::EventType::STATISTIC,
632 "TASK_ID", taskId,
633 "SYNC_REASON", info.syncReason,
634 "STOP_REASON", info.stopReason,
635 "START_TIME", info.startTime,
636 "DURATION", info.duration,
637 "UPLOAD_META", stat.uploadMeta,
638 "DOWNLOAD_META", stat.downloadMeta,
639 "DOWNLOAD_THM", stat.downloadThumb,
640 "DOWNLOAD_LCD", stat.downloadLcd,
641 "UPLOAD_ALBUM", stat.uploadAlbum,
642 "DOWNLOAD_ALBUM", stat.downloadAlbum,
643 "UPLOAD_META_ERR", stat.uploadMetaErr,
644 "SYNC_INFO", syncInfo);
645 if (ret != E_OK) {
646 MEDIA_ERR_LOG("report ReportSyncStat error %{public}d", ret);
647 }
648 return ret;
649 }
650
ReportPhotoSizeAndResolutionInfo(const QuerySizeAndResolution & querySizeAndResolution,const std::string & photoMimeType)651 void DfxReporter::ReportPhotoSizeAndResolutionInfo(const QuerySizeAndResolution& querySizeAndResolution,
652 const std::string& photoMimeType)
653 {
654 int ret = HiSysEventWrite(
655 MEDIA_LIBRARY,
656 "PHOTO_INFO_EXT",
657 HiviewDFX::HiSysEvent::EventType::STATISTIC,
658 "LOCAL_IMAGE_SIZE", querySizeAndResolution.localImageSize,
659 "LOCAL_VIDEO_SIZE", querySizeAndResolution.localVideoSize,
660 "CLOUD_IMAGE_SIZE", querySizeAndResolution.cloudImageSize,
661 "CLOUD_VIDEO_SIZE", querySizeAndResolution.cloudVideoSize,
662 "PHOTO_MIMETYPE", photoMimeType,
663 "LOCAL_IMAGE_RESOLUTION", querySizeAndResolution.localImageResolution,
664 "LOCAL_VIDEO_RESOLUTION", querySizeAndResolution.localVideoResolution,
665 "CLOUD_IMAGE_RESOLUTION", querySizeAndResolution.cloudImageResolution,
666 "CLOUD_VIDEO_RESOLUTION", querySizeAndResolution.cloudVideoResolution,
667 "LOCAL_IMAGE_ROM_SIZE", querySizeAndResolution.localImageRomSize,
668 "LOCAL_VIDEO_ROM_SIZE", querySizeAndResolution.localVideoRomSize,
669 "CACHE_ROM_SIZE", querySizeAndResolution.cacheRomSize,
670 "HIGHLIGHT_ROM_SIZE", querySizeAndResolution.highlightRomSize,
671 "THUMBNAIL_ROM_SIZE", querySizeAndResolution.ThumbnailRomSize,
672 "EDITDATA_ROM_SIZE", querySizeAndResolution.EditdataRomSize);
673 if (ret != 0) {
674 MEDIA_ERR_LOG("Report ReportPhotoSizeAndResolutionInfo error: %{public}d", ret);
675 }
676 }
677
ReportAccurateRefreshResult(const AccurateRefreshDfxDataPoint & reportData)678 void DfxReporter::ReportAccurateRefreshResult(const AccurateRefreshDfxDataPoint& reportData)
679 {
680 std::string bundleName = MediaLibraryBundleManager::GetInstance()->GetClientBundleName();
681 int ret = HiSysEventWrite(
682 MEDIA_LIBRARY,
683 "MEDIALIB_TIMEOUT_ERROR",
684 HiviewDFX::HiSysEvent::EventType::FAULT,
685 "BUNDLE_NAME", bundleName,
686 "SQL", reportData.sqlStr,
687 "TARGET_BUSINESS", reportData.targetBusiness,
688 "TOTAL_COST_TIME", reportData.totalCostTime,
689 "STANDARD_COST_TIME", reportData.standardCostTime,
690 "PHOTO_OPERATION_TOTAL_TIME", reportData.photoOperationTotalTime,
691 "ALBUM_OPERATION_TOTAL_TIME", reportData.albumOperationTotalTime,
692 "ALBUM_ID", reportData.albumId,
693 "ALBUM_OPERATION_TIME", reportData.albumOperationTime,
694 "ALBUM_HIDDEN_INFO_OPERATION_TIME", reportData.albumHiddenInfoOperationTime);
695 if (ret != 0) {
696 MEDIA_ERR_LOG("ReportAccurateRefreshService error:%{public}d", ret);
697 }
698 }
699
700 } // namespace Media
701 } // namespace OHOS