Skip to content

Commit

Permalink
Gator 8.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bengaineyarm committed Dec 1, 2022
1 parent 86ccae2 commit b6ad117
Show file tree
Hide file tree
Showing 102 changed files with 2,802 additions and 1,047 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "vcpkg"]
path = vcpkg
url = https://github.com/microsoft/vcpkg.git
[submodule "ext/perfetto"]
path = ext/perfetto
url = https://github.com/google/perfetto.git
2 changes: 1 addition & 1 deletion build-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ show_help() {
echo "Usage:"
echo " $0 [-n <ndk>] [-a <api>] [-t <target>] [-g <generator>] [-o <path>] [-c <cmake>] [-l <mode>] [-d] [-s]"
echo "Where:"
echo " -p <profile> - Specify the predefined provile to build. Defaults to "
echo " -p <profile> - Specify the predefined profile to build. Defaults to "
echo " 'native-gcc' if not specified. Must be one of "
echo " 'native-gcc', 'native-clang', 'arm-glibc', 'arm-musl', "
echo " 'arm64-glibc' or 'arm64-musl'."
Expand Down
1,235 changes: 636 additions & 599 deletions daemon/CMakeLists.txt

Large diffs are not rendered by default.

17 changes: 14 additions & 3 deletions daemon/CapturedXML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Logging.h"
#include "OlyUtility.h"
#include "PrimarySourceProvider.h"
#include "ProtocolVersion.h"
#include "SessionData.h"
#include "lib/FsEntry.h"
#include "lib/String.h"
Expand All @@ -20,6 +21,7 @@
#include <set>

#include <dirent.h>
#include <mxml/mxml.h>

/* Basic target OS detection */
#undef GATOR_TARGET_OS
Expand Down Expand Up @@ -108,6 +110,11 @@ static mxml_node_t * getTree(bool includeTime,
}
}

if (gSessionData.mWaitForProcessCommand != nullptr) {
mxml_node_t * const process_data = mxmlNewElement(captured, "process");
mxmlElementSetAttrf(process_data, "process_name", "%s", gSessionData.mWaitForProcessCommand);
}

