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