• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef MEDIA_DFX_H
17 #define MEDIA_DFX_H
18 
19 #include <cstring>
20 #include <list>
21 #include <memory>
22 #include <map>
23 #include <string>
24 #include <refbase.h>
25 #include "nocopyable.h"
26 #include "hisysevent.h"
27 #include "hitrace_meter.h"
28 #include "meta/meta.h"
29 #ifndef CROSS_PLATFORM
30 #include "nlohmann/json.hpp"
31 #endif
32 #include <chrono>
33 #include <mutex>
34 
35 namespace OHOS {
36 namespace Media {
37 #ifndef CROSS_PLATFORM
38 using json = nlohmann::json;
39 #endif
40 enum CallType {
41     AVPLAYER,
42     AVRECORDER,
43     METADATA_RETRIEVER,
44     IMAGE_GENERATER,
45     AVDEMUXER,
46     AVMUXER,
47     VIDEO_DECODER,
48     VIDEO_ENCODER,
49     AUDIO_DECODER,
50     AUDIO_ENCODER,
51     SOUNDPOOL,
52     SCREEN_CAPTRUER,
53     AVTRANSCODER
54 };
55 class __attribute__((visibility("default"))) MediaEvent : public NoCopyable {
56 public:
57     MediaEvent() = default;
58     ~MediaEvent() = default;
59     bool CreateMsg(const char *format, ...) __attribute__((__format__(printf, 2, 3)));
60     void EventWrite(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type,
61         std::string module);
62     void EventWriteWithAppInfo(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type,
63         std::string module, std::string status, int32_t appUid, int32_t appPid);
64     void EventWriteBundleName(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type,
65         std::string module, std::string status, int32_t appUid, int32_t appPid, std::string bundleName);
66     void SourceEventWrite(const std::string& eventName, OHOS::HiviewDFX::HiSysEvent::EventType type, const std::string&
67         appName, uint64_t instanceId, const std::string& callerType, int8_t sourceType, const std::string& sourceUrl,
68         const std::string& errMsg);
69     void ScreenCaptureEventWrite(const std::string& eventName, OHOS::HiviewDFX::HiSysEvent::EventType type,
70         const std::string& appName, uint64_t instanceId, int8_t captureMode, int8_t dataMode, int32_t errorCode,
71         const std::string& errMsg);
72     void CommonStatisicsEventWrite(CallType callType, OHOS::HiviewDFX::HiSysEvent::EventType type,
73         const std::map<int32_t, std::list<std::pair<uint64_t, std::shared_ptr<Meta>>>>& infoMap);
74 private:
75     void StatisicsHiSysEventWrite(CallType callType, OHOS::HiviewDFX::HiSysEvent::EventType type,
76         const std::vector<std::string>& infoArr);
77 #ifndef CROSS_PLATFORM
78     void ParseOneEvent(const std::pair<uint64_t, std::shared_ptr<OHOS::Media::Meta>> &listPair, json& metaInfoJson);
79 #endif
80     std::string msg_;
81 };
82 
83 
84 __attribute__((visibility("default"))) void BehaviorEventWrite(std::string status, std::string module);
85 __attribute__((visibility("default"))) void BehaviorEventWriteForScreenCapture(std::string status,
86     std::string module, int32_t appUid, int32_t appPid);
87 __attribute__((visibility("default"))) void StatisticEventWriteBundleName(std::string status,
88     std::string module, std::string bundleName = "");
89 __attribute__((visibility("default"))) void FaultEventWrite(std::string msg, std::string module);
90 __attribute__((visibility("default"))) void FaultSourceEventWrite(const std::string& appName, uint64_t instanceId,
91     const std::string& callerType, int8_t sourceType, const std::string& sourceUrl, const std::string& errorMessage);
92 __attribute__((visibility("default"))) void FaultScreenCaptureEventWrite(const std::string& appName,
93     uint64_t instanceId, int8_t captureMode, int8_t dataMode, int32_t errorCode, const std::string& errorMessage);
94 __attribute__((visibility("default"))) int32_t CreateMediaInfo(CallType callType, int32_t uid, uint64_t instanceId);
95 __attribute__((visibility("default"))) int32_t AppendMediaInfo(const std::shared_ptr<Meta>& meta, uint64_t instanceId);
96 __attribute__((visibility("default"))) int32_t ReportMediaInfo(uint64_t instanceId);
97 __attribute__((visibility("default"))) uint64_t GetMediaInfoContainInstanceNum();
98 
99 class __attribute__((visibility("default"))) MediaTrace : public NoCopyable {
100 public:
101     explicit MediaTrace(const std::string &funcName, HiTraceOutputLevel level = HITRACE_LEVEL_INFO,
102         const std::string &customArgs = "");
103     static void TraceBegin(const std::string &funcName, int32_t taskId, HiTraceOutputLevel level = HITRACE_LEVEL_INFO,
104         const std::string &customCategory = "", const std::string &customArgs = "");
105     static void TraceEnd(const std::string &funcName, int32_t taskId, HiTraceOutputLevel level = HITRACE_LEVEL_INFO);
106     static void CounterTrace(const std::string &varName, int32_t val, HiTraceOutputLevel level = HITRACE_LEVEL_INFO);
107     ~MediaTrace();
108 private:
109     HiTraceOutputLevel level_ = HITRACE_LEVEL_INFO;
110 };
111 } // namespace Media
112 } // namespace OHOS
113 #endif // MEDIA_DFX_H