AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
APerformanceFrame.h
1/*
2 * AUI Framework - Declarative UI toolkit for modern C++20
3 * Copyright (C) 2020-2024 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
21#include <chrono>
22#include "AUI/Common/AColor.h"
23#include "AUI/Common/AException.h"
24#include "AUI/Performance/APerformanceSection.h"
25#include "AUI/Traits/values.h"
26
27
33class API_AUI_CORE APerformanceFrame: public aui::noncopyable {
34public:
35 using Consumer = std::function<void(APerformanceSection::Datas sections)>;
36
37#if AUI_PROFILING
38 APerformanceFrame(Consumer consumer);
40#else
41 APerformanceFrame() = default;
42 ~APerformanceFrame() = default;
43#endif
44
45 static APerformanceFrame* current() {
46#if AUI_PROFILING
47 return currentStorage();
48#else
49 throw AException("AUI_PROFILING is disabled");
50#endif
51 }
52
53 void addSection(APerformanceSection::Data section) {
54 mSections << std::move(section);
55 };
56
57 [[nodiscard]]
58 const APerformanceSection::Datas& sections() const noexcept {
59 return mSections;
60 };
61
62private:
64 Consumer mConsumer;
65
66 [[nodiscard]]
67 static APerformanceFrame*& currentStorage() noexcept {
68 thread_local APerformanceFrame* s = nullptr;
69 return s;
70 }
71};
Abstract AUI exception.
Definition: AException.h:29
Defines beginning and ending of window frame by RAII.
Definition: APerformanceFrame.h:33
Definition: APerformanceSection.h:29
Forbids copy of your class.
Definition: values.h:40