-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add perf benchmark utility. * Update documentation. * Fix. * Fix doc. --------- Co-authored-by: Yong He <yhe@nvidia.com>
- Loading branch information
Showing
21 changed files
with
169 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "slang-performance-profiler.h" | ||
#include "slang-dictionary.h" | ||
|
||
namespace Slang | ||
{ | ||
struct FuncProfileInfo | ||
{ | ||
int invocationCount = 0; | ||
std::chrono::nanoseconds duration = std::chrono::nanoseconds::zero(); | ||
}; | ||
class PerformanceProfilerImpl : public PerformanceProfiler | ||
{ | ||
public: | ||
OrderedDictionary<const char*, FuncProfileInfo> data; | ||
|
||
virtual FuncProfileContext enterFunction(const char* funcName) override | ||
{ | ||
auto entry = data.tryGetValue(funcName); | ||
if (!entry) | ||
{ | ||
data.add(funcName, FuncProfileInfo()); | ||
entry = data.tryGetValue(funcName); | ||
} | ||
entry->invocationCount++; | ||
FuncProfileContext ctx; | ||
ctx.funcName = funcName; | ||
ctx.startTime = std::chrono::high_resolution_clock::now(); | ||
return ctx; | ||
} | ||
virtual void exitFunction(FuncProfileContext ctx) override | ||
{ | ||
auto endTime = std::chrono::high_resolution_clock::now(); | ||
auto duration = endTime - ctx.startTime; | ||
auto entry = data.tryGetValue(ctx.funcName); | ||
entry->duration += duration; | ||
} | ||
virtual void getResult(StringBuilder& out) override | ||
{ | ||
for (auto func : data) | ||
{ | ||
out << func.key << ": \t"; | ||
out << func.value.invocationCount << "\t" << func.value.duration.count()/1000000 << "\n"; | ||
} | ||
} | ||
}; | ||
|
||
PerformanceProfiler* Slang::PerformanceProfiler::getProfiler() | ||
{ | ||
static PerformanceProfilerImpl profiler = PerformanceProfilerImpl(); | ||
return &profiler; | ||
} | ||
} |
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,42 @@ | ||
#ifndef SLANG_CORE_PERFORMANCE_PROFILER_H | ||
#define SLANG_CORE_PERFORMANCE_PROFILER_H | ||
|
||
#include "slang-string.h" | ||
#include <chrono> | ||
|
||
namespace Slang | ||
{ | ||
|
||
struct FuncProfileContext | ||
{ | ||
const char* funcName = nullptr; | ||
std::chrono::time_point<std::chrono::high_resolution_clock> startTime; | ||
}; | ||
|
||
class PerformanceProfiler | ||
{ | ||
public: | ||
virtual FuncProfileContext enterFunction(const char* funcName) = 0; | ||
virtual void exitFunction(FuncProfileContext context) = 0; | ||
virtual void getResult(StringBuilder& out) = 0; | ||
public: | ||
static PerformanceProfiler* getProfiler(); | ||
}; | ||
|
||
struct PerformanceProfilerFuncRAIIContext | ||
{ | ||
FuncProfileContext context; | ||
PerformanceProfilerFuncRAIIContext(const char* funcName) | ||
{ | ||
context = PerformanceProfiler::getProfiler()->enterFunction(funcName); | ||
} | ||
~PerformanceProfilerFuncRAIIContext() | ||
{ | ||
PerformanceProfiler::getProfiler()->exitFunction(context); | ||
} | ||
}; | ||
|
||
#define SLANG_PROFILE PerformanceProfilerFuncRAIIContext _profileContext(__func__) | ||
} | ||
|
||
#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
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
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.