add instanceId and tid in anr report

Signed-off-by: huzeqi <huzeqi@huawei.com>
Change-Id: I972faa81312e26d9abe353554e42e93debff6306
This commit is contained in:
huzeqi
2022-03-26 15:02:23 +08:00
parent 1543f421ab
commit 44bfb3bc3d
4 changed files with 24 additions and 14 deletions
+5
View File
@@ -196,6 +196,11 @@ public:
virtual void RemoveTaskObserver() = 0;
virtual bool WillRunOnCurrentThread(TaskType type) const = 0;
virtual int32_t GetTid(TaskType type)
{
return 0;
}
protected:
TaskExecutor() = default;
@@ -124,9 +124,7 @@ void FlutterTaskExecutor::InitPlatformThread(bool useCurrentEventRunner)
platformRunner_ = fml::MessageLoop::GetCurrent().GetTaskRunner();
#endif
#ifdef ACE_DEBUG
FillTaskTypeTable(TaskType::PLATFORM);
#endif
}
void FlutterTaskExecutor::InitJsThread(bool newThread)
@@ -138,10 +136,8 @@ void FlutterTaskExecutor::InitJsThread(bool newThread)
jsRunner_ = uiRunner_;
}
#ifdef ACE_DEBUG
PostTaskToTaskRunner(
jsRunner_, [weak = AceType::WeakClaim(this)] { FillTaskTypeTable(weak, TaskType::JS); }, 0);
#endif
}
void FlutterTaskExecutor::InitOtherThreads(const flutter::TaskRunners& taskRunners)
@@ -155,14 +151,12 @@ void FlutterTaskExecutor::InitOtherThreads(const flutter::TaskRunners& taskRunne
PostTaskToTaskRunner(
gpuRunner_, [] { SetThreadPriority(GPU_THREAD_PRIORITY); }, 0);
#ifdef ACE_DEBUG
PostTaskToTaskRunner(
uiRunner_, [weak = AceType::WeakClaim(this)] { FillTaskTypeTable(weak, TaskType::UI); }, 0);
PostTaskToTaskRunner(
ioRunner_, [weak = AceType::WeakClaim(this)] { FillTaskTypeTable(weak, TaskType::IO); }, 0);
PostTaskToTaskRunner(
gpuRunner_, [weak = AceType::WeakClaim(this)] { FillTaskTypeTable(weak, TaskType::GPU); }, 0);
#endif
}
bool FlutterTaskExecutor::OnPostTask(Task&& task, TaskType type, uint32_t delayTime) const
@@ -229,6 +223,8 @@ void FlutterTaskExecutor::RemoveTaskObserver()
fml::MessageLoop::GetCurrent().RemoveTaskObserver(reinterpret_cast<intptr_t>(this));
}
thread_local TaskExecutor::TaskType FlutterTaskExecutor::localTaskType = TaskExecutor::TaskType::UNKNOWN;
#ifdef ACE_DEBUG
static const char* TaskTypeToString(TaskExecutor::TaskType type)
{
@@ -251,8 +247,6 @@ static const char* TaskTypeToString(TaskExecutor::TaskType type)
}
}
thread_local TaskExecutor::TaskType FlutterTaskExecutor::localTaskType = TaskExecutor::TaskType::UNKNOWN;
bool FlutterTaskExecutor::OnPreSyncTask(TaskType type) const
{
std::lock_guard<std::mutex> lock(tableMutex_);
@@ -295,6 +289,7 @@ void FlutterTaskExecutor::DumpDeadSyncTask(TaskType from, TaskType to) const
TaskTypeToString(from), itFrom->second.tid, itFrom->second.threadName.c_str(), TaskTypeToString(to),
itTo->second.tid, itTo->second.threadName.c_str());
}
#endif
void FlutterTaskExecutor::FillTaskTypeTable(TaskType type)
{
@@ -333,6 +328,5 @@ void FlutterTaskExecutor::FillTaskTypeTable(const WeakPtr<FlutterTaskExecutor>&
taskExecutor->FillTaskTypeTable(type);
}
}
#endif
} // namespace OHOS::Ace
@@ -16,10 +16,8 @@
#ifndef FOUNDATION_ACE_FRAMEWORKS_COMMON_FLUTTER_FLUTTER_TASK_EXECUTOR_H
#define FOUNDATION_ACE_FRAMEWORKS_COMMON_FLUTTER_FLUTTER_TASK_EXECUTOR_H
#ifdef ACE_DEBUG
#include <thread>
#include <unordered_map>
#endif
#include "flutter/common/task_runners.h"
#include "flutter/fml/thread.h"
@@ -46,6 +44,11 @@ public:
void RemoveTaskObserver() override;
bool WillRunOnCurrentThread(TaskType type) const final;
int32_t GetTid(TaskType type) final
{
return taskTypeTable_[type].tid;
}
private:
bool OnPostTask(Task&& task, TaskType type, uint32_t delayTime) const final;
Task WrapTaskWithTraceId(Task&& task, int32_t id) const final;
@@ -55,6 +58,8 @@ private:
void OnPostSyncTask() const final;
void DumpDeadSyncTask(TaskType from, TaskType to) const;
mutable std::unordered_map<std::thread::id, std::thread::id> syncTaskTable_;
#endif
void FillTaskTypeTable(TaskType type);
static void FillTaskTypeTable(const WeakPtr<FlutterTaskExecutor>& weak, TaskType type);
@@ -66,10 +71,8 @@ private:
};
mutable std::mutex tableMutex_;
mutable std::unordered_map<std::thread::id, std::thread::id> syncTaskTable_;
std::unordered_map<TaskType, ThreadInfo> taskTypeTable_;
static thread_local TaskType localTaskType;
#endif
std::unique_ptr<fml::Thread> jsThread_;
+9 -1
View File
@@ -156,7 +156,7 @@ private:
void DetonatedBomb();
mutable std::shared_mutex mutex_;
int32_t instanceId_;
int32_t instanceId_ = 0;
TaskExecutor::TaskType type_;
std::string threadName_;
int32_t loopTime_ = 0;
@@ -364,6 +364,14 @@ void ThreadWatcher::RawReport(RawEventType type) const
auto engine = EngineHelper::GetEngine(instanceId_);
message = engine ? engine->GetStacktraceMessage() : "";
}
int32_t tid = 0;
auto taskExecutor = taskExecutor_.Upgrade();
if (taskExecutor) {
tid = taskExecutor->GetTid(type_);
}
std::string threadInfo = "Blocked thread id = " + std::to_string(tid) + "\n";
threadInfo += "JSVM instance id = " + std::to_string(instanceId_) + "\n";
message = threadInfo + message;
EventReport::ANRRawReport(type, AceApplicationInfo::GetInstance().GetUid(),
AceApplicationInfo::GetInstance().GetPackageName(), AceApplicationInfo::GetInstance().GetProcessName(),
message);