-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FancyZones] Trace various function calls (#10183)
* Implement CallTracer * Add CallTracer to various places * Newline * Fix unit tests not compiling for some reason * Add macro remove some trace calls * Add indentation * Add semicolon * Update src/modules/fancyzones/lib/CallTracer.cpp Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com> * Actually indent/unindent output * Fix initial indent level Co-authored-by: Enrico Giordani <enrico.giordani@gmail.com> Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com>
- Loading branch information
1 parent
9a061d7
commit 7377ef5
Showing
10 changed files
with
123 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "pch.h" | ||
#include "CallTracer.h" | ||
#include <thread> | ||
|
||
namespace | ||
{ | ||
// Non-localizable | ||
const std::string entering = " Enter"; | ||
const std::string exiting = " Exit"; | ||
|
||
std::mutex indentLevelMutex; | ||
std::map<std::thread::id, int> indentLevel; | ||
|
||
std::string GetIndentation() | ||
{ | ||
std::unique_lock lock(indentLevelMutex); | ||
int level = indentLevel[std::this_thread::get_id()]; | ||
|
||
if (level <= 0) | ||
{ | ||
return {}; | ||
} | ||
else | ||
{ | ||
return std::string(2 * min(level, 64) - 1, ' ') + " - "; | ||
} | ||
} | ||
|
||
void Indent() | ||
{ | ||
std::unique_lock lock(indentLevelMutex); | ||
indentLevel[std::this_thread::get_id()]++; | ||
} | ||
|
||
void Unindent() | ||
{ | ||
std::unique_lock lock(indentLevelMutex); | ||
indentLevel[std::this_thread::get_id()]--; | ||
} | ||
} | ||
|
||
CallTracer::CallTracer(const char* functionName) : | ||
functionName(functionName) | ||
{ | ||
Logger::trace((GetIndentation() + functionName + entering).c_str()); | ||
Indent(); | ||
} | ||
|
||
CallTracer::~CallTracer() | ||
{ | ||
Unindent(); | ||
Logger::trace((GetIndentation() + functionName + exiting).c_str()); | ||
} |
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,13 @@ | ||
#pragma once | ||
|
||
#include "common/logger/logger.h" | ||
|
||
#define _TRACER_ CallTracer callTracer(__FUNCTION__) | ||
|
||
class CallTracer | ||
{ | ||
std::string functionName; | ||
public: | ||
CallTracer(const char* functionName); | ||
~CallTracer(); | ||
}; |
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
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