AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
APerformanceSection.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 Alex2772 and Contributors
    4 *
    5 * SPDX-License-Identifier: MPL-2.0
    6 *
    7 * This Source Code Form is subject to the terms of the Mozilla Public
    8 * License, v. 2.0. If a copy of the MPL was not distributed with this
    9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
   10 */
   11
   12#pragma once
   13
   14#include <chrono>
   15#include <optional>
   16
   17#include "AUI/Common/AColor.h"
   18#include "AUI/Common/AString.h"
   19#include "AUI/Common/AVector.h"
   20
   27class API_AUI_CORE APerformanceSection {
   28public:
   29    struct Data {
   33        const char* name;
   34
   38        AColor color;
   39        std::string verboseInfo;
   40        std::chrono::high_resolution_clock::duration duration = std::chrono::high_resolution_clock::duration(0);
   41        AVector<Data> children;
   42    };
   43
   44    using Datas = AVector<Data>;
   45
   46#if AUI_PROFILING
   55    APerformanceSection(const char* name, AOptional<AColor> color = std::nullopt, std::string verboseInfo = {});
   56    ~APerformanceSection();
   57
   58    void addSection(Data section) {
   59        mChildren << std::move(section);
   60    }
   61
   62#else
   63    // expected to be optimized out
   64
   73    APerformanceSection(const char* name, AOptional<AColor> color = std::nullopt, std::string verboseInfo = {}) {}
   74    ~APerformanceSection() = default;
   75#endif
   76
   77private:
   78#if AUI_PROFILING
   79    static APerformanceSection*& current() noexcept {
   80        thread_local APerformanceSection* v = nullptr;
   81        return v;
   82    }
   83
   84    const char* mName;
   85    AColor mColor;
   86    std::string mVerboseInfo;
   87    std::chrono::high_resolution_clock::time_point mStart;
   88    AVector<Data> mChildren;
   89
   90    APerformanceSection* mParent;
   91
   92    static AColor generateColorFromName(const char* name);
   93#endif
   94};
Represents a 4-component floating point color (RGBA).
Definition AColor.h:26
Utility wrapper implementing the stack-allocated (fast) optional idiom.
Definition AOptional.h:33
Defines performance profiling named (and colored) span within RAII range.
Definition APerformanceSection.h:27
APerformanceSection(const char *name, AOptional< AColor > color=std::nullopt, std::string verboseInfo={})
Defines performance profiling named (and colored) span within RAII range.
Definition APerformanceSection.h:73
A std::vector with AUI extensions.
Definition AVector.h:39
Definition APerformanceSection.h:29
AColor color
Color of the section.
Definition APerformanceSection.h:38
const char * name
Name of the section. Expected to be alive whole program lifetime.
Definition APerformanceSection.h:33