Started to add hardware stats reporting functionality.

This commit is contained in:
hiker 2014-09-16 22:02:20 +10:00
parent 8dfe72f73f
commit 9cdbaebd29
8 changed files with 232 additions and 15 deletions

View File

@ -1,5 +1,5 @@
# Modify this file to change the last-modified date when you add/remove a file.
# This will then trigger a new cmake run automatically.
# This will then trigger a new cmake run automatically.
file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp")
file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp")
file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*")

View File

@ -0,0 +1,75 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2014 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "config/hardware_stats.hpp"
#include "config/user_config.hpp"
#include "graphics/glwrap.hpp"
#include "graphics/irr_driver.hpp"
#include "online/http_request.hpp"
#include "utils/string_utils.hpp"
namespace HardwareStats
{
void reportHardwareStats()
{
Json json;
#ifdef WIN32
json.add("os_win", 1);
#endif
#ifdef __APPLE__
json.add("os_macosx", 1);
#endif
#ifdef __linux__
json.add("os_linx", 1);
json.add("os_unix", 1);
#endif
#ifdef DEBUG
json.add("build_debug", 1);
#endif
unsigned int ogl_version = irr_driver->getGLSLVersion();
unsigned int major = ogl_version/100;
unsigned int minor = ogl_version - 100*major;
std::string version =
StringUtils::insertValues("%d.%d", major, minor);
json.add("GL_VERSION", version);
std::string vendor;
irr_driver->getOpenGLData(&vendor);
json.add("GL_VENDOR", vendor);
json.add("video_xres", UserConfigParams::m_width );
json.add("video_yres", UserConfigParams::m_height);
// Too long for debugging atm
//json.add("GL_EXTENSIONS", getGLExtensions());
json.finish();
Log::verbose("json", "'%s'", json.toString().c_str());
Online::HTTPRequest *request = new Online::HTTPRequest(/*manage memory*/true, 1);
request->addParameter("user_id", 3);
request->addParameter("generation_date", StkTime::getTimeSinceEpoch());
request->addParameter("data_type", "hwdetect");
request->addParameter("data_version", 1);
request->addParameter("data", json.toString());
request->setURL("http://stats.supertuxkart.net/upload/v1");
// FIXME: For now: don't submit
//request->queue();
} // reportHardwareStats
} // namespace HardwareStats

View File

@ -0,0 +1,83 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2014 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_HARDWARE_STATS_HPP
#define HEADER_HARDWARE_STATS_HPP
/**
* \defgroup config
*/
#include "utils/no_copy.hpp"
#include "utils/string_utils.hpp"
namespace HardwareStats
{
class Json : public NoCopy
{
private:
std::string m_data;
public:
/** Constructor. */
Json()
{
m_data.reserve(1024);
m_data ="{";
} // Constructor
// --------------------------------------------------------------------
/** Adds a key-value pair to the json string. */
template <typename C>
void add(const std::string &key, const C&value)
{
if(m_data.size()>1) // more than '{'
m_data += ",";
m_data += "\""+key+"\":"+StringUtils::toString(value);
} // add
// --------------------------------------------------------------------
/** Specialisation for adding string values. String values in
* are enclosed in "". */
void add(const std::string &key, const std::string &value)
{
if(m_data.size()>1) // more than '{'
m_data += ",";
m_data += "\""+key+"\":\""+StringUtils::toString(value)+"\"";
} // add
// --------------------------------------------------------------------
/** Specialisation for adding character pointers. String values in
* are enclosed in "". */
void add(const std::string &key, const char *s)
{
if(m_data.size()>1) // more than '{'
m_data += ",";
m_data += "\""+key+"\":\""+StringUtils::toString(s)+"\"";
} // add
// --------------------------------------------------------------------
void finish()
{
m_data += "}";
}
// --------------------------------------------------------------------
/** Returns the json data as one string. */
std::string toString() { return m_data; }
}; // class Json
// ========================================================================
void reportHardwareStats();
}; // HardwareStats
#endif

View File

@ -17,6 +17,7 @@ bool GLContextDebugBit = true;
bool GLContextDebugBit = false;
#endif
#ifdef DEBUG
#if !defined(__APPLE__)
#define ARB_DEBUG_OUTPUT
@ -733,4 +734,32 @@ bool hasGLExtension(const char* extension)
}
}
return false;
}
} // hasGLExtension
// ----------------------------------------------------------------------------
/** Returns a space-separated list of all GL extensions. Used for hardware
* reporting.
*/
const std::string getGLExtensions()
{
std::string result;
if (glGetStringi != NULL)
{
GLint num_extensions = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions);
for (GLint i = 0; i < num_extensions; i++)
{
const char* extension = (const char*)glGetStringi(GL_EXTENSIONS, i);
if(result.size()>0)
result += " ";
result += extension;
}
}
else
{
const char* extensions = (const char*) glGetString(GL_EXTENSIONS);
result = extensions;
}
return result;
} // getGLExtensions

View File

@ -151,5 +151,7 @@ void GL32_draw2DRectangle(irr::video::SColor color, const irr::core::rect<s32>&
const irr::core::rect<s32>* clip = 0);
bool hasGLExtension(const char* extension);
const std::string getGLExtensions();
#endif

View File

@ -465,14 +465,14 @@ void IrrDriver::initDevice()
m_gui_env = m_device->getGUIEnvironment();
m_video_driver = m_device->getVideoDriver();
GLMajorVersion = 2;
GLMinorVersion = 1;
m_gl_major_version = 2;
m_gl_minor_version = 1;
// Call to glGetIntegerv should not be made if --no-graphics is used
if(!ProfileWorld::isNoGraphics())
{
glGetIntegerv(GL_MAJOR_VERSION, &GLMajorVersion);
glGetIntegerv(GL_MINOR_VERSION, &GLMinorVersion);
Log::info("IrrDriver", "OpenGL version: %d.%d", GLMajorVersion, GLMinorVersion);
glGetIntegerv(GL_MAJOR_VERSION, &m_gl_major_version);
glGetIntegerv(GL_MINOR_VERSION, &m_gl_minor_version);
Log::info("IrrDriver", "OpenGL version: %d.%d", m_gl_major_version, m_gl_minor_version);
Log::info("IrrDriver", "OpenGL vendor: %s", glGetString(GL_VENDOR));
Log::info("IrrDriver", "OpenGL renderer: %s", glGetString(GL_RENDERER));
Log::info("IrrDriver", "OpenGL version string: %s", glGetString(GL_VERSION));
@ -482,7 +482,7 @@ void IrrDriver::initDevice()
m_need_srgb_workaround = false;
#ifdef WIN32
// Fix for Intel Sandy Bridge on Windows which supports GL up to 3.1 only
if (strstr((const char *)glGetString(GL_VENDOR), "Intel") != NULL && (GLMajorVersion == 3 && GLMinorVersion == 1))
if (strstr((const char *)glGetString(GL_VENDOR), "Intel") != NULL && (m_gl_major_version == 3 && m_gl_minor_version == 1))
m_need_ubo_workaround = true;
#endif
// Fix for Nvidia and instanced RH
@ -494,9 +494,9 @@ void IrrDriver::initDevice()
m_need_srgb_workaround = true;
}
#ifdef WIN32
m_glsl = (GLMajorVersion > 3 || (GLMajorVersion == 3 && GLMinorVersion >= 3));
m_glsl = (m_gl_major_version > 3 || (m_gl_major_version == 3 && m_gl_minor_version >= 3));
#else
m_glsl = (GLMajorVersion > 3 || (GLMajorVersion == 3 && GLMinorVersion >= 1));
m_glsl = (m_gl_major_version > 3 || (m_gl_major_version == 3 && m_gl_minor_version >= 1));
#endif
initGL();
@ -656,6 +656,26 @@ void IrrDriver::initDevice()
m_pointer_shown = true;
} // initDevice
//-----------------------------------------------------------------------------
void IrrDriver::getOpenGLData(std::string *vendor )
{
*vendor = (char*)(glGetString(GL_VENDOR));
#ifdef XX
m_gl_major_version = 2;
m_gl_minor_version = 1;
// Call to glGetIntegerv should not be made if --no-graphics is used
if(!ProfileWorld::isNoGraphics())
{
glGetIntegerv(GL_MAJOR_VERSION, &m_gl_major_version);
glGetIntegerv(GL_MINOR_VERSION, &m_gl_minor_version);
Log::info("IrrDriver", "OpenGL version: %d.%d", m_gl_major_version, m_gl_minor_version);
Log::info("IrrDriver", "OpenGL vendor: %s", );
Log::info("IrrDriver", "OpenGL renderer: %s", glGetString(GL_RENDERER));
Log::info("IrrDriver", "OpenGL version string: %s", glGetString(GL_VERSION));
#endif
} // getOpenGLData
//-----------------------------------------------------------------------------
void IrrDriver::showPointer()
{

View File

@ -198,7 +198,7 @@ enum TypeRTT
class IrrDriver : public IEventReceiver, public NoCopy
{
private:
int GLMajorVersion, GLMinorVersion;
int m_gl_major_version, m_gl_minor_version;
bool hasVSLayer;
bool hasBaseInstance;
bool hasDrawIndirect;
@ -283,10 +283,10 @@ public:
unsigned getGLSLVersion() const
{
if (GLMajorVersion > 3 || (GLMajorVersion == 3 && GLMinorVersion == 3))
return GLMajorVersion * 100 + GLMinorVersion * 10;
else if (GLMajorVersion == 3)
return 100 + (GLMinorVersion + 3) * 10;
if (m_gl_major_version > 3 || (m_gl_major_version == 3 && m_gl_minor_version == 3))
return m_gl_major_version * 100 + m_gl_minor_version * 10;
else if (m_gl_major_version == 3)
return 100 + (m_gl_minor_version + 3) * 10;
else
return 120;
}
@ -428,6 +428,8 @@ public:
~IrrDriver();
void initDevice();
void reset();
void getOpenGLData(std::string *vendor);
void generateSkyboxCubemap();
void generateDiffuseCoefficients();
void renderSkybox(const scene::ICameraSceneNode *camera);

View File

@ -147,6 +147,7 @@
#include "audio/music_manager.hpp"
#include "audio/sfx_manager.hpp"
#include "challenges/unlock_manager.hpp"
#include "config/hardware_stats.hpp"
#include "config/player_manager.hpp"
#include "config/player_profile.hpp"
#include "config/stk_config.hpp"
@ -1287,6 +1288,11 @@ int main(int argc, char *argv[] )
}
}
if(UserConfigParams::m_internet_status==Online::RequestManager::IPERM_ALLOWED)
{
HardwareStats::reportHardwareStats();
}
if(!UserConfigParams::m_no_start_screen)
{
// If there is a current player, it was saved in the config file,