Skip to content

Commit 3e2ac8e

Browse files
committed
Add Log::*TagT()
Adds `TLM.id` at the start of the log. Also added `GLOBAL_NAME` option to `r_vkLogExtendedFunctionNames`, which only shows struct/class name, or function name for global functions.
1 parent d015ddd commit 3e2ac8e

3 files changed

Lines changed: 45 additions & 24 deletions

File tree

src/engine/renderer-vulkan/Memory/MemoryChunk.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,20 @@ MemoryChunk MemoryChunkSystem::Alloc( uint64_t size ) {
6161
SizeToLevel( size, &level, &count );
6262

6363
if ( count > 64 ) {
64-
Sys::Drop( "Allocation size too large: %ull\n", size );
64+
Sys::Drop( "Allocation size too large: %ull", size );
6565
}
6666

6767
MemoryChunk out;
6868

6969
if ( count > 1 ) {
70-
Sys::Drop( "Couldn't find memory chunk large enough to support allocation (%u bytes, requires %u * %u byte chunks)\n",
70+
Sys::Drop( "Couldn't find memory chunk large enough to support allocation (%u bytes, requires %u * %u byte chunks)",
7171
size, count, memoryAreas[level].config.chunkSize );
7272
}
7373

7474
uint32_t initialLevel = level;
7575
while ( !LockArea( &memoryAreas[level], &out.chunkArea, &out.chunk ) ) {
7676
if ( level == 0 ) {
77-
Log::WarnTag( "No memory chunks available, yielding" );
77+
Log::WarnTagT( "No memory chunks available, yielding" );
7878
std::this_thread::yield();
7979
level = initialLevel;
8080
} else {
@@ -89,8 +89,7 @@ MemoryChunk MemoryChunkSystem::Alloc( uint64_t size ) {
8989
}
9090

9191
void MemoryChunkSystem::Free( MemoryChunk* memoryChunk ) {
92-
Log::DebugTag( "%i: freeing area %u chunk %u:%u\n", std::this_thread::get_id(),
93-
memoryChunk->area, memoryChunk->chunkArea, memoryChunk->chunk );
92+
Log::DebugTagT( "Freeing area %u chunk %u:%u", memoryChunk->area, memoryChunk->chunkArea, memoryChunk->chunk );
9493

9594
memoryAreas[memoryChunk->area].chunkLocks[memoryChunk->chunkArea].value -= 1ull << memoryChunk->chunk;
9695
}
@@ -111,7 +110,7 @@ void MemoryChunkSystem::SizeToLevel( const uint64_t size, uint32_t* level, uint3
111110
} */
112111
}
113112

114-
Sys::Drop( "Couldn't find memory area with large enough chunkSize" );
113+
Sys::Drop( "Couldn't find memory area with large enough chunkSize, requested: %u bytes", size );
115114
}
116115

117116
bool MemoryChunkSystem::LockArea( MemoryArea* memoryArea, uint32_t* chunkArea, uint32_t* chunk ) {
@@ -144,10 +143,10 @@ bool MemoryChunkSystem::LockArea( MemoryArea* memoryArea, uint32_t* chunkArea, u
144143

145144
area = FindLZeroBit( expectedLocks );
146145

147-
Log::DebugTag( "%i: trying area %u\n", std::this_thread::get_id(), area );
146+
Log::DebugTagT( "Trying chunk %u", area );
148147

149148
if ( i * 64 + area >= memoryArea->config.chunks ) {
150-
Log::DebugTag( "%i: Failed: chunk %u out of range\n", std::this_thread::get_id(), area );
149+
Log::DebugTagT( "Failed: chunk %u out of range", area );
151150
return false;
152151
}
153152

@@ -162,8 +161,8 @@ bool MemoryChunkSystem::LockArea( MemoryArea* memoryArea, uint32_t* chunkArea, u
162161
!memoryArea->chunkLocks[current].value.compare_exchange_strong( expectedLocks, desiredLocks, std::memory_order_relaxed )
163162
);
164163

165-
Log::DebugTag( "%i: locked area %u:%u in %s, loop: %u\n",
166-
std::this_thread::get_id(), current, area, Timer::FormatTime( t.Time() ).c_str(),
164+
Log::DebugTagT( "Locked area %u:%u in %s, loop: %u",
165+
current, area, Timer::FormatTime( t.Time() ),
167166
loopCount );
168167

169168
*chunkArea = current;

src/engine/renderer-vulkan/MiscCVarStore.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,9 @@ Cvar::Cvar<bool> r_vkLogExtendVerbose( "r_vkLogExtendVerbose", "Print src locati
4444
Cvar::Cvar<bool> r_vkLogExtendDebug( "r_vkLogExtendDebug", "Print src location in debug logs", Cvar::NONE, false );
4545

4646
Cvar::Range<Cvar::Cvar<int>> r_vkLogExtendedFunctionNames( "r_vkLogExtendedFunctionNames",
47-
"Extended log function format: 0 - only name, 1 - name + template specialisation, 2 - all", Cvar::NONE,
48-
LogExtendedFunctionMode::NAME, LogExtendedFunctionMode::NAME, LogExtendedFunctionMode::FULL );
47+
"Extended log function format: 0 - only name/only struct or class name (for struct/class functions),"
48+
" 1 - only name, 2 - name + template specialisation, 3 - all",
49+
Cvar::NONE,
50+
LogExtendedFunctionMode::NAME, LogExtendedFunctionMode::GLOBAL_NAME, LogExtendedFunctionMode::FULL );
51+
52+
Cvar::Cvar<bool> r_vkLogShowThreadID( "r_vkLogShowThreadID", "Add thread ID to logs", Cvar::NONE, false );

src/engine/renderer-vulkan/SrcDebug/Tag.h

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3838

3939
#include "common/Common.h"
4040

41+
#include "../Thread/ThreadMemory.h"
42+
4143
namespace LogExtendedFunctionMode {
4244
enum {
45+
GLOBAL_NAME,
4346
NAME,
4447
TEMPLATE,
4548
FULL
4649
};
4750
};
4851

4952
extern Cvar::Range<Cvar::Cvar<int>> r_vkLogExtendedFunctionNames;
53+
extern Cvar::Cvar<bool> r_vkLogShowThreadID;
5054

5155
// This is kinda ugly, but it's the only way we can make it constexpr
5256

@@ -104,14 +108,18 @@ constexpr const std::string_view FunctionNameTemplate( const std::string_view na
104108
#endif
105109
}
106110

107-
inline std::string Tagged( const std::string& message, const std::source_location& loc = std::source_location::current() ) {
111+
inline std::string Tagged( const std::string& message, const bool useThreadID,
112+
const std::source_location& loc = std::source_location::current() ) {
113+
const std::string threadID = useThreadID ? Str::Format( "Thread %s", TLM.id ) : "";
114+
108115
switch ( r_vkLogExtendedFunctionNames.Get() ) {
116+
case LogExtendedFunctionMode::GLOBAL_NAME:
109117
case LogExtendedFunctionMode::NAME:
110-
return Str::Format( "%s(): %s", FunctionName( loc.function_name() ), message );
118+
return Str::Format( "%s:%s(): %s", threadID, FunctionName( loc.function_name() ), message );
111119
case LogExtendedFunctionMode::TEMPLATE:
112-
return Str::Format( "%s(): %s", FunctionNameTemplate( loc.function_name() ), message );
120+
return Str::Format( "%s:%s(): %s", threadID, FunctionNameTemplate( loc.function_name() ), message );
113121
case LogExtendedFunctionMode::FULL:
114-
return Str::Format( "%s(): %s", loc.function_name(), message );
122+
return Str::Format( "%s:%s(): %s", threadID, loc.function_name(), message );
115123
default:
116124
ASSERT_UNREACHABLE();
117125
}
@@ -120,14 +128,19 @@ inline std::string Tagged( const std::string& message, const std::source_locatio
120128
/* Add this as a base class to be able to use Log::WarnTag() etc.
121129
Allows either specifying a custom name for an object, or otherwise automatically using the class name */
122130
struct Tag {
123-
std::string Tagged( const std::string& message, const std::source_location& loc = std::source_location::current() ) {
131+
std::string Tagged( const std::string& message, const bool useThreadID,
132+
const std::source_location& loc = std::source_location::current() ) {
133+
const std::string threadID = useThreadID ? Str::Format( "Thread %s", TLM.id ) : "";
134+
124135
switch ( r_vkLogExtendedFunctionNames.Get() ) {
136+
case LogExtendedFunctionMode::GLOBAL_NAME:
137+
return Str::Format( "%s:%s: %s", threadID, name, message );
125138
case LogExtendedFunctionMode::NAME:
126-
return Str::Format( "%s:%s(): %s", name, FunctionName( loc.function_name() ), message );
139+
return Str::Format( "%s:%s:%s(): %s", threadID, name, FunctionName( loc.function_name() ), message );
127140
case LogExtendedFunctionMode::TEMPLATE:
128-
return Str::Format( "%s:%s(): %s", name, FunctionNameTemplate( loc.function_name() ), message );
141+
return Str::Format( "%s:%s:%s(): %s", threadID, name, FunctionNameTemplate( loc.function_name() ), message );
129142
case LogExtendedFunctionMode::FULL:
130-
return Str::Format( "%s(): %s", loc.function_name(), message );
143+
return Str::Format( "%s:%s(): %s", threadID, loc.function_name(), message );
131144
default:
132145
ASSERT_UNREACHABLE();
133146
}
@@ -148,9 +161,14 @@ struct Tag {
148161
}
149162
};
150163

151-
#define WarnTag( format, ... ) Warn( Tagged( format ), __VA_ARGS__ )
152-
#define NoticeTag( format, ... ) Warn( Tagged( format ), __VA_ARGS__ )
153-
#define VerboseTag( format, ... ) Warn( Tagged( format ), __VA_ARGS__ )
154-
#define DebugTag( format, ... ) Warn( Tagged( format ), __VA_ARGS__ )
164+
#define WarnTag( format, ... ) Warn( Tagged( format, r_vkLogShowThreadID.Get() ), __VA_ARGS__ )
165+
#define NoticeTag( format, ... ) Warn( Tagged( format, r_vkLogShowThreadID.Get() ), __VA_ARGS__ )
166+
#define VerboseTag( format, ... ) Warn( Tagged( format, r_vkLogShowThreadID.Get() ), __VA_ARGS__ )
167+
#define DebugTag( format, ... ) Warn( Tagged( format, r_vkLogShowThreadID.Get() ), __VA_ARGS__ )
168+
169+
#define WarnTagT( format, ... ) Warn( Tagged( format, true ), __VA_ARGS__ )
170+
#define NoticeTagT( format, ... ) Warn( Tagged( format, true ), __VA_ARGS__ )
171+
#define VerboseTagT( format, ... ) Warn( Tagged( format, true ), __VA_ARGS__ )
172+
#define DebugTagT( format, ... ) Warn( Tagged( format, true ), __VA_ARGS__ )
155173

156174
#endif // TAG_H

0 commit comments

Comments
 (0)