ability_runtime新增state profiler相关接口

Signed-off-by: eager1 <chenyige2@huawei.com>
Change-Id: Idd97890fd69cb5b3b516231ead38af0ee5e9a32a
This commit is contained in:
eager1
2024-04-23 14:50:12 +08:00
parent e7d9ac6011
commit 105e14d4a6
2 changed files with 43 additions and 1 deletions
@@ -51,6 +51,7 @@ using SendLayoutMessage = void (*)(const std::string&);
using StopServer = void (*)(const std::string&);
using StoreMessage = void (*)(int32_t, const std::string&);
using StoreInspectorInfo = void (*)(const std::string&, const std::string&);
using SetProfilerCallback = void (*)(const std::function<void(bool)> &setArkUIStateProfilerStatus);
using SetSwitchCallBack = void (*)(const std::function<void(bool)> &setStatus,
const std::function<void(int32_t)> &createLayoutInfo, int32_t instanceId);
using SetConnectCallback = void (*)(const std::function<void(bool)>);
@@ -221,9 +222,19 @@ bool ConnectServerManager::SendInstanceMessage(int32_t tid, int32_t instanceId,
TAG_LOGE(AAFwkTag::JSRUNTIME, "ConnectServerManager::SendInstanceMessage failed to find symbol 'StoreMessage'");
return false;
}
auto setProfilerCallback = reinterpret_cast<SetProfilerCallback>(
dlsym(handlerConnectServerSo_, "SetProfilerCallback"));
if (setProfilerCallback == nullptr) {
TAG_LOGI(AAFwkTag::JSRUNTIME,
"ConnectServerManager::SendInstanceMessage failed to find symbol 'setProfilerCallback'");
return false;
}
setSwitchCallBack([this](bool status) { setStatus_(status); },
[this](int32_t containerId) { createLayoutInfo_(containerId); }, instanceId);
setProfilerCallback([this](bool status) { setArkUIStateProfilerStatus_(status); });
std::string message = GetInstanceMapMessage("addInstance", instanceId, instanceName, tid);
storeMessage(instanceId, message);
@@ -261,6 +272,16 @@ bool ConnectServerManager::AddInstance(int32_t tid, int32_t instanceId, const st
setSwitchCallBack([this](bool status) { setStatus_(status); },
[this](int32_t containerId) { createLayoutInfo_(containerId); }, instanceId);
auto setProfilerCallback = reinterpret_cast<SetProfilerCallback>(
dlsym(handlerConnectServerSo_, "SetProfilerCallback"));
if (setProfilerCallback == nullptr) {
TAG_LOGE(AAFwkTag::JSRUNTIME,
"ConnectServerManager::AddInstance failed to find symbol 'setProfilerCallback'");
return false;
}
setProfilerCallback([this](bool status) { setArkUIStateProfilerStatus_(status); });
// Get the message including information of new instance, which will be send to IDE.
std::string message = GetInstanceMapMessage("addInstance", instanceId, instanceName, tid);
@@ -368,4 +389,22 @@ std::function<void(int32_t)> ConnectServerManager::GetLayoutInspectorCallback()
return createLayoutInfo_;
}
void ConnectServerManager::SetStateProfilerCallback(const std::function<void(bool)> &setArkUIStateProfilerStatus)
{
setArkUIStateProfilerStatus_ = setArkUIStateProfilerStatus;
}
void ConnectServerManager::SendArkUIStateProfilerMessage(const std::string &message)
{
TAG_LOGI(AAFwkTag::JSRUNTIME, "ConnectServerManager SendArkUIStateProfilerMessage Start");
auto sendProfilerMessage = reinterpret_cast<SendMessage>(dlsym(handlerConnectServerSo_, "SendProfilerMessage"));
if (sendProfilerMessage == nullptr) {
TAG_LOGE(AAFwkTag::JSRUNTIME,
"ConnectServerManager::SendArkUIStateProfilerMessage failed to find symbol 'sendProfilerMessage'");
return;
}
sendProfilerMessage(message);
}
} // namespace OHOS::AbilityRuntime
@@ -39,8 +39,10 @@ public:
bool AddInstance(int32_t tid, int32_t instanceId, const std::string& instanceName = "PandaDebugger");
void RemoveInstance(int32_t instanceId);
void SendInspector(const std::string& jsonTreeStr, const std::string& jsonSnapshotStr);
void SendArkUIStateProfilerMessage(const std::string &message);
void SetLayoutInspectorCallback(
const std::function<void(int32_t)> &createLayoutInfo, const std::function<void(bool)> &setStatus);
void SetStateProfilerCallback(const std::function<void(bool)> &setArkUIStateProfilerStatus);
std::function<void(int32_t)> GetLayoutInspectorCallback();
bool StoreInstanceMessage(
int32_t tid, int32_t instanceId, const std::string& instanceName = "PandaDebugger");
@@ -64,6 +66,7 @@ private:
std::unordered_map<int32_t, std::pair<std::string, int32_t>> instanceMap_;
std::function<void(int32_t)> createLayoutInfo_;
std::function<void(int32_t)> setStatus_;
std::function<void(int32_t)> setArkUIStateProfilerStatus_;
ConnectServerManager(const ConnectServerManager&) = delete;
ConnectServerManager(ConnectServerManager&&) = delete;
ConnectServerManager& operator=(const ConnectServerManager&) = delete;