mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-26 16:04:34 +00:00
Track server memory usage.
This commit is contained in:
parent
ab033188d8
commit
447f042c9a
8
server/TracyMemory.cpp
Executable file
8
server/TracyMemory.cpp
Executable file
@ -0,0 +1,8 @@
|
||||
#include "TracyMemory.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
std::atomic<size_t> memUsage = 0;
|
||||
|
||||
}
|
14
server/TracyMemory.hpp
Executable file
14
server/TracyMemory.hpp
Executable file
@ -0,0 +1,14 @@
|
||||
#ifndef __TRACYMEMORY_HPP__
|
||||
#define __TRACYMEMORY_HPP__
|
||||
|
||||
#include <atomic>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
extern std::atomic<size_t> memUsage;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -4,6 +4,8 @@
|
||||
#include <assert.h>
|
||||
#include <vector>
|
||||
|
||||
#include "TracyMemory.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
@ -15,10 +17,13 @@ public:
|
||||
: m_ptr( new char[BlockSize] )
|
||||
, m_buffer( { m_ptr } )
|
||||
, m_offset( 0 )
|
||||
{}
|
||||
{
|
||||
memUsage.fetch_add( BlockSize, std::memory_order_relaxed );
|
||||
}
|
||||
|
||||
~Slab()
|
||||
{
|
||||
memUsage.fetch_sub( BlockSize * m_buffer.size(), std::memory_order_relaxed );
|
||||
for( auto& v : m_buffer )
|
||||
{
|
||||
delete[] v;
|
||||
@ -33,6 +38,7 @@ public:
|
||||
m_ptr = new char[BlockSize];
|
||||
m_offset = 0;
|
||||
m_buffer.emplace_back( m_ptr );
|
||||
memUsage.fetch_add( BlockSize, std::memory_order_relaxed );
|
||||
}
|
||||
void* ret = m_ptr + m_offset;
|
||||
m_offset += size;
|
||||
@ -55,6 +61,7 @@ public:
|
||||
{
|
||||
if( m_buffer.size() > 1 )
|
||||
{
|
||||
memUsage.fetch_sub( BlockSize * ( m_buffer.size() - 1 ), std::memory_order_relaxed );
|
||||
for( int i=1; i<m_buffer.size(); i++ )
|
||||
{
|
||||
delete[] m_buffer[i];
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "TracyMemory.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
@ -24,6 +26,7 @@ public:
|
||||
|
||||
~Vector()
|
||||
{
|
||||
memUsage.fetch_sub( m_capacity * sizeof( T ), std::memory_order_relaxed );
|
||||
delete[] m_ptr;
|
||||
}
|
||||
|
||||
@ -77,9 +80,11 @@ private:
|
||||
if( m_capacity == 0 )
|
||||
{
|
||||
m_capacity = 64;
|
||||
memUsage.fetch_add( m_capacity * sizeof( T ), std::memory_order_relaxed );
|
||||
}
|
||||
else
|
||||
{
|
||||
memUsage.fetch_add( m_capacity * sizeof( T ), std::memory_order_relaxed );
|
||||
m_capacity *= 2;
|
||||
}
|
||||
T* ptr = new T[m_capacity];
|
||||
|
@ -309,6 +309,8 @@ void View::DrawImpl()
|
||||
ImGui::PlotLines( buf, m_mbps.data(), m_mbps.size(), 0, nullptr, 0 );
|
||||
}
|
||||
|
||||
ImGui::Text( "Memory usage: %.2f MB", memUsage.load( std::memory_order_relaxed ) / ( 1024.f * 1024.f ) );
|
||||
|
||||
std::lock_guard<std::mutex> lock( m_lock );
|
||||
{
|
||||
const auto sz = m_frames.size();
|
||||
|
Loading…
Reference in New Issue
Block a user