-
-
Notifications
You must be signed in to change notification settings - Fork 679
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add name buffer to tracy client library
To be used by Python and Go bindings to store const char * accessible via a lookup
- Loading branch information
1 parent
6199b2f
commit fbd9347
Showing
10 changed files
with
155 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "TracyNameBuffer.hpp" | ||
using namespace tracy; | ||
|
||
#include "TracyApi.h" | ||
|
||
#ifndef TRACY_BUFFER_SIZE | ||
#define TRACY_BUFFER_SIZE = 128 | ||
#endif | ||
|
||
#ifndef TRACY_NAME_LENGTH | ||
#define TRACY_NAME_LENGTH = 128 | ||
#endif | ||
|
||
NameBuffer::NameBuffer() : m_buffer(TRACY_BUFFER_SIZE, nullptr), m_index(0ul) { | ||
for (std::size_t index = 0ul, end = m_buffer.size(); index < end; ++index) | ||
m_buffer[index] = new char[TRACY_NAME_LENGTH]; | ||
} | ||
|
||
BufferEntry NameBuffer::add( const std::string& name ) { | ||
std::lock_guard<std::mutex> lock(m_mutex); | ||
if (m_index >= TRACY_BUFFER_SIZE || name.size() > TRACY_NAME_LENGTH) | ||
return std::make_pair(std::nullopt, nullptr); | ||
|
||
auto index = m_index++; | ||
name.copy(m_buffer[index], name.size()); | ||
return std::make_pair(index, m_buffer[index]); | ||
} | ||
|
||
const char* NameBuffer::get( uint16_t index ) { | ||
std::lock_guard<std::mutex> lock(m_mutex); | ||
if (index >= TRACY_BUFFER_SIZE) return nullptr; | ||
return m_buffer[index]; | ||
} | ||
|
||
#ifdef TRACY_NAME_BUFFER | ||
TRACY_API const char* ___tracy_name_buffer_add( const char* name, uint16_t* id ) { | ||
auto entry = NameBuffer::Add(name); | ||
if (!entry.first) return nullptr; | ||
|
||
if (id != nullptr) *id = *entry.first; | ||
return entry.second; | ||
} | ||
TRACY_API const char* ___tracy_name_buffer_get( uint16_t id ) { return NameBuffer::Get(id); } | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
|
||
#include <mutex> | ||
#include <optional> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace tracy { | ||
using OptionalNumber = std::optional<uint16_t>; | ||
using BufferEntry = std::pair<OptionalNumber, const char*>; | ||
|
||
class NameBuffer { | ||
public: | ||
static inline BufferEntry Add( const std::string& name ) { | ||
return getBuffer().add(name); | ||
} | ||
|
||
static inline const char* Get( uint16_t index ) { | ||
return getBuffer().get(index); | ||
} | ||
|
||
private: | ||
NameBuffer(); | ||
|
||
std::mutex m_mutex; | ||
std::vector<char*> m_buffer; | ||
std::size_t m_index; | ||
|
||
static inline NameBuffer& getBuffer() { | ||
static NameBuffer buffer; | ||
return buffer; | ||
} | ||
|
||
BufferEntry add( const std::string& name ); | ||
const char* get( uint16_t index ); | ||
}; | ||
} // namespace tracy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.