Skip to content

Commit

Permalink
Gator 8.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bengaineyarm committed Jun 23, 2022
1 parent 1ae0c4d commit 86ccae2
Show file tree
Hide file tree
Showing 197 changed files with 18,625 additions and 12,425 deletions.
11 changes: 11 additions & 0 deletions daemon/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ void Buffer::beginFrame(FrameType frameType)
packInt(static_cast<int32_t>(frameType));
}

void Buffer::writeRawFrame(lib::Span<const char> frame)
{
if (mIncludeResponseType) {
packInt(static_cast<int32_t>(ResponseType::APC_DATA));
}
// Reserve space for the length
// NOLINTNEXTLINE(bugprone-narrowing-conversions, hicpp-signed-bitwise)
mWritePos = (mWritePos + sizeof(int32_t)) & mask;
writeBytes(frame.data(), frame.size());
}

void Buffer::abortFrame()
{
mWritePos = mCommitPos;
Expand Down
1 change: 1 addition & 0 deletions daemon/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Buffer : public IBufferControl, public IRawFrameBuilderWithDirectAccess {
int packInt64(int64_t x) override;
void writeBytes(const void * data, std::size_t count) override;
void writeString(std::string_view str) override;
void writeRawFrame(lib::Span<const char> frame);

void beginFrame(FrameType frameType) override;
void abortFrame() override;
Expand Down
76 changes: 49 additions & 27 deletions daemon/CMakeLists.txt

Large diffs are not rendered by default.

117 changes: 36 additions & 81 deletions daemon/Child.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "Child.h"

#include "CapturedXML.h"
#include "Command.h"
#include "ConfigurationXML.h"
#include "CounterXML.h"
#include "Driver.h"
Expand All @@ -23,6 +22,7 @@
#include "StreamlineSetup.h"
#include "UserSpaceSource.h"
#include "armnn/ArmNNSource.h"
#include "capture/CaptureProcess.h"
#include "lib/Assert.h"
#include "lib/FsUtils.h"
#include "lib/WaitForProcessPoller.h"
Expand Down Expand Up @@ -72,21 +72,33 @@ void handleException()
std::unique_ptr<Child> Child::createLocal(agents::i_agent_spawner_t & spawner,
Drivers & drivers,
const Child::Config & config,
capture::capture_process_event_listener_t & event_listener,
logging::last_log_error_supplier_t last_error_supplier,
logging::log_setup_supplier_t log_setup_supplier)
{
return std::unique_ptr<Child>(
new Child(spawner, drivers, nullptr, config, std::move(last_error_supplier), std::move(log_setup_supplier)));
return std::unique_ptr<Child>(new Child(spawner,
drivers,
nullptr,
config,
event_listener,
std::move(last_error_supplier),
std::move(log_setup_supplier)));
}

std::unique_ptr<Child> Child::createLive(agents::i_agent_spawner_t & spawner,
Drivers & drivers,
OlySocket & sock,
capture::capture_process_event_listener_t & event_listener,
logging::last_log_error_supplier_t last_error_supplier,
logging::log_setup_supplier_t log_setup_supplier)
{
return std::unique_ptr<Child>(
new Child(spawner, drivers, &sock, {}, std::move(last_error_supplier), std::move(log_setup_supplier)));
return std::unique_ptr<Child>(new Child(spawner,
drivers,
&sock,
{},
event_listener,
std::move(last_error_supplier),
std::move(log_setup_supplier)));
}

Child * Child::getSingleton()
Expand All @@ -110,13 +122,15 @@ Child::Child(agents::i_agent_spawner_t & spawner,
Drivers & drivers,
OlySocket * sock,
Child::Config config,
capture::capture_process_event_listener_t & event_listener,
logging::last_log_error_supplier_t last_error_supplier,
logging::log_setup_supplier_t log_setup_supplier)
: haltPipeline(),
senderSem(),
sender(),
drivers(drivers),
socket(sock),
event_listener(event_listener),
numExceptions(0),
sessionEnded(),
config(std::move(config)),
Expand Down Expand Up @@ -149,7 +163,7 @@ Child::~Child()
runtime_assert(prevSingleton == this, "Exchanged Child::gSingleton with something other than this");
}

void Child::run(int notify_pid)
void Child::run()
{
prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(&"gatord-child"), 0, 0, 0);

Expand Down Expand Up @@ -258,73 +272,36 @@ void Child::run(int notify_pid)
primarySourceProvider.getDetectedUncorePmus());
}

std::set<int> appPids;
bool enableOnCommandExec = false;
if (!gSessionData.mCaptureCommand.empty()) {
std::string captureCommand;
for (auto const & cmd : gSessionData.mCaptureCommand) {
captureCommand += " ";
captureCommand += cmd;
}
LOG_WARNING("Running command:%s", captureCommand.c_str());

// This is set before any threads are started so it doesn't need
// to be protected by a mutex
command = std::make_shared<Command>(Command::run([this]() {
if (gSessionData.mStopOnExit) {
LOG_DEBUG("Ending session because command exited");
endSession();
}
}));

enableOnCommandExec = true;

appPids.insert(command->getPid());
LOG_DEBUG("Profiling pid: %d", command->getPid());
}

// set up stop thread early, so that ping commands get replied to, even if the
// setup phase below takes a long time.
std::thread stopThread {[this]() { stopThreadEntryPoint(); }};

// tell the controller that we're ready for the app to start
if (notify_pid > 0) {
LOG_DEBUG("Telling notify_pid (%d) to start the target app", notify_pid);
kill(notify_pid, SIGUSR1);
}

