MCPcopy Create free account
hub / github.com/acl-dev/acl / buildStatus

Method buildStatus

app/master/tools/master_dispatch/server/server/ServerManager.cpp:48–145  ·  view source on GitHub ↗

该函数由主线程中的定时器调用

Source from the content-addressed store, hash-verified

46
47// 该函数由主线程中的定时器调用
48void ServerManager::buildStatus()
49{
50 // 因为在子线程中也会读取 json_ 对象,所以对单例成员变量
51 // json_ 进行加锁保护,为了防止主线程被长期阻塞在锁上,所以
52 // 采用了尝试加锁方式
53 if (lock_.try_lock() == false)
54 return;
55
56 json_.reset();
57 xml_.reset();
58
59 acl::json_node& json_servers = json_.create_array();
60 json_.get_root().add_child("server", json_servers);
61
62 acl::xml_node& xml_servers = xml_.create_node("server");
63 xml_.get_root().add_child(xml_servers);
64
65 long long total_conns = 0, total_used = 0, total_qlen = 0;
66 long long total_max_threads = 0, total_curr_threads = 0;
67 long long total_busy_threads = 0;
68 acl::string load_s;
69 (void) sysload::get_load(&load_s); // 获得当前系统的负载
70
71 std::vector<ServerConnection*>::const_iterator cit = conns_.begin();
72 for (; cit != conns_.end(); ++cit)
73 {
74 total_conns += (*cit)->get_conns();
75 total_used += (*cit)->get_used();
76 total_qlen += (*cit)->get_qlen();
77 total_max_threads += (*cit)->get_max_threads();
78 total_curr_threads += (*cit)->get_curr_threads();
79 total_busy_threads += (*cit)->get_busy_threads();
80
81 acl::json_node& json_server = json_.create_node();
82 json_server.add_number("conns", (*cit)->get_conns())
83 .add_number("used", (*cit)->get_used())
84 .add_number("pid", (*cit)->get_pid())
85 .add_number("max_threads", (*cit)->get_max_threads())
86 .add_number("curr_threads", (*cit)->get_curr_threads())
87 .add_number("busy_threads", (*cit)->get_busy_threads())
88 .add_number("qlen", (*cit)->get_qlen())
89 .add_text("type", (*cit)->get_type());
90 json_servers.add_child(json_server);
91
92 xml_servers.add_child("proc", true)
93 .add_child("conns", (long long int)
94 (*cit)->get_conns())
95 .add_child("used", (long long int) (*cit)->get_used())
96 .add_child("pid", (long long int) (*cit)->get_pid())
97 .add_child("max_threads", (long long int)
98 (*cit)->get_max_threads())
99 .add_child("curr_threads", (long long int)
100 (*cit)->get_curr_threads())
101 .add_child("busy_threads", (long long int)
102 (*cit)->get_busy_threads())
103 .add_child("qlen", (long long int) (*cit)->get_qlen())
104 .add_child("type", (*cit)->get_type().c_str());
105 }

Callers 1

timer_callbackMethod · 0.80

Calls 15

beginMethod · 0.80
get_connsMethod · 0.80
get_usedMethod · 0.80
get_qlenMethod · 0.80
get_max_threadsMethod · 0.80
get_curr_threadsMethod · 0.80
get_busy_threadsMethod · 0.80
get_pidMethod · 0.80
try_lockMethod · 0.45
resetMethod · 0.45
create_nodeMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected