Don't care about memory usage tracking data races.

This commit is contained in:
Bartosz Taudul 2019-11-10 19:20:57 +01:00
parent 9504d6c68f
commit fa53c2e683
6 changed files with 17 additions and 18 deletions

View File

@ -129,11 +129,11 @@ int main( int argc, char** argv )
{
printf( "\33[2K\r\033[36;1m%7.2f Mbps", mbps );
}
printf( " \033[0m /\033[36;1m%5.1f%% \033[0m=\033[33;1m%7.2f Mbps \033[0m| \033[33mNet: \033[32m%s \033[0m| \033[33mMem: \033[31;1m%.2f MB\033[0m | \033[33mTime: %s\033[0m",
printf( " \033[0m /\033[36;1m%5.1f%% \033[0m=\033[33;1m%7.2f Mbps \033[0m| \033[33mNet: \033[32m%s \033[0m| \033[33mMem: \033[31;1m%s\033[0m | \033[33mTime: %s\033[0m",
compRatio * 100.f,
mbps / compRatio,
tracy::MemSizeToString( netTotal ),
tracy::memUsage.load( std::memory_order_relaxed ) / ( 1024.f * 1024.f ),
tracy::MemSizeToString( tracy::memUsage ),
tracy::TimeToString( worker.GetLastTime() ) );
fflush( stdout );

View File

@ -3,6 +3,6 @@
namespace tracy
{
std::atomic<size_t> memUsage( 0 );
size_t memUsage = 0;
}

View File

@ -1,13 +1,12 @@
#ifndef __TRACYMEMORY_HPP__
#define __TRACYMEMORY_HPP__
#include <atomic>
#include <stdlib.h>
namespace tracy
{
extern std::atomic<size_t> memUsage;
extern size_t memUsage;
}

View File

@ -19,12 +19,12 @@ public:
, m_buffer( { m_ptr } )
, m_usage( BlockSize )
{
memUsage.fetch_add( BlockSize, std::memory_order_relaxed );
memUsage += BlockSize;
}
~Slab()
{
memUsage.fetch_sub( m_usage, std::memory_order_relaxed );
memUsage -= m_usage;
for( auto& v : m_buffer )
{
delete[] v;
@ -113,7 +113,7 @@ public:
}
else
{
memUsage.fetch_add( size, std::memory_order_relaxed );
memUsage += size;
m_usage += size;
auto ret = new char[size];
m_buffer.emplace_back( ret );
@ -125,7 +125,7 @@ public:
{
if( m_buffer.size() > 1 )
{
memUsage.fetch_sub( m_usage - BlockSize, std::memory_order_relaxed );
memUsage -= m_usage - BlockSize;
m_usage = BlockSize;
for( int i=1; i<m_buffer.size(); i++ )
{
@ -150,7 +150,7 @@ private:
m_ptr = new char[BlockSize];
m_offset = 0;
m_buffer.emplace_back( m_ptr );
memUsage.fetch_add( BlockSize, std::memory_order_relaxed );
memUsage += BlockSize;
m_usage += BlockSize;
}

View File

@ -49,7 +49,7 @@ public:
, m_capacity( 0 )
, m_magic( 0 )
{
memUsage.fetch_add( sizeof( T ), std::memory_order_relaxed );
memUsage += sizeof( T );
m_ptr[0] = value;
}
@ -57,7 +57,7 @@ public:
{
if( m_capacity != MaxCapacity() && m_ptr )
{
memUsage.fetch_sub( Capacity() * sizeof( T ), std::memory_order_relaxed );
memUsage -= Capacity() * sizeof( T );
delete[] (T*)m_ptr;
}
}
@ -67,7 +67,7 @@ public:
{
if( m_capacity != MaxCapacity() && m_ptr )
{
memUsage.fetch_sub( Capacity() * sizeof( T ), std::memory_order_relaxed );
memUsage -= Capacity() * sizeof( T );
delete[] (T*)m_ptr;
}
memcpy( this, &src, sizeof( Vector<T> ) );
@ -239,7 +239,7 @@ public:
cap |= cap >> 8;
cap |= cap >> 16;
cap = TracyCountBits( cap );
memUsage.fetch_add( ( ( 1 << cap ) - Capacity() ) * sizeof( T ), std::memory_order_relaxed );
memUsage += ( ( 1 << cap ) - Capacity() ) * sizeof( T );
m_capacity = cap;
Realloc();
}
@ -276,13 +276,13 @@ private:
if( m_ptr == nullptr )
{
memUsage.fetch_add( sizeof( T ), std::memory_order_relaxed );
memUsage += sizeof( T );
m_ptr = new T[1];
m_capacity = 0;
}
else
{
memUsage.fetch_add( Capacity() * sizeof( T ), std::memory_order_relaxed );
memUsage += Capacity() * sizeof( T );
m_capacity++;
Realloc();
}

View File

@ -953,7 +953,7 @@ bool View::DrawConnection()
TextFocused( "Query backlog:", RealToString( m_worker.GetSendQueueSize(), true ) );
}
TextFocused( "Memory usage:", MemSizeToString( memUsage.load( std::memory_order_relaxed ) ) );
TextFocused( "Memory usage:", MemSizeToString( memUsage ) );
const auto wpos = ImGui::GetWindowPos() + ImGui::GetWindowContentRegionMin();
ImGui::GetWindowDrawList()->AddCircleFilled( wpos + ImVec2( 1 + cs * 0.5, 3 + ty * 1.75 ), cs * 0.5, m_worker.IsConnected() ? 0xFF2222CC : 0xFF444444, 10 );
@ -10761,7 +10761,7 @@ void View::DrawInfo()
if( ImGui::TreeNode( "Profiler statistics" ) )
{
TextFocused( "Profiler memory usage:", MemSizeToString( memUsage.load( std::memory_order_relaxed ) ) );
TextFocused( "Profiler memory usage:", MemSizeToString( memUsage ) );
TextFocused( "Profiler FPS:", RealToString( int( io.Framerate ), true ) );
ImGui::TreePop();
}