-
Notifications
You must be signed in to change notification settings - Fork 119
jobque: self-describing traces — named categories, colors, unit markers #3449
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
+436
−5
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
6216ca1
jobque: self-describing traces — named categories, colors, unit markers
borisbat 5cbe5e8
jobque: marker args serialize signed; palette modulus from length (re…
borisbat 81eb088
dasLLAMA: trace helpers stay que-independent; marker scope comment (r…
borisbat 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| options gen2 | ||
| options indenting = 4 | ||
|
|
||
| module jobque_profile shared public | ||
|
|
||
| //! Self-describing jobque profiling on top of the per-lane event tracer. | ||
| //! | ||
| //! Wraps the ``jobque_trace_*`` builtins with named **categories** (colored | ||
| //! legend entries for the op tags stamped via ``profile_tag``) and **markers** | ||
| //! (instant "unit" events such as ``frame`` or ``token``), so saved traces | ||
| //! carry their own meaning. Files stay perfetto-compatible; the category and | ||
| //! marker tables ride in a ``jobqueProfile`` sibling key viewers read. | ||
|
|
||
| require jobque public | ||
|
|
||
| // dark-theme viewer hues first (lane-timeline palette), then 4 extra distinct hues | ||
| let private DEFAULT_PALETTE = fixed_array<uint>( | ||
| 0x5E96DEu, 0x43B08Au, 0xAC82E4u, 0xC39536u, 0xE08563u, 0x4FC3D0u, | ||
| 0xD678B4u, 0x8385E8u, 0xD8626Au, 0x9BB556u, 0x7A9AAEu, 0xB08968u) | ||
|
|
||
| let public PROFILE_COLOR_BLUE = 0x5E96DEu | ||
| let public PROFILE_COLOR_GREEN = 0x43B08Au | ||
| let public PROFILE_COLOR_PURPLE = 0xAC82E4u | ||
| let public PROFILE_COLOR_AMBER = 0xC39536u | ||
| let public PROFILE_COLOR_CORAL = 0xE08563u | ||
| let public PROFILE_COLOR_TEAL = 0x4FC3D0u | ||
| let public PROFILE_COLOR_MAGENTA = 0xD678B4u | ||
| let public PROFILE_COLOR_INDIGO = 0x8385E8u | ||
|
|
||
| var private g_categoryIds : table<string; int> | ||
| var private g_usedCategoryIds : table<int> | ||
| var private g_markerIds : table<string; int> | ||
| var private g_nextCategoryId = 1 | ||
|
|
||
| def private resolve_color(name : string; color : uint) : uint { | ||
| if (color != 0u) return color | ||
| return DEFAULT_PALETTE[int(hash(name) % uint64(length(DEFAULT_PALETTE)))] | ||
| } | ||
|
|
||
| def public profile_start(events_per_lane : int = 65536) { | ||
| //! Arm the per-lane trace rings (`events_per_lane` events each; full lanes stop recording). | ||
| jobque_trace_start(events_per_lane) | ||
| } | ||
|
|
||
| def public profile_stop() { | ||
| //! Disarm tracing. Must be called before `profile_save`. | ||
| jobque_trace_stop() | ||
| } | ||
|
|
||
| def public profile_save(path : string) : bool { | ||
| //! Write the recorded trace as perfetto-compatible JSON, including the category and | ||
| //! marker registries. Returns false when tracing is still on or nothing was recorded. | ||
| return jobque_trace_save(path) | ||
| } | ||
|
|
||
| def public profile_tag(tag : int) { | ||
| //! Stamp the current op tag; subsequent chain publishes carry it (viewer color channel). | ||
| jobque_trace_tag(tag) | ||
| } | ||
|
|
||
| def public profile_category(id : int; name : string; color : uint = 0u) { | ||
| //! Register a named category for an existing tag id (`color` is 0xRRGGBB; | ||
| //! 0 picks from the default palette by name hash). | ||
| g_usedCategoryIds |> insert(id) | ||
| g_categoryIds[name] = id | ||
| jobque_trace_category(id, name, resolve_color(name, color)) | ||
| } | ||
|
|
||
| def public profile_category(name : string; color : uint = 0u) : int { | ||
| //! Register a named category with an auto-assigned tag id (idempotent per name). | ||
| //! Returns the tag to stamp via `profile_tag`. | ||
| var id = g_categoryIds?[name] ?? -1 | ||
| if (id < 0) { | ||
| while (g_usedCategoryIds |> key_exists(g_nextCategoryId)) { | ||
| g_nextCategoryId++ | ||
| } | ||
| id = g_nextCategoryId++ | ||
| g_usedCategoryIds |> insert(id) | ||
| g_categoryIds[name] = id | ||
| } | ||
| jobque_trace_category(id, name, resolve_color(name, color)) | ||
| return id | ||
| } | ||
|
|
||
| def public profile_marker_id(name : string) : int { | ||
| //! Register/look up a marker kind (e.g. "token", "frame"); idempotent per name. | ||
| let existing = g_markerIds?[name] ?? -1 | ||
| if (existing >= 0) return existing | ||
| let id = jobque_trace_marker_name(name) | ||
| g_markerIds[name] = id | ||
| return id | ||
| } | ||
|
|
||
| def public profile_marker(id : int; arg : int = 0) { | ||
| //! Stamp an instant unit boundary on the caller lane (no-op when tracing is off). | ||
| jobque_trace_marker(id, arg) | ||
| } | ||
|
|
||
| def public profile_marker(name : string; arg : int = 0) { | ||
| //! Convenience form of `profile_marker`; prefer the id form in hot loops. | ||
| jobque_trace_marker(profile_marker_id(name), arg) | ||
| } |
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
1 change: 1 addition & 0 deletions
1
...ce/stdlib/handmade/function-jobque-jobque_trace_category-0x9e6a5d0ed05ba6da.rst
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 @@ | ||
| Registers a named category for a trace op tag (the id stamped via ``jobque_trace_tag``), with a display color packed as 0xRRGGBB. Re-registering an id updates its name and color. The registry persists across trace sessions; ``jobque_trace_save`` writes it into the file's ``jobqueProfile`` header so viewers can label and color events without hardcoded knowledge. |
1 change: 1 addition & 0 deletions
1
...urce/stdlib/handmade/function-jobque-jobque_trace_marker-0x23d3c8a055ea0170.rst
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 @@ | ||
| Stamps an instant unit-boundary event (kind id from ``jobque_trace_marker_name``, plus a free-form ``arg`` such as the token index) on the caller lane. No-op when tracing is off — cheap enough for per-token/per-frame loops. Saved as a perfetto instant event, so unit boundaries render natively in Perfetto and unit-aware viewers can navigate trace windows by unit. |
1 change: 1 addition & 0 deletions
1
...stdlib/handmade/function-jobque-jobque_trace_marker_name-0x11d82ed54aded050.rst
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 @@ | ||
| Registers a marker kind (a "unit" name such as "token", "frame", "layer") and returns its id for ``jobque_trace_marker``. Idempotent — re-registering the same name returns the existing id. Saved traces list all marker kinds in the ``jobqueProfile`` header. |
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,37 @@ | ||
| The JOBQUE_PROFILE module wraps the low-level ``jobque_trace_*`` builtins into a | ||
| self-describing profiling API: named **categories** with colors for the op tags | ||
| stamped via ``profile_tag``, and **markers** — instant "unit" events such as | ||
| ``token`` or ``frame`` — so saved traces carry their own legend and are navigable | ||
| unit-to-unit. Files remain perfetto-compatible; the category and marker tables | ||
| ride in a ``jobqueProfile`` sibling key that Perfetto ignores. | ||
|
|
||
| See also :doc:`jobque` for the underlying event tracer. | ||
|
|
||
| All functions and symbols are in "jobque_profile" module, use require to get access to it. | ||
|
|
||
| .. code-block:: das | ||
|
|
||
| require daslib/jobque_profile | ||
|
|
||
| Example: | ||
|
|
||
| .. code-block:: das | ||
|
|
||
| require daslib/jobque_boost | ||
| require daslib/jobque_profile | ||
|
|
||
| [export] | ||
| def main() { | ||
| with_job_que() { | ||
| let heavy = profile_category("heavy op") // auto id + palette color | ||
| let tok = profile_marker_id("token") | ||
| profile_start(65536) | ||
| for (i in range(4)) { | ||
| profile_marker(tok, i) // unit boundary | ||
| profile_tag(heavy) | ||
| // ... dispatch work ... | ||
| } | ||
| profile_stop() | ||
| profile_save("trace.json") // open in Perfetto or the timeline viewer | ||
| } | ||
| } |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.