auto * const target = mxmlNewElement(captured, "target");
mxmlElementSetAttrf(target, "sample_rate", "%d", gSessionData.mSampleRate);
const auto & cpuInfo = primarySourceProvider.getCpuInfo();
Expand All @@ -119,14 +126,14 @@ static mxml_node_t * getTree(bool includeTime,
//gatord src md5
mxmlElementSetAttrf(target, "gatord_src_md5sum", "%s", gSrcMd5);
//gatord build commit id
mxmlElementSetAttrf(target, "gatord_build_id", "%s", STRIFY(GATORD_BUILD_ID));
mxmlElementSetAttrf(target, "gatord_build_id", "%s", gBuildId);

assert(cpuIds.size() > 0); // gatord should've died earlier if there were no cpus
mxmlElementSetAttrf(target, "cpuid", "0x%x", *std::max_element(std::begin(cpuIds), std::end(cpuIds)));

/* SDDAP-10049: Removed `&& (gSessionData.mSampleRate > 0)` - this allows sample rate: none
* to work with live mode, at the risk that live display is 'jittery' as data sending is dependent
* on CPU's being active and doing some context switching. */
* to work with live mode, at the risk that live display is 'jittery' as data sending is dependent
* on CPU's being active and doing some context switching. */
if (!gSessionData.mOneShot) {
mxmlElementSetAttr(target, "supports_live", "yes");
}
Expand Down Expand Up @@ -161,6 +168,10 @@ static mxml_node_t * getTree(bool includeTime,

mxml_node_t * counters = nullptr;
for (const auto & counter : gSessionData.mCounters) {
if(counter.excludeFromCapturedXml()) {
continue;
}

if (counter.isEnabled()) {
if (counters == nullptr) {
counters = mxmlNewElement(captured, "counters");
Expand Down
110 changes: 76 additions & 34 deletions daemon/Child.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@
#include "SessionData.h"
#include "StreamlineSetup.h"
#include "UserSpaceSource.h"
#include "agents/perfetto/perfetto_driver.h"
#include "agents/spawn_agent.h"
#include "armnn/ArmNNSource.h"
#include "capture/CaptureProcess.h"
#include "capture/Environment.h"
#include "lib/Assert.h"
#include "lib/FsUtils.h"
#include "lib/WaitForProcessPoller.h"
#include "lib/Waiter.h"
#include "lib/perfetto_utils.h"
#include "logging/global_log.h"
#include "mali_userspace/MaliHwCntrSource.h"
#include "xml/EventsXML.h"
Expand All @@ -38,6 +42,8 @@
#include <thread>
#include <utility>

#include <boost/asio/detached.hpp>

#include <sys/eventfd.h>
#include <sys/prctl.h>
#include <sys/wait.h>
Expand Down Expand Up @@ -69,14 +75,16 @@ void handleException()
_exit(EXCEPTION_EXIT_CODE);
}

std::unique_ptr<Child> Child::createLocal(agents::i_agent_spawner_t & spawner,
std::unique_ptr<Child> Child::createLocal(agents::i_agent_spawner_t & hi_priv_spawner,
agents::i_agent_spawner_t & lo_priv_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,
return std::unique_ptr<Child>(new Child(hi_priv_spawner,
lo_priv_spawner,
drivers,
nullptr,
config,
Expand All @@ -85,14 +93,16 @@ std::unique_ptr<Child> Child::createLocal(agents::i_agent_spawner_t & spawner,
std::move(log_setup_supplier)));
}

std::unique_ptr<Child> Child::createLive(agents::i_agent_spawner_t & spawner,
std::unique_ptr<Child> Child::createLive(agents::i_agent_spawner_t & hi_priv_spawner,
agents::i_agent_spawner_t & lo_priv_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,
return std::unique_ptr<Child>(new Child(hi_priv_spawner,
lo_priv_spawner,
drivers,
&sock,
{},
Expand All @@ -118,7 +128,8 @@ void Child::signalHandler(int signum)
singleton->endSession(signum);
}

Child::Child(agents::i_agent_spawner_t & spawner,
Child::Child(agents::i_agent_spawner_t & hi_priv_spawner,
agents::i_agent_spawner_t & lo_priv_spawner,
Drivers & drivers,
OlySocket * sock,
Child::Config config,
Expand All @@ -136,7 +147,7 @@ Child::Child(agents::i_agent_spawner_t & spawner,
config(std::move(config)),
last_error_supplier(std::move(last_error_supplier)),
log_setup_supplier(std::move(log_setup_supplier)),
agent_workers_process(*this, spawner)
agent_workers_process(*this, hi_priv_spawner, lo_priv_spawner)
{
const int fd = eventfd(0, EFD_CLOEXEC);
if (fd == -1) {
Expand Down Expand Up @@ -226,6 +237,7 @@ void Child::run()
counter.getDriver()->setupCounter(counter);
}
}

std::vector<CapturedSpe> capturedSpes;
for (const auto & speConfig : speConfigs) {
bool claimed = false;
Expand Down Expand Up @@ -285,13 +297,68 @@ void Child::run()
};

lib::Waiter waitTillStart;
lib::Waiter waitForAgents;
lib::Waiter waitForExternalSourceAgent;
lib::Waiter waitForPerfettoAgent;

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

bool enablePerfettoAgent = drivers.getPerfettoDriver().perfettoEnabled();

// Initialize ftrace source before child as it's slow and depends on nothing else
// If initialized later, us gator with ftrace has time sync issues
// Must be initialized before senderThread is started as senderThread checks externalSource
if (!addSource(createExternalSource(senderSem, drivers),
[this, &waitForExternalSourceAgent, &waitForPerfettoAgent, enablePerfettoAgent](auto & source) {
this->agent_workers_process.async_add_external_source(
source,
[&waitForExternalSourceAgent](bool success) {
waitForExternalSourceAgent.disable();
if (!success) {
handleException();
}
else {
LOG_DEBUG("Started ext_source agent");
}
});
#if defined(ANDROID) || defined(__ANDROID__)
if (enablePerfettoAgent) {
this->agent_workers_process.async_add_perfetto_source(
source,
[&waitForPerfettoAgent](bool success) {
waitForPerfettoAgent.disable();
if (!success) {
LOG_ERROR("Failed to start perfetto agent");
handleException();
}
else {
LOG_DEBUG("Started perfetto agent");
}
});
}
else {
waitForPerfettoAgent.disable();
}
#else
(void) enablePerfettoAgent;
waitForPerfettoAgent.disable();
#endif
})) {
LOG_ERROR("Unable to prepare external source for capture");
handleException();
}

// wait for the ext agent to start
if (!sessionEnded) {
LOG_DEBUG("Waiting for agents to start");
waitForExternalSourceAgent.wait();
waitForPerfettoAgent.wait();
LOG_DEBUG("Waiting for agents complete");
}

// create the primary source last as it will launch the process, which may lead to a race receiving external messages
auto newPrimarySource = primarySourceProvider.createPrimarySource(
senderSem,
*sender,
Expand All @@ -310,31 +377,6 @@ void Child::run()
auto & primarySource = *newPrimarySource;
addSource(std::move(newPrimarySource));

// Initialize ftrace source before child as it's slow and depends on nothing else
// If initialized later, us gator with ftrace has time sync issues
// Must be initialized before senderThread is started as senderThread checks externalSource
if (!addSource(createExternalSource(senderSem, drivers), [this, &waitForAgents](auto & source) {
this->agent_workers_process.async_add_external_source(source, [&waitForAgents](bool success) {
waitForAgents.disable();
if (!success) {
handleException();
}
else {
LOG_DEBUG("Started ext_source agent");
}
});
})) {
LOG_ERROR("Unable to prepare external source for capture");
handleException();
}

// wait for the ext agent to start
if (!sessionEnded) {
LOG_DEBUG("Waiting for agent to start");
waitForAgents.wait();
LOG_DEBUG("Waiting for agent complete");
}

// initialize midgard hardware counters
if (drivers.getMaliHwCntrs().countersEnabled()) {
if (!addSource(mali_userspace::createMaliHwCntrSource(senderSem, drivers.getMaliHwCntrs()))) {
Expand Down Expand Up @@ -518,9 +560,9 @@ void Child::durationThreadEntryPoint(const lib::Waiter & waitTillStart, const li
namespace {
class StreamlineCommandHandler : public IStreamlineCommandHandler {
public:
StreamlineCommandHandler(Sender & sender) : sender(sender) {}
explicit StreamlineCommandHandler(Sender & sender) : sender(sender) {}

State handleRequest(char *) override
State handleRequest(char * /* unused */) override
{
LOG_DEBUG("INVESTIGATE: Received unknown command type COMMAND_REQUEST_XML");
return State::PROCESS_COMMANDS;
Expand Down
9 changes: 6 additions & 3 deletions daemon/Child.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ class Child {
std::set<SpeConfiguration> spes;
};

static std::unique_ptr<Child> createLocal(agents::i_agent_spawner_t & spawner,
static std::unique_ptr<Child> createLocal(agents::i_agent_spawner_t & hi_priv_spawner,
agents::i_agent_spawner_t & lo_priv_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,
static std::unique_ptr<Child> createLive(agents::i_agent_spawner_t & hi_priv_spawner,
agents::i_agent_spawner_t & lo_priv_spawner,
Drivers & drivers,
OlySocket & sock,
capture::capture_process_event_listener_t & event_listener,
Expand Down Expand Up @@ -92,7 +94,8 @@ class Child {
std::shared_ptr<Command> command {};
agents::agent_workers_process_t<Child> agent_workers_process;

Child(agents::i_agent_spawner_t & spawner,
Child(agents::i_agent_spawner_t & hi_priv_spawner,
agents::i_agent_spawner_t & lo_priv_spawner,
Drivers & drivers,
OlySocket * sock,
Config config,
Expand Down
4 changes: 0 additions & 4 deletions daemon/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
#define CONFIG_SUPPORT_PERF 1
#endif

#ifndef GATORD_BUILD_ID
#define GATORD_BUILD_ID "oss"
#endif

#ifndef GATOR_SELF_PROFILE
#define GATOR_SELF_PROFILE 0
#endif
Expand Down
5 changes: 4 additions & 1 deletion daemon/Counter.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2013-2021 by Arm Limited. All rights reserved. */
/* Copyright (C) 2013-2022 by Arm Limited. All rights reserved. */

#ifndef COUNTER_H
#define COUNTER_H
Expand Down Expand Up @@ -43,6 +43,8 @@ class Counter {
int getCores() const { return mCores; }
int getKey() const { return mKey; }
Driver * getDriver() const { return mDriver; }
void setExcludeFromCapturedXml() { mExcludeFromCapturedXml = true; }
bool excludeFromCapturedXml() const { return mExcludeFromCapturedXml; }

private:
std::string mType {};
Expand All @@ -52,6 +54,7 @@ class Counter {
int mCores {-1};
int mKey {0};
Driver * mDriver {nullptr};
bool mExcludeFromCapturedXml = false;
};

#endif // COUNTER_H
11 changes: 11 additions & 0 deletions daemon/CounterXML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ static mxml_node_t * getTree(bool supportsMultiEbs,
auto setup_message = log_setup_supplier();
mxml_node_t * setup = mxmlNewElement(counters, "setup_warnings");
mxmlNewText(setup, 0, setup_message.c_str());
{
std::ostringstream buffer {};
for (auto const * driver : drivers) {
auto warnings = driver->get_other_warnings();
for (auto const & warning : warnings) {
buffer << warning << "|" << std::endl;
}
}
auto * warning_element = mxmlNewElement(counters, "other_warnings");
mxmlNewText(warning_element, 0, buffer.str().c_str());
}

// always send the cluster information; even on devices where not all the information is available.
for (size_t cluster = 0; cluster < cpuInfo.getClusters().size(); ++cluster) {
Expand Down
7 changes: 6 additions & 1 deletion daemon/DiskIODriver.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2013-2021 by Arm Limited. All rights reserved. */
/* Copyright (C) 2013-2022 by Arm Limited. All rights reserved. */

// Define to get format macros from inttypes.h
#define __STDC_FORMAT_MACROS
Expand Down Expand Up @@ -59,6 +59,11 @@ void DiskIODriver::doRead()
return;
}

constexpr size_t initialMinimum = (1 << 14) + 1;
if (mBuf.ensureCapacity(initialMinimum) != 0) {
LOG_DEBUG("Failed to ensure initial minimum size of %zu bytes for diskstats buffer", initialMinimum);
}

if (!mBuf.read("/proc/diskstats")) {
LOG_ERROR("Unable to read /proc/diskstats");
handleException();
Expand Down
6 changes: 5 additions & 1 deletion daemon/Driver.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2013-2021 by Arm Limited. All rights reserved. */
/* Copyright (C) 2013-2022 by Arm Limited. All rights reserved. */

#ifndef DRIVER_H
#define DRIVER_H
Expand All @@ -10,6 +10,8 @@
#include <cstdint>
#include <optional>
#include <set>
#include <string>
#include <vector>

class Counter;
struct SpeConfiguration;
Expand Down Expand Up @@ -59,6 +61,8 @@ class Driver {
virtual void postChildForkInChild() {}
/// Called in the parent after the gator-child process exits
virtual void postChildExitInParent() {}
//Any warning messages to be displayed in Streamline post analysis of a capture.
virtual std::vector<std::string> get_other_warnings() const { return {}; }

// name pointer is not owned by this so should just be copied
Driver(const Driver &) = default;
Expand Down
Loading

0 comments on commit b6ad117

Please sign in to comment.