#include #include #include #include "ConnectionHistory.hpp" #include "../../server/tracy_pdqsort.h" #include "../../server/TracyStorage.hpp" ConnectionHistory::ConnectionHistory() : m_fn( tracy::GetSavePath( "connection.history" ) ) { FILE* f = fopen( m_fn.c_str(), "rb" ); if( !f ) return; uint64_t sz; fread( &sz, 1, sizeof( sz ), f ); for( uint64_t i=0; i::const_iterator> vec; vec.reserve( m_connHistMap.size() ); for( auto it = m_connHistMap.begin(); it != m_connHistMap.end(); ++it ) { vec.emplace_back( it ); } tracy::pdqsort_branchless( vec.begin(), vec.end(), []( const auto& lhs, const auto& rhs ) { return lhs->second > rhs->second; } ); std::swap( m_connHistVec, vec ); } void ConnectionHistory::Count( const char* name ) { std::string addr( name ); auto it = m_connHistMap.find( addr ); if( it != m_connHistMap.end() ) { it->second++; } else { m_connHistMap.emplace( std::move( addr ), 1 ); } Rebuild(); } void ConnectionHistory::Erase( size_t idx ) { assert( idx < m_connHistVec.size() ); m_connHistMap.erase( m_connHistVec[idx] ); Rebuild(); }