Revert "Make Profiler::active_profiler a unique pointer" and add comment

This commit is contained in:
sfc-gh-tclinkenbeard 2021-01-21 14:25:20 -08:00
parent 065c7e570c
commit 4dd9c4889e
1 changed files with 7 additions and 5 deletions

View File

@ -25,7 +25,6 @@
#ifdef __linux__
#include <execinfo.h>
#include <memory>
#include <signal.h>
#include <sys/time.h>
#include <stdlib.h>
@ -125,7 +124,7 @@ struct Profiler {
OutputBuffer* output_buffer;
Future<Void> actor;
sigset_t profilingSignals;
static std::unique_ptr<Profiler> active_profiler;
static Profiler* active_profiler;
BinaryWriter environmentInfoWriter;
INetwork* network;
timer_t periodicTimer;
@ -257,7 +256,8 @@ struct Profiler {
}
};
std::unique_ptr<Profiler> Profiler::active_profiler;
// Outlives main
Profiler* Profiler::active_profiler = nullptr;
std::string findAndReplace( std::string const& fn, std::string const& symbol, std::string const& value ) {
auto i = fn.find(symbol);
@ -283,12 +283,14 @@ void startProfiling(INetwork* network, Optional<int> maybePeriod /*= {}*/, Optio
outputFile = findAndReplace(findAndReplace(findAndReplace(outputFile, "%ADDRESS%", findAndReplace(network->getLocalAddress().toString(), ":", ".")), "%PID%", format("%d", getpid())), "%TID%", format("%llx", (long long)sys_gettid()));
if (!Profiler::active_profiler)
Profiler::active_profiler = std::make_unique<Profiler>( period, outputFile, network );
Profiler::active_profiler = new Profiler( period, outputFile, network );
}
void stopProfiling() {
if (Profiler::active_profiler) {
Profiler::active_profiler.reset();
Profiler *p = Profiler::active_profiler;
Profiler::active_profiler = nullptr;
delete p;
}
}