cutelyst 4.3.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
stats.cpp
1/*
2 * SPDX-FileCopyrightText: (C) 2015-2022 Daniel Nicoletti <dantti12@gmail.com>
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5#include "application.h"
6#include "common.h"
7#include "dispatchtype.h"
8#include "enginerequest.h"
9#include "stats_p.h"
10#include "utils.h"
11
12#include <QtCore/QStringList>
13
14using namespace Cutelyst;
15
17 : d_ptr(new StatsPrivate)
18{
19 Q_D(Stats);
20 d->engineRequest = request;
21}
22
23Stats::~Stats()
24{
25 delete d_ptr;
26}
27
28void Stats::profileStart(const QString &action)
29{
30 Q_D(Stats);
31 StatsAction stat;
32 stat.action = action;
33 stat.begin = std::chrono::steady_clock::now();
34 d->actions.push_back(stat);
35}
36
37void Stats::profileEnd(const QString &action)
38{
39 Q_D(Stats);
40 for (auto &stat : d->actions) {
41 if (stat.action == action) {
42 stat.end = std::chrono::steady_clock::now();
43 break;
44 }
45 }
46}
47
49{
50 Q_D(const Stats);
51
52 QByteArray ret;
53 if (d->actions.size() == 0) {
54 return ret;
55 }
56
58 for (const auto &stat : d->actions) {
59 const std::chrono::duration<double> duration = stat.end - stat.begin;
60 table.append({stat.action, QString::number(duration.count(), 'f') + QLatin1Char('s')});
61 }
62
63 ret = Utils::buildTable(table, {QStringLiteral("Action"), QStringLiteral("Time")});
64 return ret;
65}
virtual void profileEnd(const QString &action)
Definition stats.cpp:37
virtual QByteArray report()
Definition stats.cpp:48
virtual void profileStart(const QString &action)
Definition stats.cpp:28
Stats(EngineRequest *request)
Definition stats.cpp:16
The Cutelyst namespace holds all public Cutelyst API.
void append(QList::parameter_type value)
QList::iterator end()
QString::iterator begin()
QString number(double n, char format, int precision)