1// Copyright (C) 2016 Intel Corporation.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qcsvbenchmarklogger_p.h"
5#include "qtestresult_p.h"
6#include "qbenchmark_p.h"
7
8#include <cstdio>
9
10/*! \internal
11 \class QCsvBenchmarkLogger
12 \inmodule QtTest
13
14 QCsvBenchmarkLogger implements a comma-separated value format for benchmarks.
15
16 This is intended to be suitable for import into spreadsheets.
17 It does not print test failures, debug messages, warnings or any other details.
18*/
19
20QCsvBenchmarkLogger::QCsvBenchmarkLogger(const char *filename)
21 : QAbstractTestLogger(filename)
22{
23}
24
25QCsvBenchmarkLogger::~QCsvBenchmarkLogger() = default;
26
27void QCsvBenchmarkLogger::startLogging()
28{
29 // don't print anything
30}
31
32void QCsvBenchmarkLogger::stopLogging()
33{
34 // don't print anything
35}
36
37void QCsvBenchmarkLogger::enterTestFunction(const char *)
38{
39 // don't print anything
40}
41
42void QCsvBenchmarkLogger::leaveTestFunction()
43{
44 // don't print anything
45}
46
47void QCsvBenchmarkLogger::addIncident(QAbstractTestLogger::IncidentTypes, const char *, const char *, int)
48{
49 // don't print anything
50}
51
52void QCsvBenchmarkLogger::addBenchmarkResult(const QBenchmarkResult &result)
53{
54 const char *fn = QTestResult::currentTestFunction() ? QTestResult::currentTestFunction()
55 : "UnknownTestFunc";
56 const char *tag = QTestResult::currentDataTag() ? QTestResult::currentDataTag() : "";
57 const char *gtag = QTestResult::currentGlobalDataTag()
58 ? QTestResult::currentGlobalDataTag()
59 : "";
60 const char *filler = (tag[0] && gtag[0]) ? ":" : "";
61
62 const char *metric = QTest::benchmarkMetricName(metric: result.measurement.metric);
63
64 char buf[1024];
65 // "function","[globaltag:]tag","metric",value_per_iteration,total,iterations
66 std::snprintf(s: buf, maxlen: sizeof(buf), format: "\"%s\",\"%s%s%s\",\"%s\",%.13g,%.13g,%u\n",
67 fn, gtag, filler, tag, metric,
68 result.measurement.value / result.iterations,
69 result.measurement.value, result.iterations);
70 outputString(msg: buf);
71}
72
73void QCsvBenchmarkLogger::addMessage(QAbstractTestLogger::MessageTypes, const QString &, const char *, int)
74{
75 // don't print anything
76}
77

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qtbase/src/testlib/qcsvbenchmarklogger.cpp