examples/example.stats/plugins/carb.stats/Stats.h

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

// Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION 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