@ -18,7 +18,8 @@
# include "src/core/lib/transport/connectivity_state.h"
# include <grpc/support/log.h>
# include "absl/log/log.h"
# include <grpc/support/port_platform.h>
# include "src/core/lib/gprpp/debug_location.h"
@ -72,9 +73,10 @@ class AsyncConnectivityStateWatcherInterface::Notifier {
static void SendNotification ( void * arg , grpc_error_handle /*ignored*/ ) {
Notifier * self = static_cast < Notifier * > ( arg ) ;
if ( GRPC_TRACE_FLAG_ENABLED ( connectivity_state ) ) {
gpr_log ( GPR_INFO , " watcher %p: delivering async notification for %s (%s) " ,
self - > watcher_ . get ( ) , ConnectivityStateName ( self - > state_ ) ,
self - > status_ . ToString ( ) . c_str ( ) ) ;
LOG ( INFO ) < < " watcher " < < self - > watcher_ . get ( )
< < " : delivering async notification for "
< < ConnectivityStateName ( self - > state_ ) < < " ( "
< < self - > status_ . ToString ( ) < < " ) " ;
}
self - > watcher_ - > OnConnectivityStateChange ( self - > state_ , self - > status_ ) ;
delete self ;
@ -103,10 +105,10 @@ ConnectivityStateTracker::~ConnectivityStateTracker() {
if ( current_state = = GRPC_CHANNEL_SHUTDOWN ) return ;
for ( const auto & p : watchers_ ) {
if ( GRPC_TRACE_FLAG_ENABLED ( connectivity_state ) ) {
gpr_log ( GPR_INFO ,
" ConnectivityStateTracker %s[%p]: notifying watcher %p: %s -> %s " ,
name_ , this , p . first , ConnectivityStateName ( current_state ) ,
ConnectivityStateName ( GRPC_CHANNEL_SHUTDOWN ) ) ;
LOG ( INFO ) < < " ConnectivityStateTracker " < < name_ < < " [ " < < this
< < " ]: notifying watcher " < < p . first < < " : "
< < ConnectivityStateName ( current_state ) < < " -> "
< < ConnectivityStateName ( GRPC_CHANNEL_SHUTDOWN ) ;
}
p . second - > Notify ( GRPC_CHANNEL_SHUTDOWN , absl : : Status ( ) ) ;
}
@ -116,17 +118,17 @@ void ConnectivityStateTracker::AddWatcher(
grpc_connectivity_state initial_state ,
OrphanablePtr < ConnectivityStateWatcherInterface > watcher ) {
if ( GRPC_TRACE_FLAG_ENABLED ( connectivity_state ) ) {
gpr_log ( GPR_INFO , " ConnectivityStateTracker %s[%p]: add watcher %p " , name_ ,
this , watcher . get ( ) ) ;
LOG ( INFO ) < < " ConnectivityStateTracker " < < name_ < < " [ " < < this
< < " ]: add watcher " < < watcher . get ( ) ;
}
grpc_connectivity_state current_state =
state_ . load ( std : : memory_order_relaxed ) ;
if ( initial_state ! = current_state ) {
if ( GRPC_TRACE_FLAG_ENABLED ( connectivity_state ) ) {
gpr_log ( GPR_INFO ,
" ConnectivityStateTracker %s[%p]: notifying watcher %p: %s -> %s " ,
name_ , this , watcher . get ( ) , ConnectivityStateName ( initial_state ) ,
ConnectivityStateName ( current_state ) ) ;
LOG ( INFO ) < < " ConnectivityStateTracker " < < name_ < < " [ " < < this
< < " ]: notifying watcher " < < watcher . get ( ) < < " : "
< < ConnectivityStateName ( initial_state ) < < " -> "
< < ConnectivityStateName ( current_state ) ;
}
watcher - > Notify ( current_state , status_ ) ;
}
@ -140,8 +142,8 @@ void ConnectivityStateTracker::AddWatcher(
void ConnectivityStateTracker : : RemoveWatcher (
ConnectivityStateWatcherInterface * watcher ) {
if ( GRPC_TRACE_FLAG_ENABLED ( connectivity_state ) ) {
gpr_log ( GPR_INFO , " ConnectivityStateTracker %s[%p]: remove watcher %p " ,
name_ , this , watcher ) ;
LOG ( INFO ) < < " ConnectivityStateTracker " < < name_ < < " [ " < < this
< < " ]: remove watcher " < < watcher ;
}
watchers_ . erase ( watcher ) ;
}
@ -153,18 +155,19 @@ void ConnectivityStateTracker::SetState(grpc_connectivity_state state,
state_ . load ( std : : memory_order_relaxed ) ;
if ( state = = current_state ) return ;
if ( GRPC_TRACE_FLAG_ENABLED ( connectivity_state ) ) {
gpr_log ( GPR_INFO , " ConnectivityStateTracker %s[%p]: %s -> %s (%s, %s) " ,
name_ , this , ConnectivityStateName ( current_state ) ,
ConnectivityStateName ( state ) , reason , status . ToString ( ) . c_str ( ) ) ;
LOG ( INFO ) < < " ConnectivityStateTracker " < < name_ < < " [ " < < this
< < " ]: " < < ConnectivityStateName ( current_state ) < < " -> "
< < ConnectivityStateName ( state ) < < " ( " < < reason < < " , "
< < status . ToString ( ) < < " ) " ;
}
state_ . store ( state , std : : memory_order_relaxed ) ;
status_ = status ;
for ( const auto & p : watchers_ ) {
if ( GRPC_TRACE_FLAG_ENABLED ( connectivity_state ) ) {
gpr_log ( GPR_INFO ,
" ConnectivityStateTracker %s[%p]: notifying watcher %p: %s -> %s " ,
name_ , this , p . first , ConnectivityStateName ( current_state ) ,
ConnectivityStateName ( state ) ) ;
LOG ( INFO ) < < " ConnectivityStateTracker " < < name_ < < " [ " < < this
< < " ]: notifying watcher " < < p . first < < " : "
< < ConnectivityStateName ( current_state ) < < " -> "
< < ConnectivityStateName ( state ) ;
}
p . second - > Notify ( state , status ) ;
}
@ -176,8 +179,8 @@ void ConnectivityStateTracker::SetState(grpc_connectivity_state state,
grpc_connectivity_state ConnectivityStateTracker : : state ( ) const {
grpc_connectivity_state state = state_ . load ( std : : memory_order_relaxed ) ;
if ( GRPC_TRACE_FLAG_ENABLED ( connectivity_state ) ) {
gpr_log ( GPR_INFO , " ConnectivityStateTracker %s[%p]: get current state: %s " ,
name_ , this , ConnectivityStateName ( state ) ) ;
LOG ( INFO ) < < " ConnectivityStateTracker " < < name_ < < " [ " < < this
< < " ]: get current state: " < < ConnectivityStateName ( state ) ;
}
return state ;
}