if (gSessionData.mWaitForProcessCommand != nullptr) {
LOG_DEBUG("Waiting for pids for command '%s'", gSessionData.mWaitForProcessCommand);

WaitForProcessPoller poller {gSessionData.mWaitForProcessCommand};

while ((!poller.poll(appPids)) && !sessionEnded) {
usleep(1000);
auto execTargetCallback = [this]() {
LOG_DEBUG("Received exec_target callback");
if (!event_listener.waiting_for_target()) {
handleException();
}
LOG_DEBUG("Got pids for command '%s'", gSessionData.mWaitForProcessCommand);
}

// we only consider --pid for stop on exit if we weren't given an
// app to run
std::set<int> watchPids = appPids.empty() ? gSessionData.mPids : appPids;

appPids.insert(gSessionData.mPids.begin(), gSessionData.mPids.end());
};

lib::Waiter waitTillStart;
lib::Waiter waitForAgents;

auto startedCallback = [&]() {
LOG_DEBUG("Received start capture callback");
waitTillStart.disable();
if (command) {
command->start();
}
};

auto newPrimarySource = primarySourceProvider.createPrimarySource(senderSem,
startedCallback,
appPids,
drivers.getFtraceDriver(),
enableOnCommandExec);
auto newPrimarySource = primarySourceProvider.createPrimarySource(
senderSem,
*sender,
[this]() -> bool { return sessionEnded; },
execTargetCallback,
startedCallback,
gSessionData.mPids,
drivers.getFtraceDriver(),
!gSessionData.mCaptureCommand.empty(),
agent_workers_process);
if (newPrimarySource == nullptr) {
LOG_ERROR("%s", primarySourceProvider.getPrepareFailedMessage());
handleException();
Expand Down Expand Up @@ -377,11 +354,6 @@ void Child::run(int notify_pid)
durationThread = std::thread([&]() { durationThreadEntryPoint(waitTillStart, waitTillEnd); });
}

std::thread watchPidsThread {};
if (gSessionData.mStopOnExit && !watchPids.empty()) {
watchPidsThread = std::thread([&]() { watchPidsThreadEntryPoint(watchPids, waitTillEnd); });
}

if (shouldStartUserSpaceSource(drivers.getAllPolledConst())) {
if (!addSource(createUserSpaceSource(senderSem, drivers.getAllPolled()))) {
LOG_ERROR("Unable to prepare userspace source for capture");
Expand Down Expand Up @@ -418,9 +390,6 @@ void Child::run(int notify_pid)
thread.join();
}

if (watchPidsThread.joinable()) {
watchPidsThread.join();
}
if (durationThread.joinable()) {
durationThread.join();
}
Expand Down Expand Up @@ -448,12 +417,6 @@ void Child::run(int notify_pid)

sources.clear();
sender.reset();

if (command) {
LOG_DEBUG("Waiting for command (PID: %d)", command->getPid());
command->join();
LOG_DEBUG("Command finished");
}
}

template<typename S>
Expand Down Expand Up @@ -497,10 +460,6 @@ void Child::doEndSession()

sessionEnded = true;

if (command) {
command->cancel();
}

for (auto & source : sources) {
source->interrupt();
}
Expand All @@ -517,10 +476,6 @@ void Child::cleanupException()
_exit(SECOND_EXCEPTION_EXIT_CODE);
}

if (command) {
command->cancel();
}

if (socket != nullptr) {
if (sender) {
// send the error, regardless of the command sent by Streamline
Expand Down
12 changes: 7 additions & 5 deletions daemon/Child.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Configuration.h"
#include "Source.h"
#include "agents/agent_workers_process.h"
#include "capture/CaptureProcess.h"
#include "lib/AutoClosingFd.h"
#include "logging/suppliers.h"

Expand Down Expand Up @@ -38,11 +39,13 @@ class Child {
static std::unique_ptr<Child> createLocal(agents::i_agent_spawner_t & spawner,
Drivers & drivers,
const Config & config,
capture::capture_process_event_listener_t & event_listener,
logging::last_log_error_supplier_t last_error_supplier,
logging::log_setup_supplier_t log_setup_supplier);
static std::unique_ptr<Child> createLive(agents::i_agent_spawner_t & spawner,
Drivers & drivers,
OlySocket & sock,
capture::capture_process_event_listener_t & event_listener,
logging::last_log_error_supplier_t last_error_supplier,
logging::log_setup_supplier_t log_setup_supplier);

Expand All @@ -55,12 +58,9 @@ class Child {
Child & operator=(Child &&) = delete;

/**
* @brief Runs the capture process. If notify_pid is set then SIGUSR1 will be sent to
* that pid when the capture process is ready for the target app to be started.
*
* @param notify_pid The pid to signal when the target app should be started. When <= 0 no signal is sent.
* @brief Runs the capture process
*/
void run(int notify_pid);
void run();

void endSession(int signum = 0);

Expand All @@ -80,6 +80,7 @@ class Child {
std::unique_ptr<Sender> sender;
Drivers & drivers;
OlySocket * socket;
capture::capture_process_event_listener_t & event_listener;
int numExceptions;
std::mutex sessionEndedMutex {};
lib::AutoClosingFd sessionEndEventFd {};
Expand All @@ -95,6 +96,7 @@ class Child {
Drivers & drivers,
OlySocket * sock,
Config config,
capture::capture_process_event_listener_t & event_listener,
logging::last_log_error_supplier_t last_error_supplier,
logging::log_setup_supplier_t log_setup_supplier);

Expand Down
Loading

0 comments on commit 86ccae2

Please sign in to comment.