include/tenzr/txpr/tracer.h¶
Namespaces¶
| Name |
|---|
| tenzr |
| tenzr::txpr |
Classes¶
| Name | |
|---|---|
| class | tenzr::txpr::TracerContext Per-thread stack of active tracing targets; traced operations append to the innermost active Txpr. |
| class | tenzr::txpr::TracerScope RAII guard that pushes a Txpr as the active tracing target and pops it on destruction. |
Source code¶
// Copyright 2026 The Tenzr Project Authors
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef TENZR_TXPR_TRACER_H_
#define TENZR_TXPR_TRACER_H_
#include <concepts>
#include <functional>
#include <memory>
#include <utility>
#include <vector>
#include "tenzr/common/error.h"
#include "tenzr/txpr/txpr.h"
namespace tenzr::txpr {
class TracerContext {
public:
[[nodiscard]] static bool IsActive() noexcept;
[[nodiscard]] static Txpr* CurrentTxpr() noexcept;
[[nodiscard]] static Txpr* CurrentTape() noexcept { return CurrentTxpr(); }
static void PushTxpr(Txpr* txpr);
static void PopTxpr();
static void PushTape(Txpr* txpr) { PushTxpr(txpr); }
static void PopTape() { PopTxpr(); }
private:
static std::vector<Txpr*>& TxprStack();
};
class TracerScope {
public:
explicit TracerScope(Txpr& txpr) { TracerContext::PushTxpr(&txpr); }
~TracerScope() { TracerContext::PopTxpr(); }
TracerScope(const TracerScope&) = delete;
TracerScope& operator=(const TracerScope&) = delete;
TracerScope(TracerScope&&) = delete;
TracerScope& operator=(TracerScope&&) = delete;
};
} // namespace tenzr::txpr
namespace tenzr {
using txpr::TracerContext;
using txpr::TracerScope;
} // namespace tenzr
#endif // TENZR_TXPR_TRACER_H_