Stats.h#

Fully qualified name: examples/example.stats/plugins/carb.stats/Stats.h

File members: examples/example.stats/plugins/carb.stats/Stats.h

// SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: LicenseRef-NvidiaProprietary
//
// NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
// property and proprietary rights in and to this material, related
// documentation and any modifications thereto. Any use, reproduction,
// disclosure or distribution of this material and related documentation
// without an express license agreement from NVIDIA CORPORATION or
// its affiliates is strictly prohibited.

#pragma once
#ifndef DOXYGEN_BUILD
#    include <carb/stats/IStats.h>

#    include <carb/thread/SharedMutex.h>

#    include <unordered_map>
#    include <string>
#    include <mutex>

namespace carb
{
namespace stats
{

struct StatRecord
{
    StatId id;
    std::string name;
    std::string description;
    AggregationType aggregationType;
    Value accumulation;
    size_t totalAdded;
    Value value;
};

class StatsImpl
{
public:
    StatsImpl();
    ~StatsImpl();

    StatId addStat(const StatDesc& desc);
    bool removeStat(StatId stat);
    bool addValue(StatId stat, const Value& value);
    bool getValue(StatId stat, StatDesc& value);
    size_t getCount();

    void clear();

private:
    using Table = std::unordered_map<StatId, StatRecord>;

    Table m_table;
    carb::thread::shared_mutex m_mutex;
    StatId m_nextId = StatId(0);
};

} // namespace stats
} // namespace carb
#endif