File: log.cpp

package info (click to toggle)
wxwidgets3.0 3.0.5.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 120,464 kB
  • sloc: cpp: 896,633; makefile: 52,303; ansic: 21,971; sh: 5,713; python: 2,940; xml: 1,534; perl: 264; javascript: 33
file content (108 lines) | stat: -rw-r--r-- 2,216 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/////////////////////////////////////////////////////////////////////////////
// Name:        tests/benchmarks/log.cpp
// Purpose:     Log-related benchmarks
// Author:      Vadim Zeitlin
// Created:     2012-01-21
// Copyright:   (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

#include "bench.h"

#include "wx/log.h"

// This class is used to check that the arguments of log functions are not
// evaluated.
struct NotCreated
{
    NotCreated() { wxAbort(); }

    const char* AsStr() const { return "unreachable"; }
};

// Temporarily change the log level to the given one.
class LogLevelSetter
{
public:
    LogLevelSetter(wxLogLevel levelNew)
        : m_levelOld(wxLog::GetLogLevel())
    {
        wxLog::SetLogLevel(levelNew);
    }

    ~LogLevelSetter()
    {
        wxLog::SetLogLevel(m_levelOld);
    }

private:
    const wxLogLevel m_levelOld;

    wxDECLARE_NO_COPY_CLASS(LogLevelSetter);
};

BENCHMARK_FUNC(LogDebugDisabled)
{
    LogLevelSetter level(wxLOG_Info);

    wxLogDebug("Ignored debug message: %s", NotCreated().AsStr());

    return true;
}

BENCHMARK_FUNC(LogTraceDisabled)
{
    LogLevelSetter level(wxLOG_Info);

    wxLogTrace("", NotCreated().AsStr());

    return true;
}

BENCHMARK_FUNC(LogTraceActive)
{
    static bool s_added = false;
    if ( !s_added )
    {
        s_added = true;
        wxLog::AddTraceMask("logbench");
    }

    // Remove the actual logging overhead by simply throwing away the log
    // messages.
    class NulLog : public wxLog
    {
    public:
        NulLog()
            : m_logOld(wxLog::SetActiveTarget(this))
        {
        }

        virtual ~NulLog()
        {
            wxLog::SetActiveTarget(m_logOld);
        }

    protected:
        virtual void DoLogRecord(wxLogLevel,
                                 const wxString&,
                                 const wxLogRecordInfo&)
        {
        }

        wxLog* m_logOld;
    };

    NulLog nulLog;

    wxLogTrace("logbench", "Trace message");

    return true;
}

BENCHMARK_FUNC(LogTraceInactive)
{
    wxLogTrace("bloordyblop", "Trace message");

    return true;
}