summaryrefslogtreecommitdiffstats
path: root/src/Runtime/Source/system/Qt3DSDataLogger.cpp
blob: 2f45f012703c89d6c3f306d4fb71ba49e5eabe45 (plain)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/****************************************************************************
**
** Copyright (C) 1993-2009 NVIDIA Corporation.
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "SystemPrefix.h"

//==============================================================================
//	Includes
//==============================================================================
#include "Qt3DSDataLogger.h"

//==============================================================================
//	Namespace
//==============================================================================
namespace Q3DStudio {

CDataLogger::SExternalFunctors CDataLogger::m_Functors;
CDataLogger::EDataLoggerLevel CDataLogger::m_LogLevel = CDataLogger::LOG_LEVEL_INVALID;
BOOL CDataLogger::m_Enabled = false;

// Developers - change out the = NULL to = class::LogEntry to log specific stuff.
template <>
TPerfLogGeneralEvent1::TLogEntryInternal TPerfLogGeneralEvent1::m_InternalLogFunc = NULL;
template <>
TPerfLogGeneralEvent2::TLogEntryInternal TPerfLogGeneralEvent2::m_InternalLogFunc = NULL;

template <>
TPerfLogRenderEvent1::TLogEntryInternal TPerfLogRenderEvent1::m_InternalLogFunc = NULL;
template <>
TPerfLogSceneEvent1::TLogEntryInternal TPerfLogSceneEvent1::m_InternalLogFunc = NULL;

template <>
TPerfLogMathEvent1::TLogEntryInternal TPerfLogMathEvent1::m_InternalLogFunc = NULL;
template <>
TPerfLogPresentationEvent1::TLogEntryInternal TPerfLogPresentationEvent1::m_InternalLogFunc = NULL;
template <>
TPerfLogRenderEvent2::TLogEntryInternal TPerfLogRenderEvent2::m_InternalLogFunc = NULL;

//==============================================================================
/**
 *	Set the application supplied functors to use for getting time and handling
 *  the writing out of data
 */
void CDataLogger::SetFunctors(SExternalFunctors inFunctors)
{
    m_Functors = inFunctors;
}

//==============================================================================
/**
*	Call into the specified functors to make stuff happen
*/
void CDataLogger::LogEntry(UINT32 inEntryEnum, BOOL inStartFlag)
{
    if (m_Enabled && m_Functors.m_GetTimeFunc && m_Functors.m_WriteFunc && m_Functors.m_UserData) {
        // Initialize to the correct values
        SPerfLogEntry theEntry(inEntryEnum, inStartFlag,
                               m_Functors.m_GetTimeFunc(m_Functors.m_UserData));
        m_Functors.m_WriteFunc(m_Functors.m_UserData, theEntry);
    }
}

//==============================================================================
/**
*	Enable logging
*/
void CDataLogger::Enable()
{
    SetLogLevel(m_LogLevel);
    m_Enabled = true;
}

//==============================================================================
/**
*	Disable logging
*/
void CDataLogger::Disable()
{
    m_Enabled = false;
}

//==============================================================================
/**
 *	XXX
 */
void CDataLogger::SetLogLevel(EDataLoggerLevel inLogLevel)
{
    switch (inLogLevel) {
    // No logging
    case LOG_LEVEL_NONE:
        TPerfLogGeneralEvent1::Disable();
        TPerfLogGeneralEvent2::Disable();

        TPerfLogRenderEvent1::Disable();
        TPerfLogSceneEvent1::Disable();

        TPerfLogMathEvent1::Disable();
        TPerfLogPresentationEvent1::Disable();
        TPerfLogRenderEvent2::Disable();
        break;

    case LOG_LEVEL_3:
        TPerfLogMathEvent1::Enable();
        TPerfLogPresentationEvent1::Enable();
        TPerfLogRenderEvent2::Enable();

    case LOG_LEVEL_2:
        TPerfLogRenderEvent1::Enable();
        TPerfLogSceneEvent1::Enable();

    case LOG_LEVEL_1:
        TPerfLogGeneralEvent1::Enable();
        TPerfLogGeneralEvent2::Enable();
        break;

    case LOG_LEVEL_INVALID:
    default:
        m_LogLevel = LOG_LEVEL_INVALID;
        return;
        break;
    }
    m_LogLevel = inLogLevel;
}

} // namespace Q3DStudio