mirror of
https://github.com/wolfpld/tracy
synced 2025-04-29 20:33:52 +00:00
Track connection history.
This commit is contained in:
parent
63f0dd72a5
commit
1eb46042be
@ -3,9 +3,11 @@
|
|||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include "imgui_impl_glfw.h"
|
#include "imgui_impl_glfw.h"
|
||||||
#include "imgui_impl_opengl3.h"
|
#include "imgui_impl_opengl3.h"
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
#include <GL/gl3w.h>
|
#include <GL/gl3w.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -17,6 +19,7 @@
|
|||||||
# include <shellapi.h>
|
# include <shellapi.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "../../server/tracy_pdqsort.h"
|
||||||
#include "../../server/TracyBadVersion.hpp"
|
#include "../../server/TracyBadVersion.hpp"
|
||||||
#include "../../server/TracyFileRead.hpp"
|
#include "../../server/TracyFileRead.hpp"
|
||||||
#include "../../server/TracyImGui.hpp"
|
#include "../../server/TracyImGui.hpp"
|
||||||
@ -90,6 +93,36 @@ int main( int argc, char** argv )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 );
|
||||||
|
|
||||||
|
connHistVec.reserve( connHistMap.size() );
|
||||||
|
for( auto it = connHistMap.begin(); it != connHistMap.end(); ++it )
|
||||||
|
{
|
||||||
|
connHistVec.emplace_back( it );
|
||||||
|
}
|
||||||
|
tracy::pdqsort_branchless( connHistVec.begin(), connHistVec.end(), []( const auto& lhs, const auto& rhs ) { return lhs->second > rhs->second; } );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Setup window
|
// Setup window
|
||||||
glfwSetErrorCallback(glfw_error_callback);
|
glfwSetErrorCallback(glfw_error_callback);
|
||||||
if( !glfwInit() ) return 1;
|
if( !glfwInit() ) return 1;
|
||||||
@ -233,6 +266,17 @@ int main( int argc, char** argv )
|
|||||||
ImGui::InputText( "Address", addr, 1024 );
|
ImGui::InputText( "Address", addr, 1024 );
|
||||||
if( ImGui::Button( ICON_FA_WIFI " Connect" ) && *addr && !loadThread.joinable() )
|
if( ImGui::Button( ICON_FA_WIFI " Connect" ) && *addr && !loadThread.joinable() )
|
||||||
{
|
{
|
||||||
|
std::string addrStr( addr );
|
||||||
|
auto it = connHistMap.find( addr );
|
||||||
|
if( it != connHistMap.end() )
|
||||||
|
{
|
||||||
|
it->second++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
connHistMap.emplace( std::move( addr ), 1 );
|
||||||
|
}
|
||||||
|
|
||||||
view = std::make_unique<tracy::View>( addr, fixedWidth, SetWindowTitleCallback );
|
view = std::make_unique<tracy::View>( addr, fixedWidth, SetWindowTitleCallback );
|
||||||
}
|
}
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
@ -361,6 +405,7 @@ int main( int argc, char** argv )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
FILE* f = fopen( winPosFile.c_str(), "wb" );
|
FILE* f = fopen( winPosFile.c_str(), "wb" );
|
||||||
if( f )
|
if( f )
|
||||||
{
|
{
|
||||||
@ -378,6 +423,7 @@ int main( int argc, char** argv )
|
|||||||
fwrite( data, 1, sizeof( data ), f );
|
fwrite( data, 1, sizeof( data ), f );
|
||||||
fclose( f );
|
fclose( f );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
ImGui_ImplOpenGL3_Shutdown();
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
@ -387,5 +433,22 @@ int main( int argc, char** argv )
|
|||||||
glfwDestroyWindow(window);
|
glfwDestroyWindow(window);
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
||||||
|
{
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user