diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-03-02 12:30:25 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-02 12:30:25 -0500 |
| commit | b85ca6f86d46ee3c4d5784d0bd4ebc8509e2a9bd (patch) | |
| tree | e91ce5470664cbd623374534e69e4bfc8a0f1840 | |
| parent | 6e9f407ad42ce635528b30f21366f903903a3682 (diff) | |
Feature/profile tool (#1251)
* WIP slang-profile
* Turn on symbols needed for profile.
* Remove calls to slang API from core as doing so broke profiling information.
Fix premake so slang-profile works on VS.
| -rw-r--r-- | premake5.lua | 41 | ||||
| -rw-r--r-- | source/core/slang-std-writers.cpp | 8 | ||||
| -rw-r--r-- | source/core/slang-std-writers.h | 5 | ||||
| -rw-r--r-- | tools/slang-profile/slang-profile-main.cpp | 41 | ||||
| -rw-r--r-- | tools/slang-reflection-test/slang-reflection-test-main.cpp | 6 | ||||
| -rw-r--r-- | tools/slang-test/slangc-tool.cpp | 7 |
6 files changed, 92 insertions, 16 deletions
diff --git a/premake5.lua b/premake5.lua index 93bbd0569..ec17bd267 100644 --- a/premake5.lua +++ b/premake5.lua @@ -92,11 +92,20 @@ newoption { allowed = { { "true", "True"}, { "false", "False" } } } +newoption { + trigger = "enable-profile", + description = "(Optional) If true will enable slang-profile tool - suitable for gprof usage on linux", + value = "bool", + default = "false", + allowed = { { "true", "True"}, { "false", "False" } } +} + buildLocation = _OPTIONS["build-location"] executeBinary = (_OPTIONS["execute-binary"] == "true") targetDetail = _OPTIONS["target-detail"] buildGlslang = (_OPTIONS["build-glslang"] == "true") enableCuda = (_OPTIONS["enable-cuda"] == "true") +enableProfile = (_OPTIONS["enable-profile"] == "true") -- cudaPath is only set if cuda is enabled, and CUDA_PATH enviromental variable is set cudaPath = nil @@ -734,6 +743,38 @@ standardProject "slang" buildinputs { "%{cfg.targetdir}/slang-generate" .. executableSuffix } end +if enableProfile then + tool "slang-profile" + uuid "375CC87D-F34A-4DF1-9607-C5C990FD6227" + + -- gprof needs symbols + symbols "On" + + dependson { "slang" } + + includedirs { "external/spirv-headers/include" } + + defines { "SLANG_STATIC" } + + -- The `standardProject` operation already added all the code in + -- `source/slang/*`, but we also want to incldue the umbrella + -- `slang.h` header in this prject, so we do that manually here. + files { "slang.h" } + + files { "source/core/core.natvis" } + + -- Add the slang source + addSourceDir "source/slang" + + includedirs { "." } + links { "core"} + + filter { "system:linux" } + linkoptions{ "-pg" } + buildoptions{ "-pg" } + +end + if buildGlslang then -- diff --git a/source/core/slang-std-writers.cpp b/source/core/slang-std-writers.cpp index 8b2f6f604..bf3ae72fd 100644 --- a/source/core/slang-std-writers.cpp +++ b/source/core/slang-std-writers.cpp @@ -30,13 +30,5 @@ namespace Slang return defaults; } -void StdWriters::setRequestWriters(SlangCompileRequest* request) -{ - for (int i = 0; i < SLANG_WRITER_CHANNEL_COUNT_OF; ++i) - { - spSetWriter(request, SlangWriterChannel(i), m_writers[i]); - } -} - } diff --git a/source/core/slang-std-writers.h b/source/core/slang-std-writers.h index 8ecb89227..d193bfe0c 100644 --- a/source/core/slang-std-writers.h +++ b/source/core/slang-std-writers.h @@ -12,12 +12,9 @@ class StdWriters: public RefObject { public: - ISlangWriter * getWriter(SlangWriterChannel chan) const { return m_writers[chan]; } + ISlangWriter* getWriter(SlangWriterChannel chan) const { return m_writers[chan]; } void setWriter(SlangWriterChannel chan, ISlangWriter* writer) { m_writers[chan] = writer; } - /// Set the writers on the SlangCompileRequest - void setRequestWriters(SlangCompileRequest* request); - /// Ctor StdWriters() {} diff --git a/tools/slang-profile/slang-profile-main.cpp b/tools/slang-profile/slang-profile-main.cpp new file mode 100644 index 000000000..19fb36604 --- /dev/null +++ b/tools/slang-profile/slang-profile-main.cpp @@ -0,0 +1,41 @@ +// slang-profile-main.cpp + +#include "../../source/core/slang-io.h" +#include "../../source/core/slang-std-writers.h" + +#include "../../source/core/slang-process-util.h" + +#include "../../slang-com-helper.h" + +#include "../../source/core/slang-string-util.h" + +using namespace Slang; + +SlangResult innerMain(int argc, char** argv) +{ + auto stdWriters = StdWriters::initDefaultSingleton(); + + // Time the creation of the session + { + const auto startTick = ProcessUtil::getClockTick(); + + ComPtr<slang::IGlobalSession> slangSession; + slangSession.attach(spCreateSession(nullptr)); + + const auto endTick = ProcessUtil::getClockTick(); + + printf("Ticks %f\n", double(endTick - startTick) / ProcessUtil::getClockFrequency()); + return SLANG_OK; + } + + return SLANG_OK; +} + +int main(int argc, char** argv) +{ + const SlangResult res = innerMain(argc, argv); +#ifdef _MSC_VER + _CrtDumpMemoryLeaks(); +#endif + return SLANG_SUCCEEDED(res) ? 0 : 1; +} diff --git a/tools/slang-reflection-test/slang-reflection-test-main.cpp b/tools/slang-reflection-test/slang-reflection-test-main.cpp index 7cbcc9878..ba6096f20 100644 --- a/tools/slang-reflection-test/slang-reflection-test-main.cpp +++ b/tools/slang-reflection-test/slang-reflection-test-main.cpp @@ -1272,8 +1272,10 @@ SLANG_TEST_TOOL_API SlangResult innerMain(Slang::StdWriters* stdWriters, SlangSe Slang::StdWriters::setSingleton(stdWriters); SlangCompileRequest* request = spCreateCompileRequest(session); - - stdWriters->setRequestWriters(request); + for (int i = 0; i < SLANG_WRITER_CHANNEL_COUNT_OF; ++i) + { + spSetWriter(request, SlangWriterChannel(i), stdWriters->getWriter(i)); + } char const* appName = "slang-reflection-test"; if (argc > 0) appName = argv[0]; diff --git a/tools/slang-test/slangc-tool.cpp b/tools/slang-test/slangc-tool.cpp index 6c9645b54..da810fa88 100644 --- a/tools/slang-test/slangc-tool.cpp +++ b/tools/slang-test/slangc-tool.cpp @@ -55,8 +55,11 @@ SlangResult SlangCTool::innerMain(StdWriters* stdWriters, SlangSession* session, spSetCommandLineCompilerMode(compileRequest); // Do any app specific configuration - stdWriters->setRequestWriters(compileRequest); - + for (int i = 0; i < SLANG_WRITER_CHANNEL_COUNT_OF; ++i) + { + spSetWriter(compileRequest, SlangWriterChannel(i), stdWriters->getWriter(i)); + } + SlangResult res = _compile(compileRequest, argc, argv); // Now that we are done, clean up after ourselves |
