pull/36964/head
Craig Tiller 9 months ago
parent 8c2b6a47a4
commit 6f813eb5ba
  1. 2
      src/core/lib/promise/activity.h
  2. 2
      src/core/lib/promise/party.cc
  3. 38
      src/core/util/latent_see.h

@ -547,7 +547,7 @@ class PromiseActivity final
} }
void WakeupAsync(WakeupMask) final { void WakeupAsync(WakeupMask) final {
GRPC_LATENT_SEE_SCOPE("PromiseActivity::WakeupAsync"); GRPC_LATENT_SEE_INNER_SCOPE("PromiseActivity::WakeupAsync");
wakeup_flow_.emplace(GRPC_LATENT_SEE_METADATA("Activity::Wakeup")); wakeup_flow_.emplace(GRPC_LATENT_SEE_METADATA("Activity::Wakeup"));
if (!wakeup_scheduled_.exchange(true, std::memory_order_acq_rel)) { if (!wakeup_scheduled_.exchange(true, std::memory_order_acq_rel)) {
// Can't safely run, so ask to run later. // Can't safely run, so ask to run later.

@ -267,7 +267,7 @@ bool Party::RunParty() {
} }
bool Party::RunOneParticipant(int i) { bool Party::RunOneParticipant(int i) {
GRPC_LATENT_SEE_SCOPE("Party::RunOneParticipant"); GRPC_LATENT_SEE_INNER_SCOPE("Party::RunOneParticipant");
// If the participant is null, skip. // If the participant is null, skip.
// This allows participants to complete whilst wakers still exist // This allows participants to complete whilst wakers still exist
// somewhere. // somewhere.

@ -109,16 +109,20 @@ class Scope {
const Metadata* const metadata_; const Metadata* const metadata_;
}; };
using ParentScope = Scope<true>;
using InnerScope = Scope<false>;
class Flow { class Flow {
public: public:
explicit Flow(const Metadata* metadata) : metadata_(metadata) { GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION Flow() : metadata_(nullptr) {}
GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION explicit Flow(const Metadata* metadata)
: metadata_(metadata) {
Log::Append(metadata_, EventType::kFlowStart, id_); Log::Append(metadata_, EventType::kFlowStart, id_);
Log::FlushThreadLog(); Log::FlushThreadLog();
} }
~Flow() { GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION ~Flow() {
if (metadata_ != nullptr) { if (metadata_ != nullptr) {
Log::Append(metadata_, EventType::kFlowEnd, id_); Log::Append(metadata_, EventType::kFlowEnd, id_);
Log::FlushThreadLog();
} }
} }
@ -133,8 +137,17 @@ class Flow {
return *this; return *this;
} }
bool has_value() const { return metadata_ != nullptr; } GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION bool has_value() const {
void reset() { metadata_ = nullptr; } return metadata_ != nullptr;
}
GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION void reset() { emplace(nullptr); }
GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION void emplace(const Metadata* metadata) {
if (metadata_ != nullptr) Log::Append(metadata_, EventType::kFlowEnd, id_);
metadata_ = metadata;
if (metadata_ == nullptr) return;
id_ = next_flow_id_.fetch_add(1, std::memory_order_relaxed);
Log::Append(metadata_, EventType::kFlowStart, id_);
}
private: private:
const Metadata* metadata_; const Metadata* metadata_;
@ -158,12 +171,13 @@ GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION inline void Mark(const Metadata* md) {
// exit. Because the flush takes some time it's better to place one parent scope // exit. Because the flush takes some time it's better to place one parent scope
// at the top of the stack, and use lighter weight scopes within it. // at the top of the stack, and use lighter weight scopes within it.
#define GRPC_LATENT_SEE_PARENT_SCOPE(name) \ #define GRPC_LATENT_SEE_PARENT_SCOPE(name) \
grpc_core::latent_see::Scope<true> latent_see_scope##__LINE__( \ grpc_core::latent_see::ParentScope latent_see_scope##__LINE__( \
GRPC_LATENT_SEE_METADATA(name)) GRPC_LATENT_SEE_METADATA(name))
// Scope: logs a begin and end event. Lighter weight than parent scope, but does // Inner scope: logs a begin and end event. Lighter weight than parent scope,
// not flush the thread state - so should only be enclosed by a parent scope. // but does not flush the thread state - so should only be enclosed by a parent
#define GRPC_LATENT_SEE_SCOPE(name) \ // scope.
grpc_core::latent_see::Scope<false> latent_see_scope##__LINE__( \ #define GRPC_LATENT_SEE_INNER_SCOPE(name) \
grpc_core::latent_see::InnerScope latent_see_scope##__LINE__( \
GRPC_LATENT_SEE_METADATA(name)) GRPC_LATENT_SEE_METADATA(name))
// Mark: logs a single event. // Mark: logs a single event.
#define GRPC_LATENT_SEE_MARK(name) \ #define GRPC_LATENT_SEE_MARK(name) \
@ -187,8 +201,8 @@ struct Flow {
#define GRPC_LATENT_SEE_PARENT_SCOPE(name) \ #define GRPC_LATENT_SEE_PARENT_SCOPE(name) \
do { \ do { \
} while (0) } while (0)
#define GRPC_LATENT_SEE_SCOPE(name) \ #define GRPC_LATENT_SEE_INNER_SCOPE(name) \
do { \ do { \
} while (0) } while (0)
#define GRPC_LATENT_SEE_MARK(name) \ #define GRPC_LATENT_SEE_MARK(name) \
do { \ do { \

Loading…
Cancel
Save