summaryrefslogtreecommitdiffstats
path: root/src/Runtime/Source/Viewer/PerfLog/TCPPerfLogCommon.h
blob: 23bc58f23358b7665f043c41f16265db3ef4e112 (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
/****************************************************************************
**
** 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$
**
****************************************************************************/

//==============================================================================
//	Includes
//==============================================================================
#include <stdio.h>

//==============================================================================
//	Structs
//==============================================================================
typedef struct _SPerfLogData
{
    unsigned long m_Timestamp;
    float m_FPS;
    unsigned long m_GPUMemoryUsage;
    unsigned long m_CPUMemoryUsage;
    float m_CPULoad;
    long m_GPULoad;
    float m_EMCLoad;
    char m_StringData[128];
} SPerfLogData;

typedef struct _SPerfLogDataExtra
{
    float m_MinFPS;
    float m_MaxFPS;
    float m_MinCPULoad;
    float m_MaxCPULoad;
    long m_MinGPULoad;
    long m_MaxGPULoad;
} SPerfLogDataExtra;

//==============================================================================
/**
 *	Formats SPerfLogData into a user readable form.
 */
const char *FormatPerfLogData(const SPerfLogData *inData)
{
    static char theMessageBuffer[256];
    theMessageBuffer[0] = 0;

    static unsigned long thePrevTimestamp = 0;
    static unsigned long theTimestampDiff = 0;
    if (thePrevTimestamp != 0)
        theTimestampDiff = inData->m_Timestamp - thePrevTimestamp;

    ::sprintf(theMessageBuffer, "Timestamp: %lu\tTimediff: %lu\tFPS: %.2f\tUsecase: "
                                "%s\tGPUMemoryUsage: %lu\tCPUMemoryUsage: %lu\tCPULoad: "
                                "%.2f\tGPULoad: %ld\tEMCLoad: %.2f\n",
              inData->m_Timestamp, theTimestampDiff, inData->m_FPS, inData->m_StringData,
              inData->m_GPUMemoryUsage, inData->m_CPUMemoryUsage, inData->m_CPULoad * 100,
              inData->m_GPULoad, inData->m_EMCLoad * 100);

    thePrevTimestamp = inData->m_Timestamp;

    return theMessageBuffer;
}

//==============================================================================
/**
 *	Formats SPerfLogDataExtra into a user readable form.
 */
void FormatPerfLogDataExtra(const SPerfLogData *inData, const SPerfLogDataExtra *inExtraData,
                            char *inMessageBuffer)
{
    ::sprintf(inMessageBuffer, "FPS: %.0f/%.0f/%.0f CPU: %.0f/%.0f/%.0f GPU: %ld/%ld/%ld EMC: %.0f",
              inData->m_FPS, inExtraData->m_MaxFPS, inExtraData->m_MinFPS, inData->m_CPULoad * 100,
              inExtraData->m_MaxCPULoad * 100, inExtraData->m_MinCPULoad * 100, inData->m_GPULoad,
              inExtraData->m_MaxGPULoad, inExtraData->m_MinGPULoad, inData->m_EMCLoad * 100);
}