1 /*
2 * Copyright (c) 2022-2025 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 <media_dfx.h>
17
18 #include <cstdint>
19 #include <format>
20 #include <unistd.h>
21
22 #include "securec.h"
23 #include "hitrace/tracechain.h"
24 #include "ipc_skeleton.h"
25 #include "media_utils.h"
26 #include "hitrace/tracechain.h"
27 #include "common/log.h"
28 #include "common/media_core.h"
29 #include "meta/any.h"
30 #include "osal/utils/string_utils.h"
31
32 namespace {
33 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "MediaDFX" };
34
35 constexpr uint32_t MAX_STRING_SIZE = 256;
36 constexpr int64_t HOURS_BETWEEN_REPORTS = 4;
37 constexpr int64_t MAX_MAP_SIZE = 100;
38
39 std::mutex collectMut_;
40 std::mutex reportMut_;
41 std::map<OHOS::Media::CallType,
42 std::map<int32_t, std::list<std::pair<uint64_t, std::shared_ptr<OHOS::Media::Meta>>>>> mediaInfoMap_;
43 std::map<OHOS::Media::CallType,
44 std::map<int32_t, std::list<std::pair<uint64_t, std::shared_ptr<OHOS::Media::Meta>>>>> reportMediaInfoMap_;
45 std::map<uint64_t, std::pair<OHOS::Media::CallType, int32_t>> idMap_;
46 std::chrono::system_clock::time_point currentTime_ = std::chrono::system_clock::now();
47 bool g_reachMaxMapSize {false};
48
CollectReportMediaInfo(uint64_t instanceId)49 bool CollectReportMediaInfo(uint64_t instanceId)
50 {
51 OHOS::Media::CallType ct;
52 int32_t uid;
53 std::pair<uint64_t, std::shared_ptr<OHOS::Media::Meta>> metaAppIdPair;
54 {
55 std::lock_guard<std::mutex> lock(collectMut_);
56 MEDIA_LOG_I("CollectReportMediaInfo, instanceId is %{public}" PRIu64, instanceId);
57 auto idMapIt = idMap_.find(instanceId);
58 if (idMapIt == idMap_.end()) {
59 MEDIA_LOG_W("Not found instanceId in idMap, instanceId is : %{public}" PRIu64, instanceId);
60 return false;
61 }
62 ct = idMapIt->second.first;
63 uid = idMapIt->second.second;
64 idMap_.erase(idMapIt);
65 auto ctUidToMediaInfo = mediaInfoMap_.find(ct);
66 if (ctUidToMediaInfo == mediaInfoMap_.end()) {
67 MEDIA_LOG_W("Not found calltype, calltype is : %{public}d", static_cast<OHOS::Media::CallType>(ct));
68 return false;
69 }
70 auto uidToMediaInfo = ctUidToMediaInfo->second.find(uid);
71 if (uidToMediaInfo == ctUidToMediaInfo->second.end()) {
72 MEDIA_LOG_W("Not found uid in mediaInfoMap_, uid is : %{public}" PRId32, uid);
73 return false;
74 }
75 auto& instanceList = uidToMediaInfo->second;
76 for (const auto& instancePair : instanceList) {
77 if (instancePair.first == instanceId) {
78 metaAppIdPair = instancePair;
79 instanceList.remove(instancePair);
80 break;
81 }
82 }
83 }
84 std::lock_guard<std::mutex> lock(reportMut_);
85 auto reportCtUidToMediaInfo = reportMediaInfoMap_.find(ct);
86 if (reportCtUidToMediaInfo != reportMediaInfoMap_.end()) {
87 auto it = reportCtUidToMediaInfo->second.find(uid);
88 if (it != reportCtUidToMediaInfo->second.end()) {
89 it->second.push_back(metaAppIdPair);
90 } else {
91 reportCtUidToMediaInfo->second[uid].push_back(metaAppIdPair);
92 }
93 } else {
94 reportMediaInfoMap_[ct][uid].push_back(metaAppIdPair);
95 }
96 g_reachMaxMapSize = (reportMediaInfoMap_[ct].size() >= MAX_MAP_SIZE);
97 return true;
98 }
99
StatisticsEventReport()100 int32_t StatisticsEventReport()
101 {
102 MEDIA_LOG_I("StatisticsEventReport.");
103 if (reportMediaInfoMap_.empty()) {
104 MEDIA_LOG_I("reportMediaInfoMap_ is empty, can't report");
105 return OHOS::Media::MSERR_INVALID_OPERATION;
106 }
107 OHOS::Media::MediaEvent event;
108 for (const auto &it : reportMediaInfoMap_) {
109 event.CommonStatisicsEventWrite(it.first, OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC, it.second);
110 }
111 auto currentTime = std::chrono::system_clock::now();
112 currentTime_ = currentTime;
113 reportMediaInfoMap_.clear();
114 return OHOS::Media::MSERR_OK;
115 }
116 }
117
118 namespace OHOS {
119 namespace Media {
120 using namespace OHOS::HiviewDFX;
CreateMsg(const char * format,...)121 bool MediaEvent::CreateMsg(const char *format, ...)
122 {
123 va_list args;
124 va_start(args, format);
125 char msg[MAX_STRING_SIZE] = {0};
126 auto ret = vsnprintf_s(msg, sizeof(msg), sizeof(msg) - 1, format, args);
127 va_end(args);
128 msg_ = msg;
129 return ret < 0 ? false : true;
130 }
131
EventWrite(std::string eventName,OHOS::HiviewDFX::HiSysEvent::EventType type,std::string module)132 void MediaEvent::EventWrite(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type,
133 std::string module)
134 {
135 int32_t pid = getpid();
136 uint32_t uid = getuid();
137 HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MEDIA, eventName, type,
138 "PID", pid,
139 "UID", uid,
140 "MODULE", module,
141 "MSG", msg_);
142 }
143
EventWriteWithAppInfo(std::string eventName,OHOS::HiviewDFX::HiSysEvent::EventType type,std::string module,std::string status,int32_t appUid,int32_t appPid)144 void MediaEvent::EventWriteWithAppInfo(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type,
145 std::string module, std::string status, int32_t appUid, int32_t appPid)
146 {
147 int32_t pid = getpid();
148 uint32_t uid = getuid();
149 HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MEDIA, eventName, type,
150 "PID", pid,
151 "UID", uid,
152 "MODULE", module,
153 "MSG", msg_,
154 "APP_PID", appPid,
155 "APP_UID", appUid,
156 "STATUS", status);
157 }
158
EventWriteBundleName(std::string eventName,OHOS::HiviewDFX::HiSysEvent::EventType type,std::string module,std::string status,int32_t appUid,int32_t appPid,std::string bundleName)159 void MediaEvent::EventWriteBundleName(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type,
160 std::string module, std::string status, int32_t appUid, int32_t appPid, std::string bundleName)
161 {
162 int32_t pid = getpid();
163 uint32_t uid = getuid();
164 HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MEDIA, eventName, type,
165 "PID", pid,
166 "UID", uid,
167 "MODULE", module,
168 "MSG", msg_,
169 "APP_PID", appPid,
170 "APP_UID", appUid,
171 "STATUS", status,
172 "BUNDLE", bundleName);
173 }
174
SourceEventWrite(const std::string & eventName,OHOS::HiviewDFX::HiSysEvent::EventType type,const std::string & appName,uint64_t instanceId,const std::string & callerType,int8_t sourceType,const std::string & sourceUrl,const std::string & errMsg)175 void MediaEvent::SourceEventWrite(const std::string& eventName, OHOS::HiviewDFX::HiSysEvent::EventType type,
176 const std::string& appName, uint64_t instanceId, const std::string& callerType, int8_t sourceType,
177 const std::string& sourceUrl, const std::string& errMsg)
178 {
179 std::string instanceIdStr = std::to_string(instanceId);
180 HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MEDIA, eventName, type,
181 "APP_NAME", appName,
182 "INSTANCE_ID", instanceIdStr,
183 "CALLER_TYPE", callerType,
184 "SOURCE_TYPE", sourceType,
185 "SOURCE_URI", sourceUrl,
186 "ERROR_MESG", errMsg);
187 }
188
ScreenCaptureEventWrite(const std::string & eventName,OHOS::HiviewDFX::HiSysEvent::EventType type,const std::string & appName,uint64_t instanceId,int8_t captureMode,int8_t dataMode,int32_t errorCode,const std::string & errorMessage)189 void MediaEvent::ScreenCaptureEventWrite(const std::string& eventName, OHOS::HiviewDFX::HiSysEvent::EventType type,
190 const std::string& appName, uint64_t instanceId, int8_t captureMode, int8_t dataMode, int32_t errorCode,
191 const std::string& errorMessage)
192 {
193 std::string instanceIdStr = std::to_string(instanceId);
194 HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MEDIA, eventName, type,
195 "APP_NAME", appName,
196 "INSTANCE_ID", instanceIdStr,
197 "CAPTURE_MODE", captureMode,
198 "DATA_MODE", dataMode,
199 "ERROR_CODE", errorCode,
200 "ERROR_MESG", errorMessage);
201 }
202
CommonStatisicsEventWrite(CallType callType,OHOS::HiviewDFX::HiSysEvent::EventType type,const std::map<int32_t,std::list<std::pair<uint64_t,std::shared_ptr<Meta>>>> & infoMap)203 void MediaEvent::CommonStatisicsEventWrite(CallType callType, OHOS::HiviewDFX::HiSysEvent::EventType type,
204 const std::map<int32_t, std::list<std::pair<uint64_t, std::shared_ptr<Meta>>>>& infoMap)
205 {
206 MEDIA_LOG_I("MediaEvent::CommonStatisicsEventWrite");
207 if (infoMap.empty()) {
208 MEDIA_LOG_I("Player infoMap is empty.");
209 return;
210 }
211 std::vector<std::string> infoArr;
212 #ifndef CROSS_PLATFORM
213 for (const auto& kv : infoMap) {
214 json jsonArray;
215 json eventInfoJson;
216 json mediaEvents;
217 for (const auto& listPair : kv.second) {
218 json metaInfoJson;
219 ParseOneEvent(listPair, metaInfoJson);
220 mediaEvents.push_back(metaInfoJson);
221 }
222 eventInfoJson["appName"] = GetClientBundleName(kv.first);
223 eventInfoJson["mediaEvents"] = mediaEvents;
224 jsonArray.push_back(eventInfoJson);
225 infoArr.push_back(jsonArray.dump());
226 }
227 #endif
228 StatisicsHiSysEventWrite(callType, type, infoArr);
229 }
230
231 #ifndef CROSS_PLATFORM
ParseOneEvent(const std::pair<uint64_t,std::shared_ptr<OHOS::Media::Meta>> & listPair,json & metaInfoJson)232 void MediaEvent::ParseOneEvent(const std::pair<uint64_t, std::shared_ptr<OHOS::Media::Meta>> &listPair,
233 json& metaInfoJson)
234 {
235 for (auto it = listPair.second->begin(); it != listPair.second->end(); ++it) {
236 Any valueType = OHOS::Media::GetDefaultAnyValue(it->first);
237 if (Any::IsSameTypeWith<int32_t>(valueType)) {
238 int32_t intVal;
239 if (listPair.second->GetData(it->first, intVal)) {
240 metaInfoJson[it->first] = std::to_string(intVal);
241 }
242 } else if (Any::IsSameTypeWith<uint32_t>(valueType)) {
243 uint32_t uintVal;
244 if (listPair.second->GetData(it->first, uintVal)) {
245 metaInfoJson[it->first] = std::to_string(uintVal);
246 }
247 } else if (Any::IsSameTypeWith<uint64_t>(valueType)) {
248 uint64_t uintVal;
249 if (listPair.second->GetData(it->first, uintVal)) {
250 metaInfoJson[it->first] = std::to_string(uintVal);
251 }
252 } else if (Any::IsSameTypeWith<std::string>(valueType)) {
253 std::string strVal;
254 if (listPair.second->GetData(it->first, strVal)) {
255 metaInfoJson[it->first] = strVal;
256 }
257 } else if (Any::IsSameTypeWith<int8_t>(valueType)) {
258 int8_t intVal;
259 if (listPair.second->GetData(it->first, intVal)) {
260 metaInfoJson[it->first] = std::to_string(intVal);
261 }
262 } else if (Any::IsSameTypeWith<bool>(valueType)) {
263 bool isTrue;
264 if (listPair.second->GetData(it->first, isTrue)) {
265 metaInfoJson[it->first] = isTrue ? "true" : "false";
266 }
267 } else if (Any::IsSameTypeWith<float>(valueType)) {
268 float floatVal = 0.0f;
269 if (listPair.second->GetData(it->first, floatVal)) {
270 metaInfoJson[it->first] = OSAL::FloatToString(floatVal);
271 }
272 } else {
273 MEDIA_LOG_I("not found type matched with it->first: %{public}s", it->first.c_str());
274 }
275 }
276 }
277 #endif
278
StatisicsHiSysEventWrite(CallType callType,OHOS::HiviewDFX::HiSysEvent::EventType type,const std::vector<std::string> & infoArr)279 void MediaEvent::StatisicsHiSysEventWrite(CallType callType, OHOS::HiviewDFX::HiSysEvent::EventType type,
280 const std::vector<std::string>& infoArr)
281 {
282 MEDIA_LOG_I("MediaEvent::StatisicsHiSysEventWrite");
283 std::string eventName;
284 switch (callType) {
285 case CallType::AVPLAYER:
286 eventName = "PLAYER_COMMON_STATISTICS";
287 break;
288 case CallType::AVRECORDER:
289 eventName = "RECORDER_STATISTICS";
290 break;
291 case CallType::SCREEN_CAPTRUER:
292 eventName = "SCREEN_CAPTURE_STATISTICS";
293 break;
294 case CallType::AVTRANSCODER:
295 eventName = "TRANSCODER_STATISTICS";
296 break;
297 default:
298 return;
299 }
300 HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MEDIA, eventName, type,
301 "EVENTS", infoArr);
302 }
303
BehaviorEventWrite(std::string status,std::string module)304 void BehaviorEventWrite(std::string status, std::string module)
305 {
306 MediaEvent event;
307 if (event.CreateMsg("%s, current state is: %s", "state change", status.c_str())) {
308 event.EventWrite("PLAYER_STATE", OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, module);
309 }
310 }
311
BehaviorEventWriteForScreenCapture(std::string status,std::string module,int32_t appUid,int32_t appPid)312 void BehaviorEventWriteForScreenCapture(std::string status, std::string module, int32_t appUid, int32_t appPid)
313 {
314 MediaEvent event;
315 if (event.CreateMsg("%s, current state is: %s", "state change", status.c_str())) {
316 event.EventWriteWithAppInfo("PLAYER_STATE", OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
317 module, status, appUid, appPid);
318 }
319 }
320
StatisticEventWriteBundleName(std::string status,std::string module,std::string bundleName)321 void StatisticEventWriteBundleName(std::string status, std::string module, std::string bundleName)
322 {
323 MediaEvent event;
324 int32_t appUid = IPCSkeleton::GetCallingUid();
325 int32_t appPid = IPCSkeleton::GetCallingPid();
326 if (bundleName == "") {
327 bundleName = GetClientBundleName(appUid);
328 }
329 if (event.CreateMsg("%s is invoke %s", bundleName.c_str(), module.c_str())) {
330 event.EventWriteBundleName("PLAYER_STATISTICS", OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC,
331 module, status, appUid, appPid, bundleName);
332 }
333 }
334
FaultEventWrite(std::string msg,std::string module)335 void FaultEventWrite(std::string msg, std::string module)
336 {
337 MediaEvent event;
338 if (event.CreateMsg("%s", msg.c_str())) {
339 event.EventWrite("PLAYER_ERR", OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, module);
340 }
341 }
342
FaultSourceEventWrite(const std::string & appName,uint64_t instanceId,const std::string & callerType,int8_t sourceType,const std::string & sourceUrl,const std::string & errorMessage)343 void FaultSourceEventWrite(const std::string& appName, uint64_t instanceId, const std::string& callerType,
344 int8_t sourceType, const std::string& sourceUrl, const std::string& errorMessage)
345 {
346 MediaEvent event;
347 event.SourceEventWrite("SOURCE_FAILURE", OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, appName, instanceId,
348 callerType, sourceType, sourceUrl, errorMessage);
349 }
350
FaultScreenCaptureEventWrite(const std::string & appName,uint64_t instanceId,int8_t captureMode,int8_t dataMode,int32_t errorCode,const std::string & errorMessage)351 void FaultScreenCaptureEventWrite(const std::string& appName, uint64_t instanceId, int8_t captureMode, int8_t dataMode,
352 int32_t errorCode, const std::string& errorMessage)
353 {
354 MediaEvent event;
355 event.ScreenCaptureEventWrite("SCREEN_CAPTURE_FAILURE", OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, appName,
356 instanceId, captureMode, dataMode, errorCode, errorMessage);
357 }
358
CreateMediaInfo(CallType callType,int32_t uid,uint64_t instanceId)359 int32_t CreateMediaInfo(CallType callType, int32_t uid, uint64_t instanceId)
360 {
361 MEDIA_LOG_I("CreateMediaInfo uid is: %{public}" PRId32 " instanceId is: %{public}" PRIu64, uid, instanceId);
362 std::lock_guard<std::mutex> lock(collectMut_);
363 auto instanceIdMap = idMap_.find(instanceId);
364 if (instanceIdMap != idMap_.end()) {
365 MEDIA_LOG_I("instanceId already exists id idMap_");
366 return MSERR_INVALID_VAL;
367 } else {
368 MEDIA_LOG_I("CreateMediaInfo not found instanceId in idMap_, add the instanceId to idMap_");
369 std::pair<CallType, int32_t> insertToMapPair(callType, uid);
370 idMap_[instanceId] = insertToMapPair;
371 }
372 std::shared_ptr<Meta> meta = std::make_shared<Meta>();
373 std::pair<uint64_t, std::shared_ptr<Meta>> metaAppIdPair(instanceId, meta);
374 auto ctUidToMediaInfo = mediaInfoMap_.find(callType);
375 if (ctUidToMediaInfo != mediaInfoMap_.end()) {
376 auto it = ctUidToMediaInfo->second.find(uid);
377 if (it != ctUidToMediaInfo->second.end()) {
378 it->second.push_back(metaAppIdPair);
379 MEDIA_LOG_I("CreateMediaInfo: Successfully inserted metaAppIdPair for uid ");
380 } else {
381 ctUidToMediaInfo->second[uid].push_back(metaAppIdPair);
382 MEDIA_LOG_I("CreateMediaInfo: Successfully created new list for uid and inserted metaAppIdPair.");
383 }
384 } else {
385 mediaInfoMap_[callType][uid].push_back(metaAppIdPair);
386 MEDIA_LOG_I("CreateMediaInfo: Successfully created new list for callType and uid ");
387 }
388 return MSERR_OK;
389 }
390
AppendMediaInfo(const std::shared_ptr<Meta> & meta,uint64_t instanceId)391 int32_t AppendMediaInfo(const std::shared_ptr<Meta>& meta, uint64_t instanceId)
392 {
393 MEDIA_LOG_I("AppendMediaInfo.");
394 if (meta == nullptr || meta->Empty()) {
395 MEDIA_LOG_I("Insert meta is empty.");
396 return MSERR_INVALID_OPERATION;
397 }
398 std::lock_guard<std::mutex> lock(collectMut_);
399 auto idMapIt = idMap_.find(instanceId);
400 if (idMapIt == idMap_.end()) {
401 MEDIA_LOG_I("Not found instanceId when append meta, instanceId is : %{public}" PRIu64, instanceId);
402 return MSERR_INVALID_VAL;
403 }
404 CallType ct = idMapIt->second.first;
405 int32_t uid = idMapIt->second.second;
406 auto ctUidToMediaInfo = mediaInfoMap_.find(ct);
407 if (ctUidToMediaInfo == mediaInfoMap_.end()) {
408 MEDIA_LOG_I("Not found calltype when append meta, calltype is : %{public}d", static_cast<CallType>(ct));
409 return MSERR_INVALID_OPERATION;
410 }
411 auto it = ctUidToMediaInfo->second.find(uid);
412 if (it == ctUidToMediaInfo->second.end()) {
413 MEDIA_LOG_I("Not found uid when append meta, uid is : %{public}" PRId32, uid);
414 return MSERR_INVALID_OPERATION;
415 }
416 auto& instanceList = it->second;
417 for (const auto& instancePair : instanceList) {
418 if (instancePair.first == instanceId) {
419 auto arg = meta->begin();
420 while (arg != meta->end()) {
421 instancePair.second->SetData(arg->first, arg->second);
422 ++arg;
423 }
424 break;
425 }
426 }
427 return MSERR_OK;
428 }
429
ReportMediaInfo(uint64_t instanceId)430 int32_t ReportMediaInfo(uint64_t instanceId)
431 {
432 MEDIA_LOG_I("Report.");
433 MEDIA_LOG_I("Delete media info instanceId is: %{public}" PRIu64, instanceId);
434 if (!CollectReportMediaInfo(instanceId)) {
435 MEDIA_LOG_I("Collect media info fail.");
436 return MSERR_INVALID_OPERATION;
437 }
438 std::lock_guard<std::mutex> lock(reportMut_);
439 if (g_reachMaxMapSize) {
440 MEDIA_LOG_I("Event data size exceeds 100, report the event");
441 g_reachMaxMapSize = false;
442 return StatisticsEventReport();
443 }
444 auto currentTime = std::chrono::system_clock::now();
445 auto diff = currentTime - currentTime_;
446 auto hour = std::chrono::duration_cast<std::chrono::hours>(diff).count();
447 if (hour >= HOURS_BETWEEN_REPORTS) {
448 MEDIA_LOG_I("Over 4 hours, report the event");
449 return StatisticsEventReport();
450 }
451 return MSERR_OK;
452 }
453
GetMediaInfoContainInstanceNum()454 uint64_t GetMediaInfoContainInstanceNum()
455 {
456 uint64_t mediaInsNum = 0;
457 {
458 std::lock_guard<std::mutex> lock(collectMut_);
459 for (const auto &typeUid : mediaInfoMap_) {
460 for (const auto &uidIns : typeUid.second) {
461 mediaInsNum += uidIns.second.size();
462 }
463 }
464 }
465 uint64_t reportInsNum = 0;
466 {
467 std::lock_guard<std::mutex> lock(reportMut_);
468 for (const auto &typeUid : reportMediaInfoMap_) {
469 for (const auto &uidIns : typeUid.second) {
470 reportInsNum += uidIns.second.size();
471 }
472 }
473 }
474 MEDIA_LOG_I("MediaInfo instances %{public}" PRIu64 ", ReportInfo instances %{public}" PRIu64,
475 mediaInsNum, reportInsNum);
476 return mediaInsNum + reportInsNum;
477 }
478
MediaTrace(const std::string & funcName,HiTraceOutputLevel level,const std::string & customArgs)479 MediaTrace::MediaTrace(const std::string &funcName, HiTraceOutputLevel level, const std::string &customArgs)
480 {
481 StartTraceEx(level, HITRACE_TAG_ZMEDIA, funcName.c_str(), customArgs.c_str());
482 level_ = level;
483 }
484
TraceBegin(const std::string & funcName,int32_t taskId,HiTraceOutputLevel level,const std::string & customCategory,const std::string & customArgs)485 void MediaTrace::TraceBegin(const std::string &funcName, int32_t taskId, HiTraceOutputLevel level,
486 const std::string &customCategory, const std::string &customArgs)
487 {
488 StartAsyncTraceEx(level, HITRACE_TAG_ZMEDIA, funcName.c_str(), taskId, customCategory.c_str(), customArgs.c_str());
489 }
490
TraceEnd(const std::string & funcName,int32_t taskId,HiTraceOutputLevel level)491 void MediaTrace::TraceEnd(const std::string &funcName, int32_t taskId, HiTraceOutputLevel level)
492 {
493 FinishAsyncTraceEx(level, HITRACE_TAG_ZMEDIA, funcName.c_str(), taskId);
494 }
495
CounterTrace(const std::string & varName,int32_t val,HiTraceOutputLevel level)496 void MediaTrace::CounterTrace(const std::string &varName, int32_t val, HiTraceOutputLevel level)
497 {
498 CountTraceEx(level, HITRACE_TAG_ZMEDIA, varName.c_str(), val);
499 }
500
~MediaTrace()501 MediaTrace::~MediaTrace()
502 {
503 FinishTraceEx(level_, HITRACE_TAG_ZMEDIA);
504 }
505 } // namespace Media
506 } // namespace OHOS
507