• 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 RS_UNMARSHAL_TASK_MANAGER_H
17 #define RS_UNMARSHAL_TASK_MANAGER_H
18 #include <memory>
19 #include <optional>
20 #include <string>
21 
22 namespace OHOS::Rosen {
23 enum class UnmarshalTaskState : uint8_t {
24     UNINVOKED,
25     RUNNING,
26     COMPLETED,
27 };
28 
29 struct UnmarshalTaskInfo {
30     UnmarshalTaskState state = UnmarshalTaskState::UNINVOKED;
31     std::string name;
32     uint64_t invokeTimestamp = 0;
33     uint64_t completeTimestamp = 0;
34     uint64_t uid = 0;
35     std::string Dump() const;
36     uint64_t GetTaskDuration() const;
37 };
38 
39 class RSUnmarshalRunningTaskManager;
40 class RSUnmarshalCompletedTaskManager;
41 
42 class RSUnmarshalTaskManager {
43 public:
44     static RSUnmarshalTaskManager& Instance();
45 
46     uint64_t BeginTask(std::string name);
47     void EndTask(uint64_t uid);
48     void Clear();
49 
50     std::optional<UnmarshalTaskInfo> GetLongestTask() const;
51     std::optional<UnmarshalTaskInfo> GetRunningLongestTask() const;
52     std::optional<UnmarshalTaskInfo> GetCompletedLongestTask() const;
53 
54     std::string Dump() const;
55 
56 private:
57     RSUnmarshalTaskManager();
58     ~RSUnmarshalTaskManager() noexcept = default;
59 
60     RSUnmarshalTaskManager(const RSUnmarshalTaskManager&) = delete;
61     RSUnmarshalTaskManager(RSUnmarshalTaskManager&&) = delete;
62     RSUnmarshalTaskManager& operator=(const RSUnmarshalTaskManager&) = delete;
63     RSUnmarshalTaskManager& operator=(RSUnmarshalTaskManager&&) = delete;
64 
65     uint64_t GetUid() const;
66 
67     std::unique_ptr<RSUnmarshalRunningTaskManager> runningTaskMgr_;
68     std::unique_ptr<RSUnmarshalCompletedTaskManager> completedTaskMgr_;
69 };
70 
71 namespace UnmarshalTaskUtil {
72 std::string UnmarshalTaskStateToString(UnmarshalTaskState state);
73 uint64_t GetTimestamp();
74 } // namespace UnmarshalTaskUtil
75 } // namespace OHOS::Rosen
76 #endif