Copy as Markdown
Other Tools
// -*- mode: C++ -*-
// AUTOGENERATED BY toolkit/components/gecko_trace/scripts/codegen.py DO NOT EDIT.
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
#ifndef GECKO_TRACE_EVENTS_H
#define GECKO_TRACE_EVENTS_H
#include "mozilla/Maybe.h"
#include "mozilla/gecko_trace/SpanEvent.h"
namespace mozilla::gecko_trace {
/**
* Namespace containing auto-generated event classes for GeckoTrace.
*
* Each event class corresponds to a trace event definition and provides
* a builder-pattern interface for setting attributes before emission.
*/
namespace events {
/**
* Trace event class for "source_located" events.
*
* Base event that adds source-code location capture
*
* Generated from: toolkit/components/gecko-trace/gecko-trace.yaml:11:4
*
* Usage:
* SpanEvent::SourceLocated()
* .WithSourceFile(source.file)
* .WithSourceLine(source.line);
*
* Attributes:
* - source.file (string): Source file where the event was emitted
* - source.line (integer): Line number where the event was emitted
*/
template <class T>
class SourceLocatedEventBase : public virtual SpanEvent {
public:
/**
* Set the source.file attribute for this trace event.
*
* Source file where the event was emitted
*
* @param aSourceFile The source.file value
* (type: std::string_view)
* @return Reference to this event object for method chaining
*/
T& WithSourceFile(std::string_view aSourceFile) {
mSourceFile = mozilla::Some(aSourceFile);
return static_cast<T&>(*this);
}
/**
* Set the source.line attribute for this trace event.
*
* Line number where the event was emitted
*
* @param aSourceLine The source.line value
* (type: int64_t)
* @return Reference to this event object for method chaining
*/
T& WithSourceLine(int64_t aSourceLine) {
mSourceLine = mozilla::Some(aSourceLine);
return static_cast<T&>(*this);
}
bool ForEachKeyValue(
std::function<bool(std::string_view, AttributeValue)> aCallback)
const override {
// Process this event's attributes
if (mSourceFile.isSome() &&
!aCallback("source.file",
AttributeValue(mSourceFile.value()))) {
return false;
}
if (mSourceLine.isSome() &&
!aCallback("source.line",
AttributeValue(mSourceLine.value()))) {
return false;
}
return true;
}
std::string_view GetEventName() const override {
return "source_located";
}
size_t Size() const override {
size_t size = 2;
return size;
}
private:
mozilla::Maybe<std::string_view> mSourceFile;
mozilla::Maybe<int64_t> mSourceLine;
};
class SourceLocatedEvent : public SourceLocatedEventBase<SourceLocatedEvent> { };
} // namespace events
/**
* Namespace containing factory functions for creating trace events.
*
* These functions provide a convenient way to create event objects using
* the builder pattern. Each function returns an event object that can be
* configured with attributes and then emitted.
*
* Example usage:
* SpanEvent::SomeEvent()
* .WithAttribute1(value1)
* .WithAttribute2(value2);
*/
namespace event {
/**
* Create a new source_located trace event.
*
* Base event that adds source-code location capture
*
* @return A new SourceLocatedEvent instance ready for
* configuration
*/
inline events::SourceLocatedEvent SourceLocated() {
return events::SourceLocatedEvent{};
}
} // namespace event
} // namespace mozilla::gecko_trace
#endif // GECKO_TRACE_EVENTS_H