-
Notifications
You must be signed in to change notification settings - Fork 23
Add PerfTrace API and add tracing to XmlHttpRequest #125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+165
−19
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e712f07
Add PerfTrace API
ryantrem 476b464
Add missing include
ryantrem 090c6c1
Update arcana to merged commit
ryantrem 49be36b
Minor cleanup and comments
ryantrem 597b8d0
PR feedback
ryantrem 597018d
Format in VS as requested!
ryantrem 3c088ee
Line break
ryantrem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,11 +1,20 @@ | ||
| set(SOURCES | ||
| "Include/Babylon/Api.h" | ||
| "Include/Babylon/DebugTrace.h" | ||
| "Source/DebugTrace.cpp") | ||
| "Include/Babylon/PerfTrace.h" | ||
| "Source/DebugTrace.cpp" | ||
| "Source/PerfTrace.cpp") | ||
|
|
||
| add_library(Foundation ${SOURCES}) | ||
|
|
||
| target_include_directories(Foundation INTERFACE "Include") | ||
| target_include_directories(Foundation | ||
| PRIVATE "Include/Babylon" | ||
| INTERFACE "Include") | ||
|
|
||
| target_link_libraries(Foundation | ||
| PUBLIC napi | ||
| PRIVATE napi-extensions | ||
| PRIVATE arcana) | ||
|
|
||
| set_property(TARGET Foundation PROPERTY FOLDER Core) | ||
| source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES}) |
This file contains hidden or 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,49 @@ | ||
| #pragma once | ||
| #include <memory> | ||
| #include <napi/env.h> | ||
|
|
||
|
|
||
| namespace Babylon | ||
| { | ||
| namespace PerfTrace | ||
| { | ||
| enum class Level | ||
| { | ||
| // Tracing is a no-op. | ||
| None, | ||
| // Traces time intervals with platform specific profiling APIs. | ||
| Mark, | ||
| // Traces time intervals and also performas platform specific logging. | ||
| Log, | ||
| }; | ||
|
|
||
| // Controls a perf trace interval. When the handle is destructed, the perf interval ends. | ||
| class Handle | ||
| { | ||
| public: | ||
| ~Handle(); | ||
| Handle(const Handle&) = delete; | ||
| Handle& operator=(const Handle&) = delete; | ||
| Handle(Handle&&) noexcept; | ||
| Handle& operator=(Handle&&) noexcept; | ||
|
|
||
| // Transfers ownership of the handle to a napi value. After this call, destructing the passed in handle has no effect. | ||
| static Napi::Value ToNapi(Napi::Env env, Handle handle); | ||
|
|
||
| // Transfers ownership of the handle from a napi value. After this call, destructing the returned handle will end the perf trace interval. | ||
| static Handle FromNapi(Napi::Value napiValue); | ||
|
|
||
| private: | ||
| friend Handle Trace(const char* name); | ||
| Handle(const char* name); | ||
| class Impl; | ||
| std::unique_ptr<Impl> m_impl; | ||
| }; | ||
|
|
||
| // Sets the trace level. It is None by default. | ||
| void SetLevel(Level level); | ||
|
|
||
| // Starts a perf trace interval. Destructing the returned handle ends the perf trace interval. | ||
| Handle Trace(const char* name); | ||
| } | ||
| } |
This file contains hidden or 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,76 @@ | ||
| #include "PerfTrace.h" | ||
| #include <arcana/tracing/trace_region.h> | ||
| #include <cstdint> | ||
| #include <unordered_map> | ||
|
|
||
| namespace | ||
| { | ||
| std::unordered_map<std::uint32_t, Babylon::PerfTrace::Handle> g_traceHandles; | ||
| std::uint32_t g_nextTraceId = 0; | ||
ryantrem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| namespace Babylon | ||
| { | ||
| namespace PerfTrace | ||
| { | ||
| void SetLevel(Level level) | ||
| { | ||
| switch(level) | ||
| { | ||
| case Level::None: | ||
| arcana::trace_region::disable(); | ||
| break; | ||
| case Level::Mark: | ||
| arcana::trace_region::enable(arcana::trace_level::mark); | ||
| break; | ||
| case Level::Log: | ||
| arcana::trace_region::enable(arcana::trace_level::log); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| // Private implementation to hide arcana::trace_region | ||
| class Handle::Impl | ||
| { | ||
| public: | ||
| Impl(const char* name) : m_region(name) {} | ||
| private: | ||
| arcana::trace_region m_region; | ||
| }; | ||
|
|
||
| Handle::Handle(const char* name) | ||
| : m_impl(std::make_unique<Impl>(name)) | ||
| { | ||
| } | ||
|
|
||
| Handle::~Handle() = default; | ||
| Handle::Handle(Handle&&) noexcept = default; | ||
| Handle& Handle::operator=(Handle&&) noexcept = default; | ||
|
|
||
| Handle Trace(const char* name) | ||
| { | ||
| return Handle(name); | ||
| } | ||
|
|
||
| Napi::Value Handle::ToNapi(Napi::Env env, Handle traceHandle) | ||
| { | ||
| g_nextTraceId++; | ||
ryantrem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| g_traceHandles.emplace(g_nextTraceId, std::move(traceHandle)); | ||
| return Napi::Value::From(env, g_nextTraceId); | ||
| } | ||
ryantrem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Handle Handle::FromNapi(Napi::Value napiValue) | ||
| { | ||
| const std::uint32_t traceId = napiValue.As<Napi::Number>().Uint32Value(); | ||
| auto it = g_traceHandles.find(traceId); | ||
| if (it == g_traceHandles.end()) | ||
| { | ||
| throw std::runtime_error("Invalid TraceHandle ID"); | ||
| } | ||
|
|
||
| Handle traceHandle = std::move(it->second); | ||
| g_traceHandles.erase(it); | ||
| return traceHandle; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.