Skip to content

Commit

Permalink
logging: add AQ_TRACE for omitting trace logs
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Jul 2, 2024
1 parent 8741839 commit 2f220d9
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 41 deletions.
5 changes: 3 additions & 2 deletions src/allocator/GBM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <aquamarine/backend/Backend.hpp>
#include <aquamarine/allocator/Swapchain.hpp>
#include "FormatUtils.hpp"
#include "Shared.hpp"
#include <xf86drm.h>
#include <gbm.h>

Expand Down Expand Up @@ -105,9 +106,9 @@ Aquamarine::CGBMBuffer::CGBMBuffer(const SAllocatorBufferParams& params, Hypruti
allocator->backend->log(AQ_LOG_WARNING, "GBM: Using modifier-less allocation");
bo = gbm_bo_create(allocator->gbmDevice, params.size.x, params.size.y, params.format, flags);
} else {
allocator->backend->log(AQ_LOG_TRACE, std::format("GBM: Using modifier-based allocation, modifiers: {}", explicitModifiers.size()));
TRACE(allocator->backend->log(AQ_LOG_TRACE, std::format("GBM: Using modifier-based allocation, modifiers: {}", explicitModifiers.size())));
for (auto& mod : explicitModifiers) {
allocator->backend->log(AQ_LOG_TRACE, std::format("GBM: | mod 0x{:x}", mod));
TRACE(allocator->backend->log(AQ_LOG_TRACE, std::format("GBM: | mod 0x{:x}", mod)));
}
bo = gbm_bo_create_with_modifiers(allocator->gbmDevice, params.size.x, params.size.y, params.format, explicitModifiers.data(), explicitModifiers.size());

Expand Down
12 changes: 6 additions & 6 deletions src/backend/Wayland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,26 @@ bool Aquamarine::CWaylandBackend::start() {
backend->log(AQ_LOG_DEBUG, std::format("Got registry at 0x{:x}", (uintptr_t)waylandState.registry->resource()));

waylandState.registry->setGlobal([this](CCWlRegistry* r, uint32_t id, const char* name, uint32_t version) {
backend->log(AQ_LOG_TRACE, std::format(" | received global: {} (version {}) with id {}", name, version, id));
TRACE(backend->log(AQ_LOG_TRACE, std::format(" | received global: {} (version {}) with id {}", name, version, id)));

const std::string NAME = name;

if (NAME == "wl_seat") {
backend->log(AQ_LOG_TRACE, std::format(" > binding to global: {} (version {}) with id {}", name, 9, id));
TRACE(backend->log(AQ_LOG_TRACE, std::format(" > binding to global: {} (version {}) with id {}", name, 9, id)));
waylandState.seat = makeShared<CCWlSeat>((wl_proxy*)wl_registry_bind((wl_registry*)waylandState.registry->resource(), id, &wl_seat_interface, 9));
initSeat();
} else if (NAME == "xdg_wm_base") {
backend->log(AQ_LOG_TRACE, std::format(" > binding to global: {} (version {}) with id {}", name, 6, id));
TRACE(backend->log(AQ_LOG_TRACE, std::format(" > binding to global: {} (version {}) with id {}", name, 6, id)));
waylandState.xdg = makeShared<CCXdgWmBase>((wl_proxy*)wl_registry_bind((wl_registry*)waylandState.registry->resource(), id, &xdg_wm_base_interface, 6));
initShell();
} else if (NAME == "wl_compositor") {
backend->log(AQ_LOG_TRACE, std::format(" > binding to global: {} (version {}) with id {}", name, 6, id));
TRACE(backend->log(AQ_LOG_TRACE, std::format(" > binding to global: {} (version {}) with id {}", name, 6, id)));
waylandState.compositor = makeShared<CCWlCompositor>((wl_proxy*)wl_registry_bind((wl_registry*)waylandState.registry->resource(), id, &wl_compositor_interface, 6));
} else if (NAME == "wl_shm") {
backend->log(AQ_LOG_TRACE, std::format(" > binding to global: {} (version {}) with id {}", name, 1, id));
TRACE(backend->log(AQ_LOG_TRACE, std::format(" > binding to global: {} (version {}) with id {}", name, 1, id)));
waylandState.shm = makeShared<CCWlShm>((wl_proxy*)wl_registry_bind((wl_registry*)waylandState.registry->resource(), id, &wl_shm_interface, 1));
} else if (NAME == "zwp_linux_dmabuf_v1") {
backend->log(AQ_LOG_TRACE, std::format(" > binding to global: {} (version {}) with id {}", name, 5, id));
TRACE(backend->log(AQ_LOG_TRACE, std::format(" > binding to global: {} (version {}) with id {}", name, 5, id)));
waylandState.dmabuf =
makeShared<CCZwpLinuxDmabufV1>((wl_proxy*)wl_registry_bind((wl_registry*)waylandState.registry->resource(), id, &zwp_linux_dmabuf_v1_interface, 5));
if (!initDmabuf()) {
Expand Down
38 changes: 19 additions & 19 deletions src/backend/drm/DRM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ static void handlePF(int fd, unsigned seq, unsigned tv_sec, unsigned tv_usec, un

const auto& BACKEND = pageFlip->connector->backend;

BACKEND->log(AQ_LOG_TRACE, std::format("drm: pf event seq {} sec {} usec {} crtc {}", seq, tv_sec, tv_usec, crtc_id));
TRACE(BACKEND->log(AQ_LOG_TRACE, std::format("drm: pf event seq {} sec {} usec {} crtc {}", seq, tv_sec, tv_usec, crtc_id)));

if (pageFlip->connector->status != DRM_MODE_CONNECTED || !pageFlip->connector->crtc) {
BACKEND->log(AQ_LOG_DEBUG, "drm: Ignoring a pf event from a disabled crtc / connector");
Expand Down Expand Up @@ -612,7 +612,7 @@ std::vector<SDRMFormat> Aquamarine::CDRMBackend::getRenderFormats() {
continue;

if (primary) {
backend->log(AQ_LOG_TRACE, std::format("drm: getRenderFormats on secondary {}", gpu->path));
TRACE(backend->log(AQ_LOG_TRACE, std::format("drm: getRenderFormats on secondary {}", gpu->path)));

// this is a secondary GPU renderer. In order to receive buffers,
// we'll force linear modifiers.
Expand All @@ -636,7 +636,7 @@ std::vector<SDRMFormat> Aquamarine::CDRMBackend::getCursorFormats() {
continue;

if (primary) {
backend->log(AQ_LOG_TRACE, std::format("drm: getCursorFormats on secondary {}", gpu->path));
TRACE(backend->log(AQ_LOG_TRACE, std::format("drm: getCursorFormats on secondary {}", gpu->path)));

// this is a secondary GPU renderer. In order to receive buffers,
// we'll force linear modifiers.
Expand Down Expand Up @@ -679,7 +679,7 @@ bool Aquamarine::SDRMPlane::init(drmModePlane* plane) {
else
formats.emplace_back(SDRMFormat{.drmFormat = plane->formats[i], .modifiers = {DRM_FORMAT_MOD_LINEAR}});

backend->backend->log(AQ_LOG_TRACE, std::format("drm: | Format {}", fourccToName(plane->formats[i])));
TRACE(backend->backend->log(AQ_LOG_TRACE, std::format("drm: | Format {}", fourccToName(plane->formats[i]))));
}

if (props.in_formats && backend->drmProps.supportsAddFb2Modifiers) {
Expand All @@ -701,7 +701,7 @@ bool Aquamarine::SDRMPlane::init(drmModePlane* plane) {
while (drmModeFormatModifierBlobIterNext(blob, &iter)) {
auto it = std::find_if(formats.begin(), formats.end(), [iter](const auto& e) { return e.drmFormat == iter.fmt; });

backend->backend->log(AQ_LOG_TRACE, std::format("drm: | Modifier {} with format {}", iter.mod, fourccToName(iter.fmt)));
TRACE(backend->backend->log(AQ_LOG_TRACE, std::format("drm: | Modifier {} with format {}", iter.mod, fourccToName(iter.fmt))));

if (it == formats.end())
formats.emplace_back(SDRMFormat{.drmFormat = iter.fmt, .modifiers = {iter.mod}});
Expand Down Expand Up @@ -735,15 +735,15 @@ bool Aquamarine::SDRMPlane::init(drmModePlane* plane) {
SP<SDRMCRTC> Aquamarine::SDRMConnector::getCurrentCRTC(const drmModeConnector* connector) {
uint32_t crtcID = 0;
if (props.crtc_id) {
backend->backend->log(AQ_LOG_TRACE, "drm: Using crtc_id for finding crtc");
TRACE(backend->backend->log(AQ_LOG_TRACE, "drm: Using crtc_id for finding crtc"));
uint64_t value = 0;
if (!getDRMProp(backend->gpu->fd, id, props.crtc_id, &value)) {
backend->backend->log(AQ_LOG_ERROR, "drm: Failed to get CRTC_ID");
return nullptr;
}
crtcID = static_cast<uint32_t>(value);
} else if (connector->encoder_id) {
backend->backend->log(AQ_LOG_TRACE, "drm: Using encoder_id for finding crtc");
TRACE(backend->backend->log(AQ_LOG_TRACE, "drm: Using encoder_id for finding crtc"));
auto encoder = drmModeGetEncoder(backend->gpu->fd, connector->encoder_id);
if (!encoder) {
backend->backend->log(AQ_LOG_ERROR, "drm: drmModeGetEncoder failed");
Expand Down Expand Up @@ -1085,7 +1085,7 @@ bool Aquamarine::CDRMOutput::commitState(bool onlyTest) {
}

if ((COMMITTED & COutputState::eOutputStateProperties::AQ_OUTPUT_STATE_BUFFER) && STATE.buffer->attachments.has(AQ_ATTACHMENT_DRM_KMS_UNIMPORTABLE)) {
backend->backend->log(AQ_LOG_TRACE, "drm: Cannot commit a KMS-unimportable buffer.");
TRACE(backend->backend->log(AQ_LOG_TRACE, "drm: Cannot commit a KMS-unimportable buffer."));
return false;
}

Expand Down Expand Up @@ -1124,7 +1124,7 @@ bool Aquamarine::CDRMOutput::commitState(bool onlyTest) {
SDRMConnectorCommitData data;

if (STATE.buffer) {
backend->backend->log(AQ_LOG_TRACE, "drm: Committed a buffer, updating state");
TRACE(backend->backend->log(AQ_LOG_TRACE, "drm: Committed a buffer, updating state"));

SP<CDRMFB> drmFB;
auto buf = STATE.buffer;
Expand Down Expand Up @@ -1156,7 +1156,7 @@ bool Aquamarine::CDRMOutput::commitState(bool onlyTest) {
// TODO: add an API to detect this and request drm_dumb linear buffers. Or do something,
// idk
if (data.cursorFB->buffer->dmabuf().modifier == DRM_FORMAT_MOD_INVALID) {
backend->backend->log(AQ_LOG_TRACE, "drm: Dropping invalid buffer for cursor plane");
TRACE(backend->backend->log(AQ_LOG_TRACE, "drm: Dropping invalid buffer for cursor plane"));
data.cursorFB = nullptr;
}
}
Expand Down Expand Up @@ -1266,7 +1266,7 @@ SP<CDRMFB> Aquamarine::CDRMFB::create(SP<IBuffer> buffer_, Hyprutils::Memory::CW
if (buffer_->attachments.has(AQ_ATTACHMENT_DRM_BUFFER)) {
auto at = (CDRMBufferAttachment*)buffer_->attachments.get(AQ_ATTACHMENT_DRM_BUFFER).get();
fb = at->fb;
backend_->log(AQ_LOG_TRACE, std::format("drm: CDRMFB: buffer has drmfb attachment with fb {:x}", (uintptr_t)fb.get()));
TRACE(backend_->log(AQ_LOG_TRACE, std::format("drm: CDRMFB: buffer has drmfb attachment with fb {:x}", (uintptr_t)fb.get())));
}

if (fb) {
Expand Down Expand Up @@ -1311,7 +1311,7 @@ void Aquamarine::CDRMFB::import() {
return;
}

backend->backend->log(AQ_LOG_TRACE, std::format("drm: CDRMFB: plane {} has fd {}, got handle {}", i, attrs.fds.at(i), boHandles.at(i)));
TRACE(backend->backend->log(AQ_LOG_TRACE, std::format("drm: CDRMFB: plane {} has fd {}, got handle {}", i, attrs.fds.at(i), boHandles.at(i))));
}

id = submitBuffer();
Expand All @@ -1322,7 +1322,7 @@ void Aquamarine::CDRMFB::import() {
return;
}

backend->backend->log(AQ_LOG_TRACE, std::format("drm: new buffer {}", id));
TRACE(backend->backend->log(AQ_LOG_TRACE, std::format("drm: new buffer {}", id)));

// FIXME: why does this implode when it doesnt on wlroots or kwin?
// closeHandles();
Expand Down Expand Up @@ -1379,7 +1379,7 @@ void Aquamarine::CDRMFB::drop() {

closeHandles();

backend->backend->log(AQ_LOG_TRACE, std::format("drm: dropping buffer {}", id));
TRACE(backend->backend->log(AQ_LOG_TRACE, std::format("drm: dropping buffer {}", id)));

int ret = drmModeCloseFB(backend->gpu->fd, id);
if (ret == -EINVAL)
Expand All @@ -1398,9 +1398,9 @@ uint32_t Aquamarine::CDRMFB::submitBuffer() {
}

if (backend->drmProps.supportsAddFb2Modifiers && attrs.modifier != DRM_FORMAT_MOD_INVALID) {
backend->backend->log(AQ_LOG_TRACE,
std::format("drm: Using drmModeAddFB2WithModifiers to import buffer into KMS: Size {} with format {} and mod {}", attrs.size,
fourccToName(attrs.format), attrs.modifier));
TRACE(backend->backend->log(AQ_LOG_TRACE,
std::format("drm: Using drmModeAddFB2WithModifiers to import buffer into KMS: Size {} with format {} and mod {}", attrs.size,
fourccToName(attrs.format), attrs.modifier)));
if (drmModeAddFB2WithModifiers(backend->gpu->fd, attrs.size.x, attrs.size.y, attrs.format, boHandles.data(), attrs.strides.data(), attrs.offsets.data(), mods.data(),
&newID, DRM_MODE_FB_MODIFIERS)) {
backend->backend->log(AQ_LOG_ERROR, "drm: Failed to submit a buffer with drmModeAddFB2WithModifiers");
Expand All @@ -1412,9 +1412,9 @@ uint32_t Aquamarine::CDRMFB::submitBuffer() {
return 0;
}

backend->backend->log(
TRACE(backend->backend->log(
AQ_LOG_TRACE,
std::format("drm: Using drmModeAddFB2 to import buffer into KMS: Size {} with format {} and mod {}", attrs.size, fourccToName(attrs.format), attrs.modifier));
std::format("drm: Using drmModeAddFB2 to import buffer into KMS: Size {} with format {} and mod {}", attrs.size, fourccToName(attrs.format), attrs.modifier)));

if (drmModeAddFB2(backend->gpu->fd, attrs.size.x, attrs.size.y, attrs.format, boHandles.data(), attrs.strides.data(), attrs.offsets.data(), &newID, 0)) {
backend->backend->log(AQ_LOG_ERROR, "drm: Failed to submit a buffer with drmModeAddFB2");
Expand Down
25 changes: 13 additions & 12 deletions src/backend/drm/impl/Atomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <xf86drm.h>
#include <xf86drmMode.h>
#include <sys/mman.h>
#include "Shared.hpp"

using namespace Aquamarine;
using namespace Hyprutils::Memory;
Expand All @@ -24,7 +25,7 @@ void Aquamarine::CDRMAtomicRequest::add(uint32_t id, uint32_t prop, uint64_t val
if (failed)
return;

backend->log(AQ_LOG_TRACE, std::format("atomic drm request: adding id {} prop {} with value {}", id, prop, val));
TRACE(backend->log(AQ_LOG_TRACE, std::format("atomic drm request: adding id {} prop {} with value {}", id, prop, val)));

if (id == 0 || prop == 0) {
backend->log(AQ_LOG_ERROR, "atomic drm request: failed to add prop: id / prop == 0");
Expand All @@ -45,18 +46,18 @@ void Aquamarine::CDRMAtomicRequest::planeProps(Hyprutils::Memory::CSharedPointer

if (!fb || !crtc) {
// Disable the plane
backend->log(AQ_LOG_TRACE, std::format("atomic planeProps: disabling plane {}", plane->id));
TRACE(backend->log(AQ_LOG_TRACE, std::format("atomic planeProps: disabling plane {}", plane->id)));
add(plane->id, plane->props.fb_id, 0);
add(plane->id, plane->props.crtc_id, 0);
add(plane->id, plane->props.crtc_x, (uint64_t)pos.x);
add(plane->id, plane->props.crtc_y, (uint64_t)pos.y);
return;
}

backend->log(AQ_LOG_TRACE,
std::format("atomic planeProps: prop blobs: src_x {}, src_y {}, src_w {}, src_h {}, crtc_w {}, crtc_h {}, fb_id {}, crtc_id {}, crtc_x {}, crtc_y {}",
plane->props.src_x, plane->props.src_y, plane->props.src_w, plane->props.src_h, plane->props.crtc_w, plane->props.crtc_h, plane->props.fb_id,
plane->props.crtc_id, plane->props.crtc_x, plane->props.crtc_y));
TRACE(backend->log(AQ_LOG_TRACE,
std::format("atomic planeProps: prop blobs: src_x {}, src_y {}, src_w {}, src_h {}, crtc_w {}, crtc_h {}, fb_id {}, crtc_id {}, crtc_x {}, crtc_y {}",
plane->props.src_x, plane->props.src_y, plane->props.src_w, plane->props.src_h, plane->props.crtc_w, plane->props.crtc_h, plane->props.fb_id,
plane->props.crtc_id, plane->props.crtc_x, plane->props.crtc_y)));

// src_ are 16.16 fixed point (lol)
add(plane->id, plane->props.src_x, 0);
Expand All @@ -75,9 +76,9 @@ void Aquamarine::CDRMAtomicRequest::addConnector(Hyprutils::Memory::CSharedPoint
const auto& STATE = connector->output->state->state();
const bool enable = STATE.enabled && data.mainFB;

backend->log(AQ_LOG_TRACE,
std::format("atomic addConnector blobs: mode_id {}, active {}, crtc_id {}, link_status {}, content_type {}", connector->crtc->props.mode_id,
connector->crtc->props.active, connector->props.crtc_id, connector->props.link_status, connector->props.content_type));
TRACE(backend->log(AQ_LOG_TRACE,
std::format("atomic addConnector blobs: mode_id {}, active {}, crtc_id {}, link_status {}, content_type {}", connector->crtc->props.mode_id,
connector->crtc->props.active, connector->props.crtc_id, connector->props.link_status, connector->props.content_type)));

add(connector->id, connector->props.crtc_id, enable ? connector->crtc->id : 0);

Expand Down Expand Up @@ -221,9 +222,9 @@ bool Aquamarine::CDRMAtomicImpl::prepareConnector(Hyprutils::Memory::CSharedPoin
return false;
}

connector->backend->log(AQ_LOG_TRACE,
std::format("Connector blob id {}: clock {}, {}x{}, vrefresh {}, name: {}", data.atomic.modeBlob, data.modeInfo.clock, data.modeInfo.hdisplay,
data.modeInfo.vdisplay, data.modeInfo.vrefresh, data.modeInfo.name));
TRACE(connector->backend->log(AQ_LOG_TRACE,
std::format("Connector blob id {}: clock {}, {}x{}, vrefresh {}, name: {}", data.atomic.modeBlob, data.modeInfo.clock,
data.modeInfo.hdisplay, data.modeInfo.vdisplay, data.modeInfo.vrefresh, data.modeInfo.name)));
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/include/Shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Aquamarine {
bool envEnabled(const std::string& env);
bool isTrace();
};

#define RASSERT(expr, reason, ...) \
Expand All @@ -17,4 +18,11 @@ namespace Aquamarine {
raise(SIGABRT); \
}

#define ASSERT(expr) RASSERT(expr, "?")
#define ASSERT(expr) RASSERT(expr, "?")

#define TRACE(expr) \
{ \
if (Aquamarine::isTrace()) { \
expr; \
} \
}
10 changes: 9 additions & 1 deletion src/utils/Shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@
bool Aquamarine::envEnabled(const std::string& env) {
auto e = getenv(env.c_str());
return e && e == std::string{"1"};
}
}

static bool trace = []() -> bool {
return Aquamarine::envEnabled("AQ_TRACE");
}();

bool Aquamarine::isTrace() {
return trace;
}

0 comments on commit 2f220d9

Please sign in to comment.