2018-08-17 15:24:50 +00:00
|
|
|
#include <assert.h>
|
2018-07-28 16:50:22 +00:00
|
|
|
#include <inttypes.h>
|
2017-09-15 19:25:47 +00:00
|
|
|
#include <imgui.h>
|
|
|
|
#include "imgui_impl_glfw_gl3.h"
|
|
|
|
#include <stdio.h>
|
2018-07-15 18:10:34 +00:00
|
|
|
#include <stdlib.h>
|
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>
|
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
|
|
|
|
|
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"
|
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"
|
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 );
|
|
|
|
#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-03-24 21:20:06 +00:00
|
|
|
int main( int argc, char** argv )
|
2017-09-15 19:25:47 +00:00
|
|
|
{
|
2018-03-24 21:20:06 +00:00
|
|
|
std::unique_ptr<tracy::View> view;
|
2018-04-21 12:31:33 +00:00
|
|
|
int badVer = 0;
|
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-07-29 12:24:24 +00:00
|
|
|
char title[128];
|
|
|
|
sprintf( title, "Tracy server %i.%i.%i", tracy::Version::Major, tracy::Version::Minor, tracy::Version::Patch );
|
|
|
|
|
2017-09-15 19:25:47 +00:00
|
|
|
// Setup window
|
2018-04-14 13:12:16 +00:00
|
|
|
glfwSetErrorCallback(glfw_error_callback);
|
2017-09-15 19:25:47 +00:00
|
|
|
if (!glfwInit())
|
|
|
|
return 1;
|
|
|
|
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-07-29 12:24:24 +00:00
|
|
|
GLFWwindow* window = glfwCreateWindow(1650, 960, title, NULL, NULL);
|
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-04-14 13:12:16 +00:00
|
|
|
ImGui::CreateContext();
|
2018-08-29 21:22:54 +00:00
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
io.IniFilename = tracy::GetSavePath( "imgui.ini" );
|
|
|
|
|
2017-09-15 19:25:47 +00:00
|
|
|
ImGui_ImplGlfwGL3_Init(window, true);
|
|
|
|
|
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
|
|
|
|
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 );
|
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;
|
|
|
|
style.FrameRounding = 5.f * dpiScale;
|
2018-08-17 17:06:30 +00:00
|
|
|
style.ScrollbarSize *= dpiScale;
|
2018-01-13 13:08:14 +00:00
|
|
|
style.Colors[ImGuiCol_WindowBg] = ImVec4( 0.11f, 0.11f, 0.08f, 0.94f );
|
|
|
|
style.Colors[ImGuiCol_ScrollbarBg] = ImVec4( 1, 1, 1, 0.03f );
|
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;
|
|
|
|
|
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);
|
|
|
|
|
2017-09-15 19:25:47 +00:00
|
|
|
ImGui_ImplGlfwGL3_NewFrame();
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2018-07-15 18:10:41 +00:00
|
|
|
ImGui::Begin( "Tracy server", nullptr, ImGuiWindowFlags_AlwaysAutoResize );
|
2018-08-17 21:08:07 +00:00
|
|
|
char buf[128];
|
|
|
|
sprintf( buf, "Tracy %i.%i.%i", tracy::Version::Major, tracy::Version::Minor, tracy::Version::Patch );
|
|
|
|
tracy::TextCentered( buf );
|
2018-08-17 21:22:13 +00:00
|
|
|
if( ImGui::Button( ICON_FA_BOOK " User manual" ) )
|
2018-08-03 23:15:56 +00:00
|
|
|
{
|
|
|
|
OpenWebpage( "https://bitbucket.org/wolfpld/tracy/downloads/tracy.pdf" );
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
2018-08-17 21:22:13 +00:00
|
|
|
if( ImGui::Button( ICON_FA_GLOBE_AMERICAS " Homepage" ) )
|
2018-07-15 18:10:41 +00:00
|
|
|
{
|
|
|
|
OpenWebpage( "https://bitbucket.org/wolfpld/tracy" );
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
|
|
|
OpenWebpage( "https://www.youtube.com/watch?v=fB5B46lbapc" );
|
|
|
|
}
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::Text( "Connect to client" );
|
2017-09-15 19:37:28 +00:00
|
|
|
ImGui::InputText( "Address", addr, 1024 );
|
2018-08-17 21:22:13 +00:00
|
|
|
if( ImGui::Button( ICON_FA_WIFI " Connect" ) && *addr && !loadThread.joinable() )
|
2017-09-15 19:37:28 +00:00
|
|
|
{
|
2018-08-17 15:24:50 +00:00
|
|
|
view = std::make_unique<tracy::View>( addr, fixedWidth, SetWindowTitleCallback );
|
2017-09-15 19:37:28 +00:00
|
|
|
}
|
2017-09-30 12:32:30 +00:00
|
|
|
ImGui::Separator();
|
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
|
|
|
{
|
2018-08-17 13:18:37 +00:00
|
|
|
loadThread = std::thread( [&view, f, &badVer, fixedWidth] {
|
2018-07-28 16:17:56 +00:00
|
|
|
try
|
|
|
|
{
|
2018-08-17 15:24:50 +00:00
|
|
|
view = std::make_unique<tracy::View>( *f, fixedWidth, SetWindowTitleCallback );
|
2018-07-28 16:17:56 +00:00
|
|
|
}
|
|
|
|
catch( const tracy::UnsupportedVersion& e )
|
|
|
|
{
|
|
|
|
badVer = e.version;
|
|
|
|
}
|
|
|
|
} );
|
2018-04-21 12:31:33 +00:00
|
|
|
}
|
2018-04-21 13:00:54 +00:00
|
|
|
}
|
|
|
|
catch( const tracy::NotTracyDump& e )
|
|
|
|
{
|
|
|
|
badVer = -1;
|
2017-09-30 14:58:02 +00:00
|
|
|
}
|
2017-09-30 12:32:30 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-21 12:31:33 +00:00
|
|
|
|
2018-07-28 16:17:56 +00:00
|
|
|
if( badVer != 0 )
|
|
|
|
{
|
|
|
|
if( loadThread.joinable() ) { loadThread.join(); }
|
|
|
|
tracy::BadVersion( badVer );
|
|
|
|
}
|
2018-04-21 12:31:33 +00:00
|
|
|
|
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
|
|
|
{
|
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() )
|
|
|
|
{
|
|
|
|
view.reset();
|
|
|
|
}
|
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 );
|
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:
|
|
|
|
ImGui::Text( "Initialization..." );
|
|
|
|
break;
|
|
|
|
case tracy::LoadProgress::Locks:
|
|
|
|
ImGui::Text( "Locks..." );
|
|
|
|
break;
|
|
|
|
case tracy::LoadProgress::Messages:
|
|
|
|
ImGui::Text( "Messages..." );
|
|
|
|
break;
|
|
|
|
case tracy::LoadProgress::Zones:
|
|
|
|
ImGui::Text( "CPU zones..." );
|
|
|
|
break;
|
|
|
|
case tracy::LoadProgress::GpuZones:
|
|
|
|
ImGui::Text( "GPU zones..." );
|
|
|
|
break;
|
|
|
|
case tracy::LoadProgress::Plots:
|
|
|
|
ImGui::Text( "Plots..." );
|
|
|
|
break;
|
|
|
|
case tracy::LoadProgress::Memory:
|
|
|
|
ImGui::Text( "Memory..." );
|
|
|
|
break;
|
|
|
|
case tracy::LoadProgress::CallStacks:
|
|
|
|
ImGui::Text( "Call stacks..." );
|
|
|
|
break;
|
|
|
|
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
|
|
|
|
2018-07-29 14:56:46 +00:00
|
|
|
ImGui::Text( "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();
|
|
|
|
}
|
2017-09-15 19:25:47 +00:00
|
|
|
|
|
|
|
// Rendering
|
|
|
|
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);
|
|
|
|
ImGui::Render();
|
2018-04-14 13:12:16 +00:00
|
|
|
ImGui_ImplGlfwGL3_RenderDrawData(ImGui::GetDrawData());
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
ImGui_ImplGlfwGL3_Shutdown();
|
2018-04-14 13:12:16 +00:00
|
|
|
ImGui::DestroyContext();
|
2017-09-15 19:25:47 +00:00
|
|
|
glfwTerminate();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|