mirror of
https://github.com/apple/foundationdb.git
synced 2025-05-31 18:19:35 +08:00
Add collector to get running actor name
This commit is contained in:
parent
d291f11e71
commit
805c4200ce
@ -22,6 +22,7 @@
|
||||
#include "flow/singleton.h"
|
||||
#include "fdbrpc/IAsyncFile.h"
|
||||
#include "fdbclient/ActorLineageProfiler.h"
|
||||
#include "fdbclient/NameLineage.h"
|
||||
#include <msgpack.hpp>
|
||||
#include <memory>
|
||||
#include <boost/endian/conversion.hpp>
|
||||
@ -249,9 +250,10 @@ std::vector<std::shared_ptr<Sample>> SampleCollection_t::get(double from /*= 0.0
|
||||
return res;
|
||||
}
|
||||
|
||||
void sample(Reference<ActorLineage>* p) {
|
||||
if (!p->isValid()) { return; }
|
||||
boost::asio::post(ActorLineageProfiler::instance().context(), [lineage = Reference<ActorLineage>::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);
|
||||
});
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ class SampleCollection_t {
|
||||
|
||||
SampleCollector _collector;
|
||||
mutable std::mutex mutex;
|
||||
std::atomic<double> windowSize = 60.0;
|
||||
std::atomic<double> windowSize = 0.0;
|
||||
std::deque<std::shared_ptr<Sample>> data;
|
||||
ProfilerConfig config;
|
||||
|
||||
|
@ -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
|
||||
|
25
fdbclient/NameLineage.cpp
Normal file
25
fdbclient/NameLineage.cpp
Normal file
@ -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;
|
||||
}
|
39
fdbclient/NameLineage.h
Normal file
39
fdbclient/NameLineage.h
Normal file
@ -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 <string_view>
|
||||
|
||||
#include "fdbclient/ActorLineageProfiler.h"
|
||||
|
||||
struct NameLineage : LineageProperties<NameLineage> {
|
||||
static constexpr std::string_view name = "Actor"sv;
|
||||
const char* actorName;
|
||||
};
|
||||
|
||||
struct NameLineageCollector : IALPCollector<NameLineage> {
|
||||
NameLineageCollector() : IALPCollector() {}
|
||||
std::optional<std::any> collect(ActorLineage* lineage) override {
|
||||
auto str = lineage->get(&NameLineage::actorName);
|
||||
ASSERT(str.has_value());
|
||||
return std::string_view(*str, std::strlen(*str));
|
||||
}
|
||||
};
|
@ -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 <class Interface, class Request>
|
||||
Future<REPLY_TYPE(Request)> loadBalance(
|
||||
|
@ -2171,7 +2171,6 @@ ACTOR Future<Void> fdbd(Reference<ClusterConnectionFile> connFile,
|
||||
auto asyncPriorityInfo =
|
||||
makeReference<AsyncVar<ClusterControllerPriorityInfo>>(getCCPriorityInfo(fitnessFilePath, processClass));
|
||||
auto dbInfo = makeReference<AsyncVar<ServerDBInfo>>();
|
||||
ActorLineageProfiler::instance().setFrequency(10);
|
||||
|
||||
actors.push_back(reportErrors(monitorAndWriteCCPriorityInfo(fitnessFilePath, asyncPriorityInfo),
|
||||
"MonitorAndWriteCCPriorityInfo"));
|
||||
|
@ -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());
|
||||
|
@ -48,7 +48,7 @@ Reference<ActorLineage> getCurrentLineage() {
|
||||
return *currentLineage;
|
||||
}
|
||||
|
||||
void sample(Reference<ActorLineage>* p);
|
||||
void sample(LineageReference* lineagePtr);
|
||||
|
||||
void replaceLineage(LineageReference* lineage) {
|
||||
if (!startSampling) {
|
||||
|
18
flow/flow.h
18
flow/flow.h
@ -547,18 +547,24 @@ public:
|
||||
// getCurrentLineage()).
|
||||
class LineageReference : public Reference<ActorLineage> {
|
||||
public:
|
||||
LineageReference() : Reference<ActorLineage>(nullptr), allocated(false) {}
|
||||
explicit LineageReference(ActorLineage* ptr) : Reference<ActorLineage>(ptr), allocated(false) {}
|
||||
LineageReference(const LineageReference& r) : Reference<ActorLineage>(r), allocated(false) {}
|
||||
LineageReference() : Reference<ActorLineage>(nullptr), allocated_(false) {}
|
||||
explicit LineageReference(ActorLineage* ptr) : Reference<ActorLineage>(ptr), allocated_(false) {}
|
||||
LineageReference(const LineageReference& r) : Reference<ActorLineage>(r), allocated_(false) {}
|
||||
|
||||
void setActorName(const char* name) { actorName_ = name; }
|
||||
const char* actorName() { return actorName_; }
|
||||
void allocate() {
|
||||
Reference<ActorLineage>::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<bool> startSampling;
|
||||
|
Loading…
x
Reference in New Issue
Block a user