mirror of
https://github.com/wolfpld/tracy.git
synced 2025-03-20 07:40:02 +08:00
Make ring buffer size adjustable.
If call stack capture is enabled for context switch data, the 64KB buffer is too small to work without overruns. However, if the default buffer size is increased, then the maximum locked memory limit is hit. This change keeps the small buffer size for all the buffers that may be used without escalated privileges. The context switch buffer is bigger, but it does not need to obey the limits, as the application is running as root, if it is to be used.
This commit is contained in:
+14
-11
@@ -3,19 +3,19 @@
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
template<size_t Size>
|
||||
class RingBuffer
|
||||
{
|
||||
public:
|
||||
RingBuffer( int fd, int id, int cpu = -1 )
|
||||
: m_id( id )
|
||||
RingBuffer( int size, int fd, int id, int cpu = -1 )
|
||||
: m_size( size )
|
||||
, m_id( id )
|
||||
, m_cpu( cpu )
|
||||
, m_fd( fd )
|
||||
{
|
||||
const auto pageSize = uint32_t( getpagesize() );
|
||||
assert( Size >= pageSize );
|
||||
assert( __builtin_popcount( Size ) == 1 );
|
||||
m_mapSize = Size + pageSize;
|
||||
assert( size >= pageSize );
|
||||
assert( __builtin_popcount( size ) == 1 );
|
||||
m_mapSize = size + pageSize;
|
||||
auto mapAddr = mmap( nullptr, m_mapSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 );
|
||||
if( mapAddr == MAP_FAILED )
|
||||
{
|
||||
@@ -66,16 +66,18 @@ public:
|
||||
|
||||
void Read( void* dst, uint64_t offset, uint64_t cnt )
|
||||
{
|
||||
auto src = ( m_tail + offset ) % Size;
|
||||
if( src + cnt <= Size )
|
||||
const auto size = m_size;
|
||||
auto src = ( m_tail + offset ) % size;
|
||||
if( src + cnt <= size )
|
||||
{
|
||||
memcpy( dst, m_buffer + src, cnt );
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto s0 = Size - src;
|
||||
memcpy( dst, m_buffer + src, s0 );
|
||||
memcpy( (char*)dst + s0, m_buffer, cnt - s0 );
|
||||
const auto s0 = size - src;
|
||||
const auto buf = m_buffer;
|
||||
memcpy( dst, buf + src, s0 );
|
||||
memcpy( (char*)dst + s0, buf, cnt - s0 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +117,7 @@ private:
|
||||
std::atomic_store_explicit( (volatile std::atomic<uint64_t>*)&m_metadata->data_tail, m_tail, std::memory_order_release );
|
||||
}
|
||||
|
||||
int m_size;
|
||||
uint64_t m_tail;
|
||||
char* m_buffer;
|
||||
int m_id;
|
||||
|
||||
Reference in New Issue
Block a user