From 805c4200ce7a8f2e76b6feccf6f350f1ec83f8c2 Mon Sep 17 00:00:00 2001 From: Lukas Joswiak Date: Wed, 16 Jun 2021 18:08:51 -0700 Subject: [PATCH] Add collector to get running actor name --- fdbclient/ActorLineageProfiler.cpp | 8 +++--- fdbclient/ActorLineageProfiler.h | 2 +- fdbclient/CMakeLists.txt | 2 ++ fdbclient/NameLineage.cpp | 25 ++++++++++++++++++ fdbclient/NameLineage.h | 39 +++++++++++++++++++++++++++++ fdbclient/NativeAPI.actor.cpp | 2 ++ fdbserver/worker.actor.cpp | 1 - flow/actorcompiler/ActorCompiler.cs | 1 + flow/flow.cpp | 2 +- flow/flow.h | 18 ++++++++----- 10 files changed, 88 insertions(+), 12 deletions(-) create mode 100644 fdbclient/NameLineage.cpp create mode 100644 fdbclient/NameLineage.h diff --git a/fdbclient/ActorLineageProfiler.cpp b/fdbclient/ActorLineageProfiler.cpp index cd9c22fbf0..7ceedf144d 100644 --- a/fdbclient/ActorLineageProfiler.cpp +++ b/fdbclient/ActorLineageProfiler.cpp @@ -22,6 +22,7 @@ #include "flow/singleton.h" #include "fdbrpc/IAsyncFile.h" #include "fdbclient/ActorLineageProfiler.h" +#include "fdbclient/NameLineage.h" #include #include #include @@ -249,9 +250,10 @@ std::vector> SampleCollection_t::get(double from /*= 0.0 return res; } -void sample(Reference* p) { - if (!p->isValid()) { return; } - boost::asio::post(ActorLineageProfiler::instance().context(), [lineage = Reference::addRef(p->getPtr())]() { +void sample(LineageReference* lineagePtr) { + if (!lineagePtr->isValid()) { return; } + (*lineagePtr)->modify(&NameLineage::actorName) = lineagePtr->actorName(); + boost::asio::post(ActorLineageProfiler::instance().context(), [lineage = LineageReference::addRef(lineagePtr->getPtr())]() { SampleCollection::instance().collect(lineage); }); } diff --git a/fdbclient/ActorLineageProfiler.h b/fdbclient/ActorLineageProfiler.h index e18a740e10..60d5c9f815 100644 --- a/fdbclient/ActorLineageProfiler.h +++ b/fdbclient/ActorLineageProfiler.h @@ -143,7 +143,7 @@ class SampleCollection_t { SampleCollector _collector; mutable std::mutex mutex; - std::atomic windowSize = 60.0; + std::atomic windowSize = 0.0; std::deque> data; ProfilerConfig config; diff --git a/fdbclient/CMakeLists.txt b/fdbclient/CMakeLists.txt index 7138962115..bb78a82b4e 100644 --- a/fdbclient/CMakeLists.txt +++ b/fdbclient/CMakeLists.txt @@ -54,6 +54,8 @@ set(FDBCLIENT_SRCS MultiVersionTransaction.actor.cpp MultiVersionTransaction.h MutationList.h + NameLineage.h + NameLineage.cpp NativeAPI.actor.cpp NativeAPI.actor.h Notified.h diff --git a/fdbclient/NameLineage.cpp b/fdbclient/NameLineage.cpp new file mode 100644 index 0000000000..5f98cf73c4 --- /dev/null +++ b/fdbclient/NameLineage.cpp @@ -0,0 +1,25 @@ +/* + * NameLineage.cpp + * + * This source file is part of the FoundationDB open source project + * + * Copyright 2013-2021 Apple Inc. and the FoundationDB project authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "fdbclient/NameLineage.h" + +namespace { +NameLineageCollector nameLineageCollector; +} diff --git a/fdbclient/NameLineage.h b/fdbclient/NameLineage.h new file mode 100644 index 0000000000..691fde4baa --- /dev/null +++ b/fdbclient/NameLineage.h @@ -0,0 +1,39 @@ +/* + * NameLineage.h + * + * This source file is part of the FoundationDB open source project + * + * Copyright 2013-2021 Apple Inc. and the FoundationDB project authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#include "fdbclient/ActorLineageProfiler.h" + +struct NameLineage : LineageProperties { + static constexpr std::string_view name = "Actor"sv; + const char* actorName; +}; + +struct NameLineageCollector : IALPCollector { + NameLineageCollector() : IALPCollector() {} + std::optional collect(ActorLineage* lineage) override { + auto str = lineage->get(&NameLineage::actorName); + ASSERT(str.has_value()); + return std::string_view(*str, std::strlen(*str)); + } +}; diff --git a/fdbclient/NativeAPI.actor.cpp b/fdbclient/NativeAPI.actor.cpp index 164b8a828c..a8028f2c13 100644 --- a/fdbclient/NativeAPI.actor.cpp +++ b/fdbclient/NativeAPI.actor.cpp @@ -44,6 +44,7 @@ #include "fdbclient/KeyRangeMap.h" #include "fdbclient/Knobs.h" #include "fdbclient/ManagementAPI.actor.h" +#include "fdbclient/NameLineage.h" #include "fdbclient/CommitProxyInterface.h" #include "fdbclient/MonitorLeader.h" #include "fdbclient/MutationList.h" @@ -90,6 +91,7 @@ using std::pair; namespace { TransactionLineageCollector transactionLineageCollector; +NameLineageCollector nameLineageCollector; template Future loadBalance( diff --git a/fdbserver/worker.actor.cpp b/fdbserver/worker.actor.cpp index a6e17e58e6..869bbad461 100644 --- a/fdbserver/worker.actor.cpp +++ b/fdbserver/worker.actor.cpp @@ -2171,7 +2171,6 @@ ACTOR Future fdbd(Reference connFile, auto asyncPriorityInfo = makeReference>(getCCPriorityInfo(fitnessFilePath, processClass)); auto dbInfo = makeReference>(); - ActorLineageProfiler::instance().setFrequency(10); actors.push_back(reportErrors(monitorAndWriteCCPriorityInfo(fitnessFilePath, asyncPriorityInfo), "MonitorAndWriteCCPriorityInfo")); diff --git a/flow/actorcompiler/ActorCompiler.cs b/flow/actorcompiler/ActorCompiler.cs index df7a1ea853..cb464b140e 100644 --- a/flow/actorcompiler/ActorCompiler.cs +++ b/flow/actorcompiler/ActorCompiler.cs @@ -1286,6 +1286,7 @@ namespace actorcompiler constructor.WriteLine("{"); constructor.Indent(+1); ProbeEnter(constructor, actor.name); + constructor.WriteLine("this->lineage.setActorName(\"{0}\");", actor.name); constructor.WriteLine("LineageScope _(&this->lineage);"); // constructor.WriteLine("getCurrentLineage()->modify(&StackLineage::actorName) = LiteralStringRef(\"{0}\");", actor.name); constructor.WriteLine("this->{0};", body.call()); diff --git a/flow/flow.cpp b/flow/flow.cpp index 2cab41d550..ee95c14c80 100644 --- a/flow/flow.cpp +++ b/flow/flow.cpp @@ -48,7 +48,7 @@ Reference getCurrentLineage() { return *currentLineage; } -void sample(Reference* p); +void sample(LineageReference* lineagePtr); void replaceLineage(LineageReference* lineage) { if (!startSampling) { diff --git a/flow/flow.h b/flow/flow.h index 1554185222..d080546597 100644 --- a/flow/flow.h +++ b/flow/flow.h @@ -547,18 +547,24 @@ public: // getCurrentLineage()). class LineageReference : public Reference { public: - LineageReference() : Reference(nullptr), allocated(false) {} - explicit LineageReference(ActorLineage* ptr) : Reference(ptr), allocated(false) {} - LineageReference(const LineageReference& r) : Reference(r), allocated(false) {} + LineageReference() : Reference(nullptr), allocated_(false) {} + explicit LineageReference(ActorLineage* ptr) : Reference(ptr), allocated_(false) {} + LineageReference(const LineageReference& r) : Reference(r), allocated_(false) {} + void setActorName(const char* name) { actorName_ = name; } + const char* actorName() { return actorName_; } void allocate() { Reference::setPtrUnsafe(new ActorLineage()); - allocated = true; + allocated_ = true; } - bool isAllocated() { return allocated; } + bool isAllocated() { return allocated_; } private: - bool allocated; + // The actor name has to be a property of the LineageReference because all + // actors store their own LineageReference copy, but not all actors point + // to their own ActorLineage. + const char* actorName_; + bool allocated_; }; extern std::atomic startSampling;