summaryrefslogtreecommitdiff
path: root/indra/newview/lltelemetry.cpp
blob: 0c63e2fede5d45b4b56949d9399d812a98c166f4 (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
 /**
 * @file lltelemetry.cpp
 * @brief Wrapper for Rad Game Tools Telemetry
 *
 * $LicenseInfo:firstyear=2020&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2020, Linden Research, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#include "llviewerprecompiledheaders.h"

#include "lltelemetry.h"

#if LLPROFILE_USE_RAD_TELEMETRY_PROFILER
    #if LL_WINDOWS
        #include "llwin32headers.h"

        // build-vc120-64\packages\lib\release
        // build-vc150-64\packages\lib\release
        #ifdef _MSC_VER
            #pragma comment(lib,"rad_tm_win64.lib")
        #else
            #pragma message "NOTE: Rad GameTools Telemetry requested but non-MSVC compiler not yet supported on Windows"
        #endif
    #endif // LL_WINDOWS

    #if LL_DARWIN
        #pragma message "NOTE: Rad Game Tools Telemetry requested but not yet supported on Darwin"
    #endif

    #if LL_LINUX
        #pragma message "NOTE: Rad Game Tools Telemetry requested but not yet supported on Linux"
    #endif

//
// local consts
//
static const tm_int32 TELEMETRY_BUFFER_SIZE  = 8 * 1024 * 1024;

//
// local globals
//
static char *gTelemetryBufferPtr = NULL; // Telemetry

static const char *tm_status[ TMERR_INIT_NETWORKING_FAILED + 1 ] =
{
      "Telemetry pass: connected"                       // TM_OK
    , "Telemetry FAIL: disabled via #define NTELEMETRY" // TMERR_DISABLED
    , "Telemetry FAIL: invalid paramater"               // TMERR_INVALID_PARAM
    , "Telemetry FAIL: DLL not found"                   // TMERR_NULL_API
    , "Telemetry FAIL: out of resources"                // TMERR_OUT_OF_RESOURCES
    , "Telemetry FAIL: tmInitialize() not called"       // TMERR_UNINITIALIZED
    , "Telemetry FAIL: bad hostname"                    // TMERR_BAD_HOSTNAME
    , "Telemetry FAIL: couldn't connect to server"      // TMERR_COULD_NOT_CONNECT
    , "Telemetry FAIL: unknown network error"           // TMERR_UNKNOWN_NETWORK
    , "Telemetry FAIL: tmShutdown() already called"     // TMERR_ALREADY_SHUTDOWN
    , "Telemetry FAIL: memory buffer too small"         // TMERR_ARENA_TOO_SMALL
    , "Telemetry FAIL: server handshake error"          // TMERR_BAD_HANDSHAKE
    , "Telemetry FAIL: unaligned parameters"            // TMERR_UNALIGNED
    , "Telemetry FAIL: network not initialized"         // TMERR_NETWORK_NOT_INITIALIZED -- WSAStartup not called before tmOpen()
    , "Telemetry FAIL: bad version"                     // TMERR_BAD_VERSION
    , "Telemetry FAIL: timer too large"                 // TMERR_BAD_TIMER
    , "Telemetry FAIL: tmOpen() already called"         // TMERR_ALREADY_OPENED
    , "Telemetry FAIL: tmInitialize() already called"   // TMERR_ALREADY_INITIALIZED
    , "Telemetry FAIL: could't open file"               // TMERR_FILE_OPEN_FAILED
    , "Telemetry FAIL: tmOpen() failed networking"      // TMERR_INIT_NETWORKING_FAILED
};

//
// exported functionality
//

void telemetry_shutdown()
{
    #if LL_WINDOWS
        if (gTelemetryBufferPtr)
        {
            tmClose(0);
            tmShutdown();

            delete[] gTelemetryBufferPtr;
            gTelemetryBufferPtr = NULL;
        }
    #endif
}

void telemetry_startup()
{
    #if LL_WINDOWS
        tmLoadLibrary(TM_RELEASE); // Loads .dll

        gTelemetryBufferPtr = new char[ TELEMETRY_BUFFER_SIZE ];
        tmInitialize(TELEMETRY_BUFFER_SIZE, gTelemetryBufferPtr);

        tm_error telemetry_status = tmOpen(
            0,                     // unused
            "SecondLife",          // app name
            __DATE__ " " __TIME__, // build identifier
            "localhost",           // server name (or filename)
            TMCT_TCP,              // connection type (or TMCT_FILE)
            4719,                  // port
            TMOF_INIT_NETWORKING,  // open flags
            250 );                 // timeout ms

        if (telemetry_status == TMERR_UNKNOWN)
        {
            LL_ERRS() << "Telemetry FAIL: unknown error" << LL_ENDL;
        }
        else if (telemetry_status && (telemetry_status <= TMERR_INIT_NETWORKING_FAILED))
        {
            LL_INFOS() << tm_status[ telemetry_status ] << LL_ENDL;
            free(gTelemetryBufferPtr);
            gTelemetryBufferPtr = NULL;
        }
    #endif // LL_WINDOWS
}

// Called after we render a frame
void telemetry_update()
{
    #if LL_WINDOWS
        if (gTelemetryBufferPtr)
        {
            tmTick(0);
        }
    #endif
}
#endif // LLPROFILE_USE_RAD_TELEMETRY_PROFILER