• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_BASE_LOG_DUMP_RECORDER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_LOG_DUMP_RECORDER_H
18 
19 #include "base/json/json_util.h"
20 #include "base/thread/task_executor.h"
21 #include "base/utils/singleton.h"
22 #include "base/utils/utils.h"
23 
24 namespace OHOS::Ace {
25 class DumpRecorder : public Singleton<DumpRecorder> {
26     DECLARE_SINGLETON(DumpRecorder);
27 
28 public:
29     void Start(std::function<bool()>&& func);
30 
31     void Stop();
32 
33     void StopInner();
34 
35     void Init();
36 
37     void Clear();
38 
GetFrameDumpFunc()39     std::function<bool()> GetFrameDumpFunc() const
40     {
41         return frameDumpFunc_;
42     }
43 
IsRecording()44     bool IsRecording() const
45     {
46         return frameDumpFunc_ != nullptr;
47     }
48 
49     void Record(int64_t timestamp, std::unique_ptr<JsonValue>&& json);
50 
51     void Diff(int64_t timestamp);
52 
53     bool Compare(std::unique_ptr<JsonValue>& prevNode, std::unique_ptr<JsonValue>& curNode, std::string& diff);
54 
55     bool CompareDumpParam(std::unique_ptr<JsonValue>& curParams, std::unique_ptr<JsonValue>& prevParams);
56 
57     void Output(const std::string& content);
58 
59 private:
60     uint32_t fileSize_ = 0;
61     std::function<bool()> frameDumpFunc_;
62     std::unique_ptr<JsonValue> recordTree_;
63     std::map<int64_t, std::unique_ptr<JsonValue>> records_;
64 };
65 } // namespace OHOS::Ace
66 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_LOG_DUMP_RECORDER_H