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
495504void 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
0 commit comments