-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebugger.cpp
126 lines (116 loc) · 3.53 KB
/
debugger.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "debugger.h"
#include "scheduler.h"
namespace co
{
CoDebugger & CoDebugger::getInstance()
{
static CoDebugger obj;
return obj;
}
std::string CoDebugger::GetAllInfo()
{
std::string s;
s += "==============================================\n";
s += "TaskCount: " + std::to_string(TaskCount());
s += "\nCurrentTaskID: " + std::to_string(GetCurrentTaskID());
s += "\nCurrentTaskInfo: " + std::string(GetCurrentTaskDebugInfo());
s += "\nCurrentTaskYieldCount: " + std::to_string(GetCurrentTaskYieldCount());
s += "\nCurrentThreadID: " + std::to_string(GetCurrentThreadID());
s += "\nCurrentProcessID: " + std::to_string(GetCurrentProcessID());
s += "\nTimerCount: " + std::to_string(GetTimerCount());
s += "\nSleepTimerCount: " + std::to_string(GetSleepTimerCount());
s += "\n--------------------------------------------";
s += "\nTask Map:";
auto vm = GetTasksStateInfo();
for (std::size_t state = 0; state < vm.size(); ++state)
{
s += "\n " + GetTaskStateName((TaskState)state) + " ->";
for (auto &kv : vm[state])
{
s += "\n " + std::to_string(kv.second) + " " + kv.first.to_string();
}
}
s += "\n--------------------------------------------";
#if __linux__
s += "\n" + GetFdInfo();
s += "\nEpollWait:" + std::to_string(GetEpollWaitCount());
#endif
s += "\n--------------------------------------------";
s += "\nObject Counter:";
auto objs = GetDebuggerObjectCounts();
for (auto &kv : objs)
s += "\nCount(" + kv.first + "): " + std::to_string((uint64_t)kv.second);
s += "\n--------------------------------------------";
s += "\n==============================================";
return s;
}
uint32_t CoDebugger::TaskCount()
{
return g_Scheduler.TaskCount();
}
uint64_t CoDebugger::GetCurrentTaskID()
{
return g_Scheduler.GetCurrentTaskID();
}
uint64_t CoDebugger::GetCurrentTaskYieldCount()
{
return g_Scheduler.GetCurrentTaskYieldCount();
}
void CoDebugger::SetCurrentTaskDebugInfo(const std::string & info)
{
g_Scheduler.SetCurrentTaskDebugInfo(info);
}
const char * CoDebugger::GetCurrentTaskDebugInfo()
{
return g_Scheduler.GetCurrentTaskDebugInfo();
}
uint32_t CoDebugger::GetCurrentThreadID()
{
return g_Scheduler.GetCurrentThreadID();
}
uint32_t CoDebugger::GetCurrentProcessID()
{
return g_Scheduler.GetCurrentProcessID();
}
uint64_t CoDebugger::GetTimerCount()
{
return g_Scheduler.timer_mgr_.Size();
}
uint64_t CoDebugger::GetSleepTimerCount()
{
return g_Scheduler.sleep_wait_.timer_mgr_.Size();
}
std::map<SourceLocation, uint32_t> CoDebugger::GetTasksInfo()
{
return Task::GetStatInfo();
}
std::vector<std::map<SourceLocation, uint32_t>> CoDebugger::GetTasksStateInfo()
{
return Task::GetStateInfo();
}
ThreadLocalInfo& CoDebugger::GetLocalInfo()
{
return g_Scheduler.GetLocalInfo();
}
#if __linux__
/// ------------ Linux -------------
// 鑾峰彇Fd缁熻淇℃伅
std::string CoDebugger::GetFdInfo()
{
return FdManager::getInstance().GetDebugInfo();
}
// 鑾峰彇绛夊緟epoll鐨勫崗绋嬫暟閲�
uint32_t CoDebugger::GetEpollWaitCount()
{
return g_Scheduler.io_wait_.wait_io_sentries_.size();
}
#endif
CoDebugger::object_counts_result_t CoDebugger::GetDebuggerObjectCounts()
{
object_counts_result_t result;
std::unique_lock<LFLock> lock(CoDebugger::getInstance().object_counts_spinlock_);
for (auto & elem : object_counts_)
result.push_back(std::make_pair(elem.first, (uint64_t)elem.second));
return result;
}
} //namespace co