Skip to content

Commit d5c9895

Browse files
committed
feat:给常用模块都加了RECORD_SCOPE()
1 parent b9eeec5 commit d5c9895

File tree

13 files changed

+56
-0
lines changed

13 files changed

+56
-0
lines changed

modules/alarm/alarm.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <tbox/base/log.h>
2525
#include <tbox/base/assert.h>
26+
#include <tbox/base/wrapped_recorder.h>
2627
#include <tbox/event/loop.h>
2728
#include <tbox/event/timer_event.h>
2829

@@ -187,6 +188,7 @@ void Alarm::onTimeExpired() {
187188
state_ = State::kInited;
188189
activeTimer();
189190

191+
RECORD_SCOPE();
190192
++cb_level_;
191193
if (cb_)
192194
cb_();

modules/eventx/loop_wdog.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <tbox/base/log.h>
3030
#include <tbox/base/assert.h>
3131
#include <tbox/base/defines.h>
32+
#include <tbox/base/wrapped_recorder.h>
3233

3334
namespace tbox {
3435
namespace eventx {
@@ -92,6 +93,7 @@ void CheckLoopTag() {
9293
if (loop_info_sptr->state == State::kTobeCheck) {
9394
loop_info_sptr->state = State::kTimeout;
9495
_loop_die_cb(loop_info_sptr->name);
96+
RECORD_EVENT();
9597
}
9698
}
9799
}

modules/eventx/timer_fd.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <tbox/base/log.h>
2727
#include <tbox/base/assert.h>
2828
#include <tbox/base/defines.h>
29+
#include <tbox/base/wrapped_recorder.h>
2930
#include <tbox/event/loop.h>
3031
#include <tbox/event/fd_event.h>
3132

@@ -183,6 +184,7 @@ void TimerFd::onEvent(short events)
183184
disable();
184185

185186
if (d_->cb) {
187+
RECORD_SCOPE();
186188
++d_->cb_level;
187189
d_->cb();
188190
--d_->cb_level;

modules/http/server/server_imp.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <tbox/base/log.h>
2323
#include <tbox/base/assert.h>
24+
#include <tbox/base/wrapped_recorder.h>
2425
#include <tbox/util/buffer.h>
2526

2627
#include "middleware.h"
@@ -104,13 +105,15 @@ void Server::Impl::use(Middleware *wp_middleware)
104105

105106
void Server::Impl::onTcpConnected(const TcpServer::ConnToken &ct)
106107
{
108+
RECORD_SCOPE();
107109
auto conn = new Connection;
108110
tcp_server_.setContext(ct, conn);
109111
conns_.insert(conn);
110112
}
111113

112114
void Server::Impl::onTcpDisconnected(const TcpServer::ConnToken &ct)
113115
{
116+
RECORD_SCOPE();
114117
Connection *conn = static_cast<Connection*>(tcp_server_.getContext(ct));
115118
TBOX_ASSERT(conn != nullptr);
116119

@@ -142,6 +145,7 @@ bool IsLastRequest(const Request *req)
142145

143146
void Server::Impl::onTcpReceived(const TcpServer::ConnToken &ct, Buffer &buff)
144147
{
148+
RECORD_SCOPE();
145149
Connection *conn = static_cast<Connection*>(tcp_server_.getContext(ct));
146150
TBOX_ASSERT(conn != nullptr);
147151

@@ -188,6 +192,7 @@ void Server::Impl::onTcpReceived(const TcpServer::ConnToken &ct, Buffer &buff)
188192

189193
void Server::Impl::onTcpSendCompleted(const TcpServer::ConnToken &ct)
190194
{
195+
RECORD_SCOPE();
191196
if (!tcp_server_.isClientValid(ct))
192197
return;
193198

@@ -209,6 +214,7 @@ void Server::Impl::onTcpSendCompleted(const TcpServer::ConnToken &ct)
209214
*/
210215
void Server::Impl::commitRespond(const TcpServer::ConnToken &ct, int index, Respond *res)
211216
{
217+
RECORD_SCOPE();
212218
if (!tcp_server_.isClientValid(ct)) {
213219
delete res;
214220
return;
@@ -264,6 +270,7 @@ void Server::Impl::commitRespond(const TcpServer::ConnToken &ct, int index, Resp
264270

265271
void Server::Impl::handle(ContextSptr sp_ctx, size_t cb_index)
266272
{
273+
RECORD_SCOPE();
267274
if (cb_index >= req_cb_.size())
268275
return;
269276

modules/jsonrpc/rpc.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <tbox/base/log.h>
2323
#include <tbox/base/json.hpp>
24+
#include <tbox/base/wrapped_recorder.h>
2425
#include "proto.h"
2526
#include "inner_types.h"
2627

@@ -69,6 +70,7 @@ void Rpc::cleanup()
6970

7071
void Rpc::request(const std::string &method, const Json &js_params, RequestCallback &&cb)
7172
{
73+
RECORD_SCOPE();
7274
int id = 0;
7375
if (cb) {
7476
id = ++id_alloc_;
@@ -100,6 +102,7 @@ void Rpc::addService(const std::string &method, ServiceCallback &&cb)
100102

101103
void Rpc::respond(int id, int errcode, const Json &js_result)
102104
{
105+
RECORD_SCOPE();
103106
if (id == 0) {
104107
LogWarn("send id == 0 respond");
105108
return;
@@ -116,6 +119,7 @@ void Rpc::respond(int id, int errcode, const Json &js_result)
116119

117120
void Rpc::respond(int id, const Json &js_result)
118121
{
122+
RECORD_SCOPE();
119123
if (id == 0) {
120124
LogWarn("send id == 0 respond");
121125
return;
@@ -127,6 +131,7 @@ void Rpc::respond(int id, const Json &js_result)
127131

128132
void Rpc::respond(int id, int errcode)
129133
{
134+
RECORD_SCOPE();
130135
if (id == 0) {
131136
LogWarn("send id == 0 respond");
132137
return;
@@ -138,6 +143,7 @@ void Rpc::respond(int id, int errcode)
138143

139144
void Rpc::onRecvRequest(int id, const std::string &method, const Json &js_params)
140145
{
146+
RECORD_SCOPE();
141147
auto iter = method_services_.find(method);
142148
if (iter != method_services_.end() && iter->second) {
143149
int errcode = 0;
@@ -159,6 +165,7 @@ void Rpc::onRecvRequest(int id, const std::string &method, const Json &js_params
159165

160166
void Rpc::onRecvRespond(int id, int errcode, const Json &js_result)
161167
{
168+
RECORD_SCOPE();
162169
auto iter = request_callback_.find(id);
163170
if (iter != request_callback_.end()) {
164171
if (iter->second)

modules/mqtt/client.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <tbox/base/log.h>
2525
#include <tbox/base/assert.h>
2626
#include <tbox/base/lifetime_tag.hpp>
27+
#include <tbox/base/wrapped_recorder.h>
2728
#include <tbox/event/timer_event.h>
2829
#include <tbox/event/fd_event.h>
2930

@@ -209,6 +210,7 @@ bool Client::start()
209210
return false;
210211
}
211212

213+
RECORD_SCOPE();
212214
//! 基础设置
213215
const char *client_id = nullptr;
214216
if (!d_->config.base.client_id.empty())
@@ -289,6 +291,7 @@ bool Client::start()
289291
//! 由于 mosquitto_connect() 是阻塞函数,为了避免阻塞其它事件,特交给子线程去做
290292
d_->sp_thread = new thread(
291293
[this, is_alive] {
294+
RECORD_SCOPE();
292295
int ret = mosquitto_connect_async(d_->sp_mosq,
293296
d_->config.base.broker.domain.c_str(),
294297
d_->config.base.broker.port,
@@ -312,6 +315,7 @@ void Client::stop()
312315
if (d_->state <= State::kInited)
313316
return;
314317

318+
RECORD_SCOPE();
315319
if (d_->state == State::kTcpConnected ||
316320
d_->state == State::kMqttConnected) {
317321
//! 如果已成功连接,则立即断开
@@ -337,6 +341,7 @@ int Client::subscribe(const std::string &topic, int *p_mid, int qos)
337341
return false;
338342
}
339343

344+
RECORD_SCOPE();
340345
int mid = 0;
341346
int ret = mosquitto_subscribe(d_->sp_mosq, &mid, topic.c_str(), qos);
342347
if (p_mid != nullptr)
@@ -353,6 +358,7 @@ int Client::unsubscribe(const std::string &topic, int *p_mid)
353358
return false;
354359
}
355360

361+
RECORD_SCOPE();
356362
int mid = 0;
357363
int ret = mosquitto_unsubscribe(d_->sp_mosq, &mid, topic.c_str());
358364
if (p_mid != nullptr)
@@ -370,6 +376,7 @@ int Client::publish(const std::string &topic, const void *payload_ptr, size_t pa
370376
return false;
371377
}
372378

379+
RECORD_SCOPE();
373380
int mid = 0;
374381
int ret = mosquitto_publish(d_->sp_mosq, &mid, topic.c_str(),
375382
payload_size, payload_ptr,
@@ -405,6 +412,7 @@ void Client::onTimerTick()
405412
auto is_alive = d_->alive_tag.get(); //! 原理见Q1
406413
d_->sp_thread = new thread(
407414
[this, is_alive] {
415+
RECORD_SCOPE();
408416
int ret = mosquitto_reconnect_async(d_->sp_mosq);
409417
d_->wp_loop->runInLoop(
410418
[this, is_alive, ret] {
@@ -483,6 +491,7 @@ void Client::onConnected(int rc)
483491

484492
LogInfo("connected");
485493

494+
RECORD_SCOPE();
486495
if (d_->state != State::kMqttConnected) {
487496
d_->state = State::kMqttConnected;
488497
++d_->cb_level;
@@ -494,6 +503,7 @@ void Client::onConnected(int rc)
494503

495504
void Client::onDisconnected(int rc)
496505
{
506+
RECORD_SCOPE();
497507
disableSocketRead();
498508
disableSocketWrite();
499509

@@ -515,6 +525,7 @@ void Client::onPublish(int mid)
515525
{
516526
LogInfo("mid:%d", mid);
517527

528+
RECORD_SCOPE();
518529
++d_->cb_level;
519530
if (d_->callbacks.message_pub)
520531
d_->callbacks.message_pub(mid);
@@ -525,6 +536,7 @@ void Client::onSubscribe(int mid, int qos, const int *granted_qos)
525536
{
526537
LogInfo("mid:%d, qos:%d", mid, qos);
527538

539+
RECORD_SCOPE();
528540
++d_->cb_level;
529541
if (d_->callbacks.subscribed)
530542
d_->callbacks.subscribed(mid, qos, granted_qos);
@@ -535,6 +547,7 @@ void Client::onUnsubscribe(int mid)
535547
{
536548
LogInfo("mid:%d", mid);
537549

550+
RECORD_SCOPE();
538551
++d_->cb_level;
539552
if (d_->callbacks.unsubscribed)
540553
d_->callbacks.unsubscribed(mid);
@@ -548,6 +561,7 @@ void Client::onMessage(const struct mosquitto_message *msg)
548561

549562
LogInfo("mid:%d, topic:%s", msg->mid, msg->topic);
550563

564+
RECORD_SCOPE();
551565
++d_->cb_level;
552566
if (d_->callbacks.message_recv)
553567
d_->callbacks.message_recv(msg->mid,
@@ -582,6 +596,7 @@ void Client::onTcpConnectDone(int ret, bool first_connect)
582596
if (d_->sp_thread == nullptr)
583597
return;
584598

599+
RECORD_SCOPE();
585600
d_->sp_thread->join();
586601
CHECK_DELETE_RESET_OBJ(d_->sp_thread);
587602

modules/network/buffered_fd.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <cstring>
2323
#include <tbox/base/log.h>
2424
#include <tbox/base/assert.h>
25+
#include <tbox/base/wrapped_recorder.h>
2526
#include <tbox/event/loop.h>
2627
#include <tbox/event/fd_event.h>
2728

@@ -180,6 +181,7 @@ void BufferedFd::shrinkSendBuffer()
180181

181182
void BufferedFd::onReadCallback(short)
182183
{
184+
RECORD_SCOPE();
183185
struct iovec rbuf[2];
184186
char extbuf[1024]; //! 扩展存储空间
185187

@@ -246,6 +248,7 @@ void BufferedFd::onReadCallback(short)
246248

247249
void BufferedFd::onWriteCallback(short)
248250
{
251+
RECORD_SCOPE();
249252
//! 如果发送缓冲中已无数据要发送了,那就关闭可写事件
250253
if (send_buff_.readableSize() == 0) {
251254
sp_write_event_->disable();

modules/network/dns_request.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <memory>
2626

2727
#include <tbox/base/assert.h>
28+
#include <tbox/base/wrapped_recorder.h>
2829
#include <tbox/util/serializer.h>
2930
#include <tbox/util/string.h>
3031
#include <tbox/util/fs.h>
@@ -210,6 +211,7 @@ void DnsRequest::onUdpRecv(const void *data_ptr, size_t data_size, const SockAdd
210211
if (requests_.empty())
211212
return;
212213

214+
RECORD_SCOPE();
213215
util::Deserializer parser(data_ptr, data_size);
214216

215217
uint16_t req_id, flags;

modules/network/tcp_acceptor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <tbox/base/log.h>
2828
#include <tbox/base/assert.h>
29+
#include <tbox/base/wrapped_recorder.h>
2930

3031
#include "tcp_connection.h"
3132

@@ -147,6 +148,7 @@ void TcpAcceptor::onSocketRead(short events)
147148

148149
void TcpAcceptor::onClientConnected()
149150
{
151+
RECORD_SCOPE();
150152
struct sockaddr addr;
151153
socklen_t addr_len = sizeof(addr);
152154
SocketFd peer_sock = sock_fd_.accept(&addr, &addr_len);

modules/network/tcp_client.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <tbox/base/log.h>
2323
#include <tbox/base/assert.h>
2424
#include <tbox/base/defines.h>
25+
#include <tbox/base/wrapped_recorder.h>
2526

2627
#include "tcp_connector.h"
2728
#include "tcp_connection.h"
@@ -204,6 +205,7 @@ void TcpClient::unbind()
204205

205206
void TcpClient::onTcpConnected(TcpConnection *new_conn)
206207
{
208+
RECORD_SCOPE();
207209
new_conn->setDisconnectedCallback(std::bind(&TcpClient::onTcpDisconnected, this));
208210
new_conn->setReceiveCallback(d_->received_cb, d_->received_threshold);
209211
new_conn->setSendCompleteCallback(d_->send_complete_cb);
@@ -217,6 +219,7 @@ void TcpClient::onTcpConnected(TcpConnection *new_conn)
217219
d_->state = State::kConnected;
218220

219221
if (d_->connected_cb) {
222+
RECORD_SCOPE();
220223
++d_->cb_level;
221224
d_->connected_cb();
222225
--d_->cb_level;
@@ -225,6 +228,7 @@ void TcpClient::onTcpConnected(TcpConnection *new_conn)
225228

226229
void TcpClient::onTcpDisconnected()
227230
{
231+
RECORD_SCOPE();
228232
TcpConnection *tobe_delete = nullptr;
229233
std::swap(tobe_delete, d_->sp_connection);
230234

@@ -240,6 +244,7 @@ void TcpClient::onTcpDisconnected()
240244
start();
241245

242246
if (d_->disconnected_cb) {
247+
RECORD_SCOPE();
243248
++d_->cb_level;
244249
d_->disconnected_cb();
245250
--d_->cb_level;

0 commit comments

Comments
 (0)