2018-10-23 17:44:51 +00:00
|
|
|
#include <algorithm>
|
2018-08-17 15:24:50 +00:00
|
|
|
#include <assert.h>
|
2019-06-17 17:34:48 +00:00
|
|
|
#include <chrono>
|
2018-07-28 16:50:22 +00:00
|
|
|
#include <inttypes.h>
|
2017-09-15 19:25:47 +00:00
|
|
|
#include <imgui.h>
|
2018-08-29 23:31:57 +00:00
|
|
|
#include "imgui_impl_glfw.h"
|
|
|
|
#include "imgui_impl_opengl3.h"
|
2019-06-26 16:41:42 +00:00
|
|
|
#include <mutex>
|
2018-10-23 17:39:09 +00:00
|
|
|
#include <stdint.h>
|
2017-09-15 19:25:47 +00:00
|
|
|
#include <stdio.h>
|
2018-07-15 18:10:34 +00:00
|
|
|
#include <stdlib.h>
|
2018-08-31 17:38:05 +00:00
|
|
|
#include <string>
|
2018-10-23 17:39:09 +00:00
|
|
|
#include <unordered_map>
|
2017-09-15 19:37:28 +00:00
|
|
|
#include <GL/gl3w.h>
|
2017-09-15 19:25:47 +00:00
|
|
|
#include <GLFW/glfw3.h>
|
2017-09-15 19:37:28 +00:00
|
|
|
#include <memory>
|
2017-09-30 12:32:30 +00:00
|
|
|
#include "../nfd/nfd.h"
|
2017-10-18 21:18:32 +00:00
|
|
|
#include <sys/stat.h>
|
2019-06-02 17:39:07 +00:00
|
|
|
#include <locale.h>
|
2017-09-15 19:37:28 +00:00
|
|
|
|
2018-06-28 22:31:05 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
# include <windows.h>
|
2018-07-15 18:10:34 +00:00
|
|
|
# include <shellapi.h>
|
2018-06-28 22:31:05 +00:00
|
|
|
#endif
|
|
|
|
|
2019-06-02 15:51:58 +00:00
|
|
|
#define STB_IMAGE_IMPLEMENTATION
|
|
|
|
#define STBI_ONLY_PNG
|
|
|
|
#include "stb_image.h"
|
|
|
|
|
2019-06-17 17:45:47 +00:00
|
|
|
#include "../../common/TracyProtocol.hpp"
|
2019-06-17 17:34:48 +00:00
|
|
|
#include "../../server/tracy_flat_hash_map.hpp"
|
2018-10-23 17:39:09 +00:00
|
|
|
#include "../../server/tracy_pdqsort.h"
|
2018-04-21 21:19:48 +00:00
|
|
|
#include "../../server/TracyBadVersion.hpp"
|
2017-09-30 14:58:02 +00:00
|
|
|
#include "../../server/TracyFileRead.hpp"
|
2018-08-17 21:08:07 +00:00
|
|
|
#include "../../server/TracyImGui.hpp"
|
2019-06-18 18:51:12 +00:00
|
|
|
#include "../../server/TracyPrint.hpp"
|
2018-08-29 21:22:54 +00:00
|
|
|
#include "../../server/TracyStorage.hpp"
|
2017-09-15 19:37:28 +00:00
|
|
|
#include "../../server/TracyView.hpp"
|
2018-07-28 16:07:55 +00:00
|
|
|
#include "../../server/TracyWorker.hpp"
|
2018-07-29 12:24:24 +00:00
|
|
|
#include "../../server/TracyVersion.hpp"
|
2018-08-17 21:22:13 +00:00
|
|
|
#include "../../server/IconsFontAwesome5.h"
|
2018-07-29 12:24:24 +00:00
|
|
|
|
2018-08-17 19:40:15 +00:00
|
|
|
#include "imgui_freetype.h"
|
2018-07-27 23:03:26 +00:00
|
|
|
#include "Arimo.hpp"
|
2018-08-17 18:57:26 +00:00
|
|
|
#include "Cousine.hpp"
|
2018-08-17 15:56:55 +00:00
|
|
|
#include "FontAwesomeSolid.hpp"
|
2019-06-02 16:03:56 +00:00
|
|
|
#include "icon.hpp"
|
2019-06-26 16:41:42 +00:00
|
|
|
#include "ResolvService.hpp"
|
2018-07-27 23:03:26 +00:00
|
|
|
|
2018-04-14 13:12:16 +00:00
|
|
|
static void glfw_error_callback(int error, const char* description)
|
2017-09-15 19:25:47 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Error %d: %s\n", error, description);
|
|
|
|
}
|
|
|
|
|
2018-08-17 15:19:06 +00:00
|
|
|
static void OpenWebpage( const char* url )
|
2018-07-15 18:10:34 +00:00
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
ShellExecuteA( nullptr, nullptr, url, nullptr, nullptr, 0 );
|
2019-04-04 11:58:13 +00:00
|
|
|
#elif defined __APPLE__
|
|
|
|
char buf[1024];
|
|
|
|
sprintf( buf, "open %s", url );
|
|
|
|
system( buf );
|
2018-07-15 18:10:34 +00:00
|
|
|
#else
|
|
|
|
char buf[1024];
|
|
|
|
sprintf( buf, "xdg-open %s", url );
|
|
|
|
system( buf );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-08-17 15:24:50 +00:00
|
|
|
static GLFWwindow* s_glfwWindow = nullptr;
|
|
|
|
static bool s_customTitle = false;
|
|
|
|
static void SetWindowTitleCallback( const char* title )
|
|
|
|
{
|
|
|
|
assert( s_glfwWindow );
|
|
|
|
glfwSetWindowTitle( s_glfwWindow, title );
|
|
|
|
s_customTitle = true;
|
|
|
|
}
|
|
|
|
|
2018-10-23 17:44:51 +00:00
|
|
|
std::vector<std::unordered_map<std::string, uint64_t>::const_iterator> RebuildConnectionHistory( const std::unordered_map<std::string, uint64_t>& connHistMap )
|
|
|
|
{
|
|
|
|
std::vector<std::unordered_map<std::string, uint64_t>::const_iterator> ret;
|
|
|
|
ret.reserve( connHistMap.size() );
|
|
|
|
for( auto it = connHistMap.begin(); it != connHistMap.end(); ++it )
|
|
|
|
{
|
|
|
|
ret.emplace_back( it );
|
|
|
|
}
|
|
|
|
tracy::pdqsort_branchless( ret.begin(), ret.end(), []( const auto& lhs, const auto& rhs ) { return lhs->second > rhs->second; } );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-06-17 17:34:48 +00:00
|
|
|
struct ClientData
|
|
|
|
{
|
|
|
|
int64_t time;
|
|
|
|
uint32_t protocolVersion;
|
2019-06-18 18:51:12 +00:00
|
|
|
uint32_t activeTime;
|
2019-06-17 17:34:48 +00:00
|
|
|
std::string procName;
|
2019-06-17 17:45:36 +00:00
|
|
|
std::string address;
|
2019-06-17 17:34:48 +00:00
|
|
|
};
|
|
|
|
|
2018-03-24 21:20:06 +00:00
|
|
|
int main( int argc, char** argv )
|
2017-09-15 19:25:47 +00:00
|
|
|
{
|
2019-06-17 17:34:48 +00:00
|
|
|
tracy::flat_hash_map<uint32_t, ClientData> clients;
|
|
|
|
|
2018-03-24 21:20:06 +00:00
|
|
|
std::unique_ptr<tracy::View> view;
|
2019-08-12 10:04:27 +00:00
|
|
|
tracy::BadVersionState badVer;
|
2018-03-24 21:20:06 +00:00
|
|
|
|
|
|
|
if( argc == 2 )
|
|
|
|
{
|
|
|
|
auto f = std::unique_ptr<tracy::FileRead>( tracy::FileRead::Open( argv[1] ) );
|
|
|
|
if( f )
|
|
|
|
{
|
|
|
|
view = std::make_unique<tracy::View>( *f );
|
|
|
|
}
|
|
|
|
}
|
2018-12-20 16:07:15 +00:00
|
|
|
else if( argc == 3 && strcmp( argv[1], "-a" ) == 0 )
|
|
|
|
{
|
|
|
|
view = std::make_unique<tracy::View>( argv[2] );
|
|
|
|
}
|
2018-03-24 21:20:06 +00:00
|
|
|
|
2018-07-29 12:24:24 +00:00
|
|
|
char title[128];
|
2019-02-22 01:41:13 +00:00
|
|
|
sprintf( title, "Tracy Profiler %i.%i.%i", tracy::Version::Major, tracy::Version::Minor, tracy::Version::Patch );
|
2018-07-29 12:24:24 +00:00
|
|
|
|
2018-08-31 17:38:19 +00:00
|
|
|
std::string winPosFile = tracy::GetSavePath( "window.position" );
|
|
|
|
int x = 200, y = 200, w = 1650, h = 960, maximize = 0;
|
|
|
|
{
|
|
|
|
FILE* f = fopen( winPosFile.c_str(), "rb" );
|
|
|
|
if( f )
|
|
|
|
{
|
|
|
|
uint32_t data[5];
|
|
|
|
fread( data, 1, sizeof( data ), f );
|
|
|
|
fclose( f );
|
|
|
|
x = data[0];
|
|
|
|
y = data[1];
|
|
|
|
w = data[2];
|
|
|
|
h = data[3];
|
|
|
|
maximize = data[4];
|
|
|
|
}
|
2019-02-12 00:26:14 +00:00
|
|
|
if( w <= 0 || h <= 0 )
|
2019-02-10 01:11:59 +00:00
|
|
|
{
|
|
|
|
x = 200;
|
|
|
|
y = 200;
|
|
|
|
w = 1650;
|
|
|
|
h = 960;
|
|
|
|
maximize = 0;
|
|
|
|
}
|
2018-08-31 17:38:19 +00:00
|
|
|
}
|
|
|
|
|
2018-10-23 17:39:09 +00:00
|
|
|
std::string connHistFile = tracy::GetSavePath( "connection.history" );
|
|
|
|
std::unordered_map<std::string, uint64_t> connHistMap;
|
|
|
|
std::vector<std::unordered_map<std::string, uint64_t>::const_iterator> connHistVec;
|
|
|
|
{
|
|
|
|
FILE* f = fopen( connHistFile.c_str(), "rb" );
|
|
|
|
if( f )
|
|
|
|
{
|
|
|
|
uint64_t sz;
|
|
|
|
fread( &sz, 1, sizeof( sz ), f );
|
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
uint64_t ssz, cnt;
|
|
|
|
fread( &ssz, 1, sizeof( ssz ), f );
|
|
|
|
assert( ssz < 1024 );
|
|
|
|
char tmp[1024];
|
|
|
|
fread( tmp, 1, ssz, f );
|
|
|
|
fread( &cnt, 1, sizeof( cnt ), f );
|
|
|
|
connHistMap.emplace( std::string( tmp, tmp+ssz ), cnt );
|
|
|
|
}
|
|
|
|
fclose( f );
|
2018-10-23 17:44:51 +00:00
|
|
|
connHistVec = RebuildConnectionHistory( connHistMap );
|
2018-10-23 17:39:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-15 19:25:47 +00:00
|
|
|
// Setup window
|
2018-04-14 13:12:16 +00:00
|
|
|
glfwSetErrorCallback(glfw_error_callback);
|
2018-08-29 23:31:57 +00:00
|
|
|
if( !glfwInit() ) return 1;
|
2018-08-31 17:40:08 +00:00
|
|
|
glfwWindowHint(GLFW_VISIBLE, 0);
|
2017-09-15 19:25:47 +00:00
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
2018-04-14 13:12:16 +00:00
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
2017-09-15 19:25:47 +00:00
|
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
|
|
#if __APPLE__
|
|
|
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
|
|
|
#endif
|
2018-08-31 17:38:19 +00:00
|
|
|
GLFWwindow* window = glfwCreateWindow( w, h, title, NULL, NULL);
|
2018-08-29 23:31:57 +00:00
|
|
|
if( !window ) return 1;
|
2019-06-02 16:03:56 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
GLFWimage icon;
|
|
|
|
icon.pixels = stbi_load_from_memory( (const stbi_uc*)Icon_data, Icon_size, &icon.width, &icon.height, nullptr, 4 );
|
|
|
|
glfwSetWindowIcon( window, 1, &icon );
|
|
|
|
free( icon.pixels );
|
|
|
|
}
|
|
|
|
|
2018-08-31 17:38:19 +00:00
|
|
|
glfwSetWindowPos( window, x, y );
|
2018-08-31 18:05:40 +00:00
|
|
|
#ifdef GLFW_MAXIMIZED
|
2018-08-31 17:38:19 +00:00
|
|
|
if( maximize ) glfwMaximizeWindow( window );
|
2018-08-31 18:05:40 +00:00
|
|
|
#endif
|
2018-08-17 15:24:50 +00:00
|
|
|
s_glfwWindow = window;
|
2017-09-15 19:25:47 +00:00
|
|
|
glfwMakeContextCurrent(window);
|
|
|
|
glfwSwapInterval(1); // Enable vsync
|
|
|
|
gl3wInit();
|
|
|
|
|
2018-06-28 22:31:05 +00:00
|
|
|
float dpiScale = 1.f;
|
|
|
|
#ifdef _WIN32
|
2018-07-13 21:41:38 +00:00
|
|
|
typedef UINT(*GDFS)(void);
|
|
|
|
GDFS getDpiForSystem = nullptr;
|
|
|
|
HMODULE dll = GetModuleHandleW(L"user32.dll");
|
|
|
|
if (dll != INVALID_HANDLE_VALUE)
|
|
|
|
getDpiForSystem = (GDFS)GetProcAddress(dll, "GetDpiForSystem");
|
|
|
|
if (getDpiForSystem)
|
|
|
|
dpiScale = getDpiForSystem() / 96.f;
|
2018-06-28 22:31:05 +00:00
|
|
|
#endif
|
|
|
|
|
2017-09-15 19:25:47 +00:00
|
|
|
// Setup ImGui binding
|
2018-08-29 23:31:57 +00:00
|
|
|
IMGUI_CHECKVERSION();
|
2018-04-14 13:12:16 +00:00
|
|
|
ImGui::CreateContext();
|
2018-08-29 21:22:54 +00:00
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
2018-08-31 17:38:05 +00:00
|
|
|
std::string iniFileName = tracy::GetSavePath( "imgui.ini" );
|
|
|
|
io.IniFilename = iniFileName.c_str();
|
2018-08-30 00:08:08 +00:00
|
|
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
2018-08-29 21:22:54 +00:00
|
|
|
|
2018-08-29 23:31:57 +00:00
|
|
|
ImGui_ImplGlfw_InitForOpenGL( window, true );
|
|
|
|
ImGui_ImplOpenGL3_Init( "#version 150" );
|
2017-09-15 19:25:47 +00:00
|
|
|
|
2018-08-17 15:56:55 +00:00
|
|
|
static const ImWchar rangesBasic[] = {
|
2018-07-27 23:03:26 +00:00
|
|
|
0x0020, 0x00FF, // Basic Latin + Latin Supplement
|
|
|
|
0x03BC, 0x03BC, // micro
|
2019-03-14 00:14:06 +00:00
|
|
|
0x03C3, 0x03C3, // small sigma
|
2018-07-27 23:03:26 +00:00
|
|
|
0,
|
|
|
|
};
|
2018-08-17 15:56:55 +00:00
|
|
|
static const ImWchar rangesIcons[] = {
|
2018-08-17 21:22:13 +00:00
|
|
|
ICON_MIN_FA, ICON_MAX_FA,
|
2018-08-17 15:56:55 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
ImFontConfig configMerge;
|
|
|
|
configMerge.MergeMode = true;
|
2017-09-15 19:25:47 +00:00
|
|
|
|
2018-08-17 15:56:55 +00:00
|
|
|
io.Fonts->AddFontFromMemoryCompressedTTF( tracy::Arimo_compressed_data, tracy::Arimo_compressed_size, 15.0f * dpiScale, nullptr, rangesBasic );
|
2018-08-17 16:45:04 +00:00
|
|
|
io.Fonts->AddFontFromMemoryCompressedTTF( tracy::FontAwesomeSolid_compressed_data, tracy::FontAwesomeSolid_compressed_size, 14.0f * dpiScale, &configMerge, rangesIcons );
|
2018-08-17 18:57:26 +00:00
|
|
|
auto fixedWidth = io.Fonts->AddFontFromMemoryCompressedTTF( tracy::Cousine_compressed_data, tracy::Cousine_compressed_size, 15.0f * dpiScale );
|
2019-02-22 01:44:41 +00:00
|
|
|
auto bigFont = io.Fonts->AddFontFromMemoryCompressedTTF( tracy::Arimo_compressed_data, tracy::Cousine_compressed_size, 20.0f * dpiScale );
|
2019-08-16 14:02:57 +00:00
|
|
|
auto smallFont = io.Fonts->AddFontFromMemoryCompressedTTF( tracy::Arimo_compressed_data, tracy::Cousine_compressed_size, 10.0f * dpiScale );
|
2017-10-18 21:18:32 +00:00
|
|
|
|
2018-08-17 19:40:15 +00:00
|
|
|
ImGuiFreeType::BuildFontAtlas( io.Fonts, ImGuiFreeType::LightHinting );
|
|
|
|
|
2018-01-13 12:59:16 +00:00
|
|
|
ImGui::StyleColorsDark();
|
2018-01-13 13:08:14 +00:00
|
|
|
auto& style = ImGui::GetStyle();
|
2018-08-17 17:06:14 +00:00
|
|
|
style.WindowBorderSize = 1.f * dpiScale;
|
|
|
|
style.FrameBorderSize = 1.f * dpiScale;
|
2019-09-20 22:52:13 +00:00
|
|
|
style.FrameRounding = 5.f;
|
2018-01-13 13:08:14 +00:00
|
|
|
style.Colors[ImGuiCol_ScrollbarBg] = ImVec4( 1, 1, 1, 0.03f );
|
2019-09-20 22:52:13 +00:00
|
|
|
style.ScaleAllSizes( dpiScale );
|
2018-01-13 12:59:16 +00:00
|
|
|
|
2017-09-15 19:25:47 +00:00
|
|
|
ImVec4 clear_color = ImColor(114, 144, 154);
|
|
|
|
|
2017-09-15 19:37:28 +00:00
|
|
|
char addr[1024] = { "127.0.0.1" };
|
|
|
|
|
2018-07-28 16:17:56 +00:00
|
|
|
std::thread loadThread;
|
2019-08-29 16:36:55 +00:00
|
|
|
std::unique_ptr<tracy::UdpListen> broadcastListen;
|
2018-07-28 16:17:56 +00:00
|
|
|
|
2019-07-24 21:54:47 +00:00
|
|
|
enum class ViewShutdown { False, True, Join };
|
|
|
|
ViewShutdown viewShutdown = ViewShutdown::False;
|
|
|
|
|
2019-06-26 16:41:42 +00:00
|
|
|
std::mutex resolvLock;
|
|
|
|
tracy::flat_hash_map<std::string, std::string> resolvMap;
|
|
|
|
ResolvService resolv;
|
|
|
|
|
2018-08-31 17:40:08 +00:00
|
|
|
glfwShowWindow( window );
|
|
|
|
|
2019-03-06 01:49:21 +00:00
|
|
|
double time = 0;
|
2017-09-15 19:25:47 +00:00
|
|
|
// Main loop
|
|
|
|
while (!glfwWindowShouldClose(window))
|
|
|
|
{
|
|
|
|
glfwPollEvents();
|
2018-07-29 20:11:47 +00:00
|
|
|
|
|
|
|
if( glfwGetWindowAttrib( window, GLFW_ICONIFIED ) )
|
|
|
|
{
|
|
|
|
std::this_thread::sleep_for( std::chrono::milliseconds( 50 ) );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-08-17 14:54:56 +00:00
|
|
|
int display_w, display_h;
|
|
|
|
glfwGetFramebufferSize(window, &display_w, &display_h);
|
|
|
|
|
2018-08-29 23:31:57 +00:00
|
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
|
|
ImGui_ImplGlfw_NewFrame();
|
|
|
|
ImGui::NewFrame();
|
2017-09-15 19:25:47 +00:00
|
|
|
|
2017-09-15 19:37:28 +00:00
|
|
|
if( !view )
|
2017-09-15 19:25:47 +00:00
|
|
|
{
|
2018-08-17 15:24:50 +00:00
|
|
|
if( s_customTitle )
|
|
|
|
{
|
|
|
|
s_customTitle = false;
|
|
|
|
glfwSetWindowTitle( window, title );
|
|
|
|
}
|
|
|
|
|
2019-06-18 18:56:42 +00:00
|
|
|
const auto time = std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::system_clock::now().time_since_epoch() ).count();
|
2019-06-17 17:34:48 +00:00
|
|
|
if( !broadcastListen )
|
|
|
|
{
|
2019-08-29 16:36:55 +00:00
|
|
|
broadcastListen = std::make_unique<tracy::UdpListen>();
|
2019-06-18 18:28:03 +00:00
|
|
|
if( !broadcastListen->Listen( 8086 ) )
|
2019-06-17 17:34:48 +00:00
|
|
|
{
|
2019-08-29 16:36:55 +00:00
|
|
|
broadcastListen.reset();
|
2019-06-17 17:34:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tracy::IpAddress addr;
|
2019-06-22 12:08:48 +00:00
|
|
|
size_t len;
|
2019-06-17 17:34:48 +00:00
|
|
|
auto msg = broadcastListen->Read( len, addr );
|
|
|
|
if( msg )
|
|
|
|
{
|
2019-06-18 18:26:40 +00:00
|
|
|
assert( len <= sizeof( tracy::BroadcastMessage ) );
|
|
|
|
tracy::BroadcastMessage bm;
|
|
|
|
memcpy( &bm, msg, len );
|
2019-06-17 17:34:48 +00:00
|
|
|
|
2019-06-18 18:26:40 +00:00
|
|
|
if( bm.broadcastVersion == tracy::BroadcastVersion )
|
2019-06-17 17:34:48 +00:00
|
|
|
{
|
2019-06-18 18:26:40 +00:00
|
|
|
const uint32_t protoVer = bm.protocolVersion;
|
|
|
|
const auto procname = bm.programName;
|
2019-06-18 18:51:12 +00:00
|
|
|
const auto activeTime = bm.activeTime;
|
2019-06-18 18:26:40 +00:00
|
|
|
auto address = addr.GetText();
|
|
|
|
|
2019-06-26 16:41:42 +00:00
|
|
|
const auto ipNumerical = addr.GetNumber();
|
|
|
|
auto it = clients.find( ipNumerical );
|
2019-06-18 18:26:40 +00:00
|
|
|
if( it == clients.end() )
|
|
|
|
{
|
2019-06-26 16:41:42 +00:00
|
|
|
std::string ip( address );
|
|
|
|
resolvLock.lock();
|
|
|
|
if( resolvMap.find( ip ) == resolvMap.end() )
|
|
|
|
{
|
|
|
|
resolvMap.emplace( ip, ip );
|
|
|
|
resolv.Query( ipNumerical, [&resolvMap, &resolvLock, ip] ( std::string&& name ) {
|
|
|
|
std::lock_guard<std::mutex> lock( resolvLock );
|
|
|
|
auto it = resolvMap.find( ip );
|
|
|
|
assert( it != resolvMap.end() );
|
|
|
|
std::swap( it->second, name );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
resolvLock.unlock();
|
|
|
|
clients.emplace( addr.GetNumber(), ClientData { time, protoVer, activeTime, procname, std::move( ip ) } );
|
2019-06-18 18:26:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-18 18:56:42 +00:00
|
|
|
it->second.time = time;
|
2019-06-18 18:51:12 +00:00
|
|
|
it->second.activeTime = activeTime;
|
2019-06-18 18:26:40 +00:00
|
|
|
if( it->second.protocolVersion != protoVer ) it->second.protocolVersion = protoVer;
|
|
|
|
if( strcmp( it->second.procName.c_str(), procname ) != 0 ) it->second.procName = procname;
|
|
|
|
}
|
2019-06-17 17:34:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
auto it = clients.begin();
|
|
|
|
while( it != clients.end() )
|
|
|
|
{
|
2019-06-18 18:56:42 +00:00
|
|
|
const auto diff = time - it->second.time;
|
2019-06-17 22:54:58 +00:00
|
|
|
if( diff > 4000 ) // 4s
|
2019-06-17 17:34:48 +00:00
|
|
|
{
|
|
|
|
it = clients.erase( it );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-02 17:59:31 +00:00
|
|
|
setlocale( LC_NUMERIC, "C" );
|
2019-03-07 00:18:24 +00:00
|
|
|
style.Colors[ImGuiCol_WindowBg] = ImVec4( 0.129f, 0.137f, 0.11f, 1.f );
|
2019-02-22 01:41:13 +00:00
|
|
|
ImGui::Begin( "Get started", nullptr, ImGuiWindowFlags_AlwaysAutoResize );
|
2018-08-17 21:08:07 +00:00
|
|
|
char buf[128];
|
2019-02-22 01:41:13 +00:00
|
|
|
sprintf( buf, "Tracy Profiler %i.%i.%i", tracy::Version::Major, tracy::Version::Minor, tracy::Version::Patch );
|
2019-02-22 01:44:41 +00:00
|
|
|
ImGui::PushFont( bigFont );
|
2018-08-17 21:08:07 +00:00
|
|
|
tracy::TextCentered( buf );
|
2019-02-22 01:44:41 +00:00
|
|
|
ImGui::PopFont();
|
|
|
|
ImGui::Spacing();
|
2019-06-11 00:12:34 +00:00
|
|
|
if( ImGui::Button( ICON_FA_BOOK " Manual" ) )
|
2018-08-03 23:15:56 +00:00
|
|
|
{
|
|
|
|
OpenWebpage( "https://bitbucket.org/wolfpld/tracy/downloads/tracy.pdf" );
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
2019-06-11 00:12:34 +00:00
|
|
|
if( ImGui::Button( ICON_FA_GLOBE_AMERICAS " Web" ) )
|
2018-07-15 18:10:41 +00:00
|
|
|
{
|
|
|
|
OpenWebpage( "https://bitbucket.org/wolfpld/tracy" );
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
2019-06-11 00:12:34 +00:00
|
|
|
if( ImGui::Button( ICON_FA_COMMENT " Chat" ) )
|
|
|
|
{
|
|
|
|
OpenWebpage( "https://discord.gg/pk78auc" );
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
2018-08-17 21:22:13 +00:00
|
|
|
if( ImGui::Button( ICON_FA_VIDEO " Tutorial" ) )
|
2018-07-15 18:10:41 +00:00
|
|
|
{
|
2018-10-09 17:28:24 +00:00
|
|
|
ImGui::OpenPopup( "tutorial" );
|
|
|
|
}
|
|
|
|
if( ImGui::BeginPopup( "tutorial" ) )
|
|
|
|
{
|
|
|
|
if( ImGui::Selectable( ICON_FA_VIDEO " Introduction to the Tracy Profiler" ) )
|
|
|
|
{
|
|
|
|
OpenWebpage( "https://www.youtube.com/watch?v=fB5B46lbapc" );
|
|
|
|
}
|
|
|
|
if( ImGui::Selectable( ICON_FA_VIDEO " New features in Tracy Profiler v0.3" ) )
|
|
|
|
{
|
|
|
|
OpenWebpage( "https://www.youtube.com/watch?v=3SXpDpDh2Uo" );
|
|
|
|
}
|
|
|
|
if( ImGui::Selectable( ICON_FA_VIDEO " New features in Tracy Profiler v0.4" ) )
|
|
|
|
{
|
|
|
|
OpenWebpage( "https://www.youtube.com/watch?v=eAkgkaO8B9o" );
|
|
|
|
}
|
2019-08-10 20:07:14 +00:00
|
|
|
if( ImGui::Selectable( ICON_FA_VIDEO " New features in Tracy Profiler v0.5" ) )
|
|
|
|
{
|
|
|
|
OpenWebpage( "https://www.youtube.com/watch?v=P6E7qLMmzTQ" );
|
|
|
|
}
|
2018-10-09 17:28:24 +00:00
|
|
|
ImGui::EndPopup();
|
2018-07-15 18:10:41 +00:00
|
|
|
}
|
|
|
|
ImGui::Separator();
|
2019-06-16 23:21:55 +00:00
|
|
|
ImGui::TextUnformatted( "Client address" );
|
2018-12-22 16:12:33 +00:00
|
|
|
bool connectClicked = false;
|
2019-03-15 00:47:07 +00:00
|
|
|
connectClicked |= ImGui::InputTextWithHint( "###connectaddress", "Enter address", addr, 1024, ImGuiInputTextFlags_EnterReturnsTrue );
|
2018-10-23 17:44:51 +00:00
|
|
|
if( !connHistVec.empty() )
|
|
|
|
{
|
|
|
|
ImGui::SameLine();
|
|
|
|
if( ImGui::BeginCombo( "##frameCombo", nullptr, ImGuiComboFlags_NoPreview ) )
|
|
|
|
{
|
2018-10-23 17:59:11 +00:00
|
|
|
int idxRemove = -1;
|
2018-10-23 17:44:51 +00:00
|
|
|
const auto sz = std::min<size_t>( 5, connHistVec.size() );
|
|
|
|
for( size_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
const auto& str = connHistVec[i]->first;
|
|
|
|
if( ImGui::Selectable( str.c_str() ) )
|
|
|
|
{
|
|
|
|
memcpy( addr, str.c_str(), str.size() + 1 );
|
|
|
|
}
|
2018-10-23 17:59:11 +00:00
|
|
|
if( ImGui::IsItemHovered() && ImGui::IsKeyPressed( ImGui::GetKeyIndex( ImGuiKey_Delete ), false ) )
|
|
|
|
{
|
|
|
|
idxRemove = (int)i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( idxRemove >= 0 )
|
|
|
|
{
|
|
|
|
connHistMap.erase( connHistVec[idxRemove] );
|
|
|
|
connHistVec = RebuildConnectionHistory( connHistMap );
|
2018-10-23 17:44:51 +00:00
|
|
|
}
|
|
|
|
ImGui::EndCombo();
|
|
|
|
}
|
|
|
|
}
|
2018-12-22 16:12:33 +00:00
|
|
|
connectClicked |= ImGui::Button( ICON_FA_WIFI " Connect" );
|
|
|
|
if( connectClicked && *addr && !loadThread.joinable() )
|
2017-09-15 19:37:28 +00:00
|
|
|
{
|
2018-10-23 17:39:09 +00:00
|
|
|
std::string addrStr( addr );
|
2019-01-29 20:53:56 +00:00
|
|
|
auto it = connHistMap.find( addrStr );
|
2018-10-23 17:39:09 +00:00
|
|
|
if( it != connHistMap.end() )
|
|
|
|
{
|
|
|
|
it->second++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-29 20:53:56 +00:00
|
|
|
connHistMap.emplace( std::move( addrStr ), 1 );
|
2018-10-23 17:39:09 +00:00
|
|
|
}
|
2018-10-23 17:44:51 +00:00
|
|
|
connHistVec = RebuildConnectionHistory( connHistMap );
|
2018-10-23 17:39:09 +00:00
|
|
|
|
2019-08-16 14:02:57 +00:00
|
|
|
view = std::make_unique<tracy::View>( addr, fixedWidth, smallFont, bigFont, SetWindowTitleCallback );
|
2017-09-15 19:37:28 +00:00
|
|
|
}
|
2019-06-16 23:21:55 +00:00
|
|
|
ImGui::SameLine( 0, ImGui::GetFontSize() * 2 );
|
2018-08-17 21:22:13 +00:00
|
|
|
if( ImGui::Button( ICON_FA_FOLDER_OPEN " Open saved trace" ) && !loadThread.joinable() )
|
2017-09-30 12:32:30 +00:00
|
|
|
{
|
|
|
|
nfdchar_t* fn;
|
|
|
|
auto res = NFD_OpenDialog( "tracy", nullptr, &fn );
|
|
|
|
if( res == NFD_OKAY )
|
|
|
|
{
|
2018-04-21 13:00:54 +00:00
|
|
|
try
|
2017-09-30 14:58:02 +00:00
|
|
|
{
|
2018-07-28 16:17:56 +00:00
|
|
|
auto f = std::shared_ptr<tracy::FileRead>( tracy::FileRead::Open( fn ) );
|
2018-04-21 13:00:54 +00:00
|
|
|
if( f )
|
2018-04-21 12:31:33 +00:00
|
|
|
{
|
2019-08-16 14:02:57 +00:00
|
|
|
loadThread = std::thread( [&view, f, &badVer, fixedWidth, smallFont, bigFont] {
|
2018-07-28 16:17:56 +00:00
|
|
|
try
|
|
|
|
{
|
2019-08-16 14:02:57 +00:00
|
|
|
view = std::make_unique<tracy::View>( *f, fixedWidth, smallFont, bigFont, SetWindowTitleCallback );
|
2018-07-28 16:17:56 +00:00
|
|
|
}
|
|
|
|
catch( const tracy::UnsupportedVersion& e )
|
|
|
|
{
|
2019-08-12 10:04:27 +00:00
|
|
|
badVer.state = tracy::BadVersionState::UnsupportedVersion;
|
|
|
|
badVer.version = e.version;
|
2018-07-28 16:17:56 +00:00
|
|
|
}
|
2019-08-12 10:16:48 +00:00
|
|
|
catch( const tracy::LegacyVersion& e )
|
|
|
|
{
|
|
|
|
badVer.state = tracy::BadVersionState::LegacyVersion;
|
|
|
|
badVer.version = e.version;
|
|
|
|
}
|
2018-07-28 16:17:56 +00:00
|
|
|
} );
|
2018-04-21 12:31:33 +00:00
|
|
|
}
|
2018-04-21 13:00:54 +00:00
|
|
|
}
|
2019-06-22 11:41:24 +00:00
|
|
|
catch( const tracy::NotTracyDump& )
|
2018-04-21 13:00:54 +00:00
|
|
|
{
|
2019-08-12 10:04:27 +00:00
|
|
|
badVer.state = tracy::BadVersionState::BadFile;
|
2017-09-30 14:58:02 +00:00
|
|
|
}
|
2017-09-30 12:32:30 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-21 12:31:33 +00:00
|
|
|
|
2019-08-12 10:04:27 +00:00
|
|
|
if( badVer.state != tracy::BadVersionState::Ok )
|
2018-07-28 16:17:56 +00:00
|
|
|
{
|
|
|
|
if( loadThread.joinable() ) { loadThread.join(); }
|
|
|
|
tracy::BadVersion( badVer );
|
|
|
|
}
|
2018-04-21 12:31:33 +00:00
|
|
|
|
2019-06-17 17:45:47 +00:00
|
|
|
if( !clients.empty() )
|
|
|
|
{
|
|
|
|
ImGui::Separator();
|
2019-06-17 18:24:28 +00:00
|
|
|
ImGui::TextUnformatted( "Discovered clients:" );
|
2019-06-17 17:45:47 +00:00
|
|
|
ImGui::Separator();
|
2019-06-18 18:51:12 +00:00
|
|
|
static bool widthSet = false;
|
|
|
|
ImGui::Columns( 3 );
|
|
|
|
if( !widthSet )
|
|
|
|
{
|
|
|
|
widthSet = true;
|
|
|
|
const auto w = ImGui::GetWindowWidth();
|
|
|
|
ImGui::SetColumnWidth( 0, w * 0.35f );
|
|
|
|
ImGui::SetColumnWidth( 1, w * 0.175f );
|
|
|
|
ImGui::SetColumnWidth( 2, w * 0.425f );
|
|
|
|
}
|
2019-06-26 16:41:42 +00:00
|
|
|
std::lock_guard<std::mutex> lock( resolvLock );
|
2019-06-17 17:45:47 +00:00
|
|
|
for( auto& v : clients )
|
|
|
|
{
|
|
|
|
const bool badProto = v.second.protocolVersion != tracy::ProtocolVersion;
|
|
|
|
bool sel = false;
|
2019-06-26 16:41:42 +00:00
|
|
|
const auto& name = resolvMap.find( v.second.address );
|
|
|
|
assert( name != resolvMap.end() );
|
2019-06-17 17:45:47 +00:00
|
|
|
ImGuiSelectableFlags flags = ImGuiSelectableFlags_SpanAllColumns;
|
|
|
|
if( badProto ) flags |= ImGuiSelectableFlags_Disabled;
|
2019-06-26 16:41:42 +00:00
|
|
|
if( ImGui::Selectable( name->second.c_str(), &sel, flags ) && !loadThread.joinable() )
|
2019-06-17 17:50:34 +00:00
|
|
|
{
|
2019-08-16 14:02:57 +00:00
|
|
|
view = std::make_unique<tracy::View>( v.second.address.c_str(), fixedWidth, smallFont, bigFont, SetWindowTitleCallback );
|
2019-06-17 17:50:34 +00:00
|
|
|
}
|
2019-06-17 17:45:47 +00:00
|
|
|
ImGui::NextColumn();
|
2019-06-18 18:56:42 +00:00
|
|
|
const auto acttime = ( v.second.activeTime + ( time - v.second.time ) / 1000 ) * 1000000000ll;
|
2019-06-17 17:45:47 +00:00
|
|
|
if( badProto )
|
2019-06-18 18:51:12 +00:00
|
|
|
{
|
2019-06-18 18:56:42 +00:00
|
|
|
tracy::TextDisabledUnformatted( tracy::TimeToString( acttime ) );
|
2019-06-18 18:51:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-18 18:56:42 +00:00
|
|
|
ImGui::TextUnformatted( tracy::TimeToString( acttime ) );
|
2019-06-18 18:51:12 +00:00
|
|
|
}
|
|
|
|
ImGui::NextColumn();
|
|
|
|
if( badProto )
|
2019-06-17 17:45:47 +00:00
|
|
|
{
|
|
|
|
tracy::TextDisabledUnformatted( v.second.procName.c_str() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ImGui::TextUnformatted( v.second.procName.c_str() );
|
|
|
|
}
|
|
|
|
ImGui::NextColumn();
|
|
|
|
}
|
|
|
|
ImGui::EndColumns();
|
|
|
|
}
|
|
|
|
|
2017-09-15 19:25:47 +00:00
|
|
|
ImGui::End();
|
|
|
|
}
|
2017-09-15 19:37:28 +00:00
|
|
|
else
|
2017-09-15 19:25:47 +00:00
|
|
|
{
|
2019-06-17 17:34:48 +00:00
|
|
|
if( broadcastListen )
|
|
|
|
{
|
2019-08-29 16:36:55 +00:00
|
|
|
broadcastListen.reset();
|
2019-06-17 17:34:48 +00:00
|
|
|
clients.clear();
|
|
|
|
}
|
2018-07-28 16:17:56 +00:00
|
|
|
if( loadThread.joinable() ) loadThread.join();
|
2018-08-17 14:54:56 +00:00
|
|
|
view->NotifyRootWindowSize( display_w, display_h );
|
2018-04-29 23:16:08 +00:00
|
|
|
if( !view->Draw() )
|
|
|
|
{
|
2019-07-24 21:54:47 +00:00
|
|
|
viewShutdown = ViewShutdown::True;
|
|
|
|
loadThread = std::thread( [&viewShutdown, view = std::move( view )] () mutable {
|
|
|
|
view.reset();
|
|
|
|
viewShutdown = ViewShutdown::Join;
|
|
|
|
} );
|
2018-04-29 23:16:08 +00:00
|
|
|
}
|
2017-09-15 19:25:47 +00:00
|
|
|
}
|
2018-07-28 16:07:55 +00:00
|
|
|
auto& progress = tracy::Worker::GetLoadProgress();
|
|
|
|
auto totalProgress = progress.total.load( std::memory_order_relaxed );
|
|
|
|
if( totalProgress != 0 )
|
|
|
|
{
|
|
|
|
ImGui::OpenPopup( "Loading trace..." );
|
|
|
|
}
|
2018-07-28 16:48:45 +00:00
|
|
|
if( ImGui::BeginPopupModal( "Loading trace...", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
|
2018-07-28 16:07:55 +00:00
|
|
|
{
|
2018-08-17 21:29:32 +00:00
|
|
|
tracy::TextCentered( ICON_FA_HOURGLASS_HALF );
|
2019-03-06 01:49:21 +00:00
|
|
|
|
|
|
|
time += io.DeltaTime;
|
2019-03-06 17:12:44 +00:00
|
|
|
tracy::DrawWaitingDots( time );
|
2019-03-06 01:49:21 +00:00
|
|
|
|
2018-07-28 16:07:55 +00:00
|
|
|
auto currProgress = progress.progress.load( std::memory_order_relaxed );
|
|
|
|
if( totalProgress == 0 )
|
|
|
|
{
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
totalProgress = currProgress;
|
|
|
|
}
|
2018-07-29 14:56:46 +00:00
|
|
|
switch( currProgress )
|
|
|
|
{
|
|
|
|
case tracy::LoadProgress::Initialization:
|
2019-02-10 01:50:34 +00:00
|
|
|
ImGui::TextUnformatted( "Initialization..." );
|
2018-07-29 14:56:46 +00:00
|
|
|
break;
|
|
|
|
case tracy::LoadProgress::Locks:
|
2019-02-10 01:50:34 +00:00
|
|
|
ImGui::TextUnformatted( "Locks..." );
|
2018-07-29 14:56:46 +00:00
|
|
|
break;
|
|
|
|
case tracy::LoadProgress::Messages:
|
2019-02-10 01:50:34 +00:00
|
|
|
ImGui::TextUnformatted( "Messages..." );
|
2018-07-29 14:56:46 +00:00
|
|
|
break;
|
|
|
|
case tracy::LoadProgress::Zones:
|
2019-02-10 01:50:34 +00:00
|
|
|
ImGui::TextUnformatted( "CPU zones..." );
|
2018-07-29 14:56:46 +00:00
|
|
|
break;
|
|
|
|
case tracy::LoadProgress::GpuZones:
|
2019-02-10 01:50:34 +00:00
|
|
|
ImGui::TextUnformatted( "GPU zones..." );
|
2018-07-29 14:56:46 +00:00
|
|
|
break;
|
|
|
|
case tracy::LoadProgress::Plots:
|
2019-02-10 01:50:34 +00:00
|
|
|
ImGui::TextUnformatted( "Plots..." );
|
2018-07-29 14:56:46 +00:00
|
|
|
break;
|
|
|
|
case tracy::LoadProgress::Memory:
|
2019-02-10 01:50:34 +00:00
|
|
|
ImGui::TextUnformatted( "Memory..." );
|
2018-07-29 14:56:46 +00:00
|
|
|
break;
|
|
|
|
case tracy::LoadProgress::CallStacks:
|
2019-02-10 01:50:34 +00:00
|
|
|
ImGui::TextUnformatted( "Call stacks..." );
|
2018-07-29 14:56:46 +00:00
|
|
|
break;
|
2019-06-06 21:40:37 +00:00
|
|
|
case tracy::LoadProgress::FrameImages:
|
|
|
|
ImGui::TextUnformatted( "Frame images..." );
|
|
|
|
break;
|
2019-08-12 22:56:57 +00:00
|
|
|
case tracy::LoadProgress::ContextSwitches:
|
|
|
|
ImGui::TextUnformatted( "Context switches..." );
|
|
|
|
break;
|
2019-08-16 14:51:02 +00:00
|
|
|
case tracy::LoadProgress::ContextSwitchesPerCpu:
|
|
|
|
ImGui::TextUnformatted( "CPU context switches..." );
|
|
|
|
break;
|
2018-07-29 14:56:46 +00:00
|
|
|
default:
|
|
|
|
assert( false );
|
|
|
|
break;
|
|
|
|
}
|
2018-07-28 16:07:55 +00:00
|
|
|
ImGui::ProgressBar( float( currProgress ) / totalProgress, ImVec2( 200 * dpiScale, 0 ) );
|
2018-07-28 16:56:52 +00:00
|
|
|
|
2019-02-10 01:50:34 +00:00
|
|
|
ImGui::TextUnformatted( "Progress..." );
|
2018-07-28 16:56:52 +00:00
|
|
|
auto subTotal = progress.subTotal.load( std::memory_order_relaxed );
|
|
|
|
auto subProgress = progress.subProgress.load( std::memory_order_relaxed );
|
|
|
|
if( subTotal == 0 )
|
|
|
|
{
|
|
|
|
ImGui::ProgressBar( 1.f, ImVec2( 200 * dpiScale, 0 ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ImGui::ProgressBar( float( subProgress ) / subTotal, ImVec2( 200 * dpiScale, 0 ) );
|
|
|
|
}
|
2018-07-28 16:07:55 +00:00
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
2019-07-24 21:54:47 +00:00
|
|
|
switch( viewShutdown )
|
|
|
|
{
|
|
|
|
case ViewShutdown::True:
|
|
|
|
ImGui::OpenPopup( "Capture cleanup..." );
|
|
|
|
break;
|
|
|
|
case ViewShutdown::Join:
|
|
|
|
loadThread.join();
|
|
|
|
viewShutdown = ViewShutdown::False;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if( ImGui::BeginPopupModal( "Capture cleanup...", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
|
|
|
|
{
|
|
|
|
if( viewShutdown != ViewShutdown::True ) ImGui::CloseCurrentPopup();
|
|
|
|
tracy::TextCentered( ICON_FA_BROOM );
|
|
|
|
time += io.DeltaTime;
|
|
|
|
tracy::DrawWaitingDots( time );
|
|
|
|
ImGui::Text( "Please wait, cleanup is in progress" );
|
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
2017-09-15 19:25:47 +00:00
|
|
|
|
|
|
|
// Rendering
|
2018-08-29 23:31:57 +00:00
|
|
|
ImGui::Render();
|
|
|
|
glfwMakeContextCurrent(window);
|
2017-09-15 19:25:47 +00:00
|
|
|
glViewport(0, 0, display_w, display_h);
|
|
|
|
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2018-08-29 23:31:57 +00:00
|
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
|
|
|
|
|
|
glfwMakeContextCurrent(window);
|
2017-09-15 19:25:47 +00:00
|
|
|
glfwSwapBuffers(window);
|
2018-07-29 20:11:24 +00:00
|
|
|
|
|
|
|
if( !glfwGetWindowAttrib( window, GLFW_FOCUSED ) )
|
|
|
|
{
|
|
|
|
std::this_thread::sleep_for( std::chrono::milliseconds( 50 ) );
|
|
|
|
}
|
2017-09-15 19:25:47 +00:00
|
|
|
}
|
|
|
|
|
2018-08-31 17:38:19 +00:00
|
|
|
{
|
2018-10-23 17:39:09 +00:00
|
|
|
FILE* f = fopen( winPosFile.c_str(), "wb" );
|
|
|
|
if( f )
|
|
|
|
{
|
2018-08-31 18:05:40 +00:00
|
|
|
#ifdef GLFW_MAXIMIZED
|
2018-10-23 17:39:09 +00:00
|
|
|
uint32_t maximized = glfwGetWindowAttrib( window, GLFW_MAXIMIZED );
|
|
|
|
if( maximized ) glfwRestoreWindow( window );
|
2018-08-31 18:05:40 +00:00
|
|
|
#else
|
2018-10-23 17:39:09 +00:00
|
|
|
uint32_t maximized = 0;
|
2018-08-31 18:05:40 +00:00
|
|
|
#endif
|
2018-08-31 17:38:19 +00:00
|
|
|
|
2018-10-23 17:39:09 +00:00
|
|
|
glfwGetWindowPos( window, &x, &y );
|
|
|
|
glfwGetWindowSize( window, &w, &h );
|
2018-10-05 18:23:54 +00:00
|
|
|
|
2018-10-23 17:39:09 +00:00
|
|
|
uint32_t data[5] = { uint32_t( x ), uint32_t( y ), uint32_t( w ), uint32_t( h ), maximized };
|
|
|
|
fwrite( data, 1, sizeof( data ), f );
|
|
|
|
fclose( f );
|
|
|
|
}
|
2018-08-31 17:38:19 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 19:25:47 +00:00
|
|
|
// Cleanup
|
2018-08-29 23:31:57 +00:00
|
|
|
ImGui_ImplOpenGL3_Shutdown();
|
|
|
|
ImGui_ImplGlfw_Shutdown();
|
2018-04-14 13:12:16 +00:00
|
|
|
ImGui::DestroyContext();
|
2018-08-29 23:31:57 +00:00
|
|
|
|
|
|
|
glfwDestroyWindow(window);
|
2017-09-15 19:25:47 +00:00
|
|
|
glfwTerminate();
|
|
|
|
|
2018-10-23 17:39:09 +00:00
|
|
|
{
|
|
|
|
FILE* f = fopen( connHistFile.c_str(), "wb" );
|
|
|
|
if( f )
|
|
|
|
{
|
|
|
|
uint64_t sz = uint64_t( connHistMap.size() );
|
|
|
|
fwrite( &sz, 1, sizeof( uint64_t ), f );
|
|
|
|
for( auto& v : connHistMap )
|
|
|
|
{
|
|
|
|
sz = uint64_t( v.first.size() );
|
|
|
|
fwrite( &sz, 1, sizeof( uint64_t ), f );
|
|
|
|
fwrite( v.first.c_str(), 1, sz, f );
|
|
|
|
fwrite( &v.second, 1, sizeof( v.second ), f );
|
|
|
|
}
|
|
|
|
fclose( f );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-15 19:25:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|