Skip to content
This repository was archived by the owner on Sep 30, 2026. It is now read-only.

Add a scope guard for logging to help us capture all exit paths (#1383) - #1383

Closed
ryanzhang22 wants to merge 1 commit into
pytorch:mainfrom
ryanzhang22:export-D102829439
Closed

ryanzhang22 wants to merge 1 commit into
pytorch:mainfrom
ryanzhang22:export-D102829439

Conversation

@ryanzhang22

@ryanzhang22 ryanzhang22 commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Currently, we mark all areas where we want to indicate stage completion with UST_LOGGER_MARK_COMPLETED. This macro routes us to the UST logger write method which keep a running list of all LOG(ERROR) messages. If no ERROR messages have been logged, we'll mark the stage as a success. Otherwise, we will include the error message in the Scuba write.

With this setup it's pretty easy for us to miss an exit path, especially in the post-processing path where we have a bunch of early exit branches. This change introduces a USTLoggerStageGuard to help automatically manage stage exit without needing to explicitly remember to mark UST_LOGGER_MARK_COMPLETED.

Reviewed By: scotts

Differential Revision: D102829439

@meta-cla meta-cla Bot added the cla signed label Apr 29, 2026
@meta-codesync

meta-codesync Bot commented Apr 29, 2026

Copy link
Copy Markdown

@ryanzhang22 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D102829439.

@meta-codesync meta-codesync Bot changed the title Add a scope guard for logging to help us capture all exit paths Add a scope guard for logging to help us capture all exit paths (#1383) May 1, 2026
ryanzhang22 added a commit to ryanzhang22/kineto that referenced this pull request May 1, 2026
…rch#1383)

Summary:

Currently, we mark all areas where we want to indicate stage completion with `UST_LOGGER_MARK_COMPLETED`. This macro routes us to the UST logger `write` method which keep a running list of all LOG(ERROR) messages. If no ERROR messages have been logged, we'll mark the stage as a success. Otherwise, we will include the error message in the Scuba write.

With this setup it's pretty easy for us to miss an exit path, especially in the post-processing path where we have a bunch of early exit branches. This change introduces a `USTLoggerStageGuard` to help automatically manage stage exit without needing to explicitly remember to mark `UST_LOGGER_MARK_COMPLETED`.

Note that this doesn't help us capture cases where something failed catastrophically and the process immediately exits. Many of these callsites were already pretty well instrumented, this just makes stuff a little cleaner.

Differential Revision: D102829439
@ryanzhang22
ryanzhang22 force-pushed the export-D102829439 branch from 531e801 to 89b8afd Compare May 1, 2026 19:37
ryanzhang22 added a commit to ryanzhang22/kineto that referenced this pull request Jun 1, 2026
…rch#1383)

Summary:

Currently, we mark all areas where we want to indicate stage completion with `UST_LOGGER_MARK_COMPLETED`. This macro routes us to the UST logger `write` method which keep a running list of all LOG(ERROR) messages. If no ERROR messages have been logged, we'll mark the stage as a success. Otherwise, we will include the error message in the Scuba write.

With this setup it's pretty easy for us to miss an exit path, especially in the post-processing path where we have a bunch of early exit branches. This change introduces a `USTLoggerStageGuard` to help automatically manage stage exit without needing to explicitly remember to mark `UST_LOGGER_MARK_COMPLETED`.

Note that this doesn't help us capture cases where something failed catastrophically and the process immediately exits. Many of these callsites were already pretty well instrumented, this just makes stuff a little cleaner.

Reviewed By: scotts

Differential Revision: D102829439
ryanzhang22 added a commit to ryanzhang22/kineto that referenced this pull request Jun 1, 2026
…rch#1383)

Summary:

Currently, we mark all areas where we want to indicate stage completion with `UST_LOGGER_MARK_COMPLETED`. This macro routes us to the UST logger `write` method which keep a running list of all LOG(ERROR) messages. If no ERROR messages have been logged, we'll mark the stage as a success. Otherwise, we will include the error message in the Scuba write.

With this setup it's pretty easy for us to miss an exit path, especially in the post-processing path where we have a bunch of early exit branches. This change introduces a `USTLoggerStageGuard` to help automatically manage stage exit without needing to explicitly remember to mark `UST_LOGGER_MARK_COMPLETED`.

Note that this doesn't help us capture cases where something failed catastrophically and the process immediately exits. Many of these callsites were already pretty well instrumented, this just makes stuff a little cleaner.

Reviewed By: scotts

Differential Revision: D102829439
ryanzhang22 added a commit to ryanzhang22/kineto that referenced this pull request Jun 1, 2026
…rch#1383)

Summary:

Currently, we mark all areas where we want to indicate stage completion with `UST_LOGGER_MARK_COMPLETED`. This macro routes us to the UST logger `write` method which keep a running list of all LOG(ERROR) messages. If no ERROR messages have been logged, we'll mark the stage as a success. Otherwise, we will include the error message in the Scuba write.

With this setup it's pretty easy for us to miss an exit path, especially in the post-processing path where we have a bunch of early exit branches. This change introduces a `USTLoggerStageGuard` to help automatically manage stage exit without needing to explicitly remember to mark `UST_LOGGER_MARK_COMPLETED`.

Note that this doesn't help us capture cases where something failed catastrophically and the process immediately exits. Many of these callsites were already pretty well instrumented, this just makes stuff a little cleaner.

Reviewed By: scotts

Differential Revision: D102829439
ryanzhang22 added a commit to ryanzhang22/kineto that referenced this pull request Jun 1, 2026
…rch#1383)

Summary:

Currently, we mark all areas where we want to indicate stage completion with `UST_LOGGER_MARK_COMPLETED`. This macro routes us to the UST logger `write` method which keep a running list of all LOG(ERROR) messages. If no ERROR messages have been logged, we'll mark the stage as a success. Otherwise, we will include the error message in the Scuba write.

With this setup it's pretty easy for us to miss an exit path, especially in the post-processing path where we have a bunch of early exit branches. This change introduces a `USTLoggerStageGuard` to help automatically manage stage exit without needing to explicitly remember to mark `UST_LOGGER_MARK_COMPLETED`.

Note that this doesn't help us capture cases where something failed catastrophically and the process immediately exits. Many of these callsites were already pretty well instrumented, this just makes stuff a little cleaner.

Reviewed By: scotts

Differential Revision: D102829439
ryanzhang22 added a commit to ryanzhang22/kineto that referenced this pull request Jun 1, 2026
…rch#1383)

Summary:

Currently, we mark all areas where we want to indicate stage completion with `UST_LOGGER_MARK_COMPLETED`. This macro routes us to the UST logger `write` method which keep a running list of all LOG(ERROR) messages. If no ERROR messages have been logged, we'll mark the stage as a success. Otherwise, we will include the error message in the Scuba write.

With this setup it's pretty easy for us to miss an exit path, especially in the post-processing path where we have a bunch of early exit branches. This change introduces a `USTLoggerStageGuard` to help automatically manage stage exit without needing to explicitly remember to mark `UST_LOGGER_MARK_COMPLETED`.

Note that this doesn't help us capture cases where something failed catastrophically and the process immediately exits. Many of these callsites were already pretty well instrumented, this just makes stuff a little cleaner.

Reviewed By: scotts

Differential Revision: D102829439
ryanzhang22 added a commit to ryanzhang22/kineto that referenced this pull request Jun 3, 2026
…rch#1383)

Summary:

Currently, we mark all areas where we want to indicate stage completion with `UST_LOGGER_MARK_COMPLETED`. This macro routes us to the UST logger `write` method which keep a running list of all LOG(ERROR) messages. If no ERROR messages have been logged, we'll mark the stage as a success. Otherwise, we will include the error message in the Scuba write.

With this setup it's pretty easy for us to miss an exit path, especially in the post-processing path where we have a bunch of early exit branches. This change introduces a `USTLoggerStageGuard` to help automatically manage stage exit without needing to explicitly remember to mark `UST_LOGGER_MARK_COMPLETED`.

Reviewed By: scotts

Differential Revision: D102829439
ryanzhang22 added a commit to ryanzhang22/kineto that referenced this pull request Jun 3, 2026
…rch#1383)

Summary:
Pull Request resolved: pytorch#1383

Currently, we mark all areas where we want to indicate stage completion with `UST_LOGGER_MARK_COMPLETED`. This macro routes us to the UST logger `write` method which keep a running list of all LOG(ERROR) messages. If no ERROR messages have been logged, we'll mark the stage as a success. Otherwise, we will include the error message in the Scuba write.

With this setup it's pretty easy for us to miss an exit path, especially in the post-processing path where we have a bunch of early exit branches. This change introduces a `USTLoggerStageGuard` to help automatically manage stage exit without needing to explicitly remember to mark `UST_LOGGER_MARK_COMPLETED`.

Note that this doesn't help us capture cases where something failed catastrophically and the process immediately exits. Many of these callsites were already pretty well instrumented, this just makes stuff a little cleaner.

Differential Revision: D102829439

Reviewed By: scotts
…rch#1383)

Summary:

Currently, we mark all areas where we want to indicate stage completion with `UST_LOGGER_MARK_COMPLETED`. This macro routes us to the UST logger `write` method which keep a running list of all LOG(ERROR) messages. If no ERROR messages have been logged, we'll mark the stage as a success. Otherwise, we will include the error message in the Scuba write.

With this setup it's pretty easy for us to miss an exit path, especially in the post-processing path where we have a bunch of early exit branches. This change introduces a `USTLoggerStageGuard` to help automatically manage stage exit without needing to explicitly remember to mark `UST_LOGGER_MARK_COMPLETED`.

Reviewed By: scotts

Differential Revision: D102829439
ryanzhang22 added a commit to ryanzhang22/kineto that referenced this pull request Jun 4, 2026
…rch#1383)

Summary:

Currently, we mark all areas where we want to indicate stage completion with `UST_LOGGER_MARK_COMPLETED`. This macro routes us to the UST logger `write` method which keep a running list of all LOG(ERROR) messages. If no ERROR messages have been logged, we'll mark the stage as a success. Otherwise, we will include the error message in the Scuba write.

With this setup it's pretty easy for us to miss an exit path, especially in the post-processing path where we have a bunch of early exit branches. This change introduces a `USTLoggerStageGuard` to help automatically manage stage exit without needing to explicitly remember to mark `UST_LOGGER_MARK_COMPLETED`.

Reviewed By: scotts

Differential Revision: D102829439
ryanzhang22 added a commit to ryanzhang22/kineto that referenced this pull request Jun 4, 2026
…rch#1383)

Summary:

Currently, we mark all areas where we want to indicate stage completion with `UST_LOGGER_MARK_COMPLETED`. This macro routes us to the UST logger `write` method which keep a running list of all LOG(ERROR) messages. If no ERROR messages have been logged, we'll mark the stage as a success. Otherwise, we will include the error message in the Scuba write.

With this setup it's pretty easy for us to miss an exit path, especially in the post-processing path where we have a bunch of early exit branches. This change introduces a `USTLoggerStageGuard` to help automatically manage stage exit without needing to explicitly remember to mark `UST_LOGGER_MARK_COMPLETED`.

Reviewed By: scotts

Differential Revision: D102829439
@meta-codesync meta-codesync Bot closed this in ce13b13 Jun 4, 2026
@meta-codesync

meta-codesync Bot commented Jun 4, 2026

Copy link
Copy Markdown

This pull request has been merged in ce13b13.

scotts added a commit to scotts/pytorch that referenced this pull request Jun 16, 2026
Includes the following commits:

- surface HSA queue ID (pytorch/kineto#1425) 1d43601
- Add TypedMetadata to CUPTI activities (pytorch/kineto#1434) 461a26c
- Move around methods so they are accurately described by the comments (pytorch/kineto#1435) ff95265
- Introduce TypedMetadata structs (pytorch/kineto#1433) 965a14d
- Add unit tests for sync/async interleaving behavior (pytorch/kineto#1431) 67612e6
- Restrict on-demand trace output path to a safe directory (pytorch/kineto#1426) 9ea826e
- Add a cancellation state to the state machine and remove syncTraceActive_ (pytorch/kineto#1355) 3289139
- Move state machine from profiler into async handler (pytorch/kineto#1352) eb578c5
- map kernel and copy events to logical stream ID instead of HSA queue ID (pytorch/kineto#1424) 25856f7
- Speedup and fix PyTorch CI build (pytorch/kineto#1428) e675bbb
- Add logging for async rejections (pytorch/kineto#1422) 14becfb
- Make sure we clear the logger observer before starting a new session (pytorch/kineto#1387) a8cae92
- Add a scope guard for logging to help us capture all exit paths (pytorch/kineto#1383) ce13b13
- Remove roctracer support (pytorch/kineto#1419) 2a3a002
pytorchmergebot pushed a commit to pytorch/pytorch that referenced this pull request Jun 16, 2026
Includes the following commits:

- surface HSA queue ID (pytorch/kineto#1425) 1d43601
- Add TypedMetadata to CUPTI activities (pytorch/kineto#1434) 461a26c
- Move around methods so they are accurately described by the comments (pytorch/kineto#1435) ff95265
- Introduce TypedMetadata structs (pytorch/kineto#1433) 965a14d
- Add unit tests for sync/async interleaving behavior (pytorch/kineto#1431) 67612e6
- Restrict on-demand trace output path to a safe directory (pytorch/kineto#1426) 9ea826e
- Add a cancellation state to the state machine and remove syncTraceActive_ (pytorch/kineto#1355) 3289139
- Move state machine from profiler into async handler (pytorch/kineto#1352) eb578c5
- map kernel and copy events to logical stream ID instead of HSA queue ID (pytorch/kineto#1424) 25856f7
- Speedup and fix PyTorch CI build (pytorch/kineto#1428) e675bbb
- Add logging for async rejections (pytorch/kineto#1422) 14becfb
- Make sure we clear the logger observer before starting a new session (pytorch/kineto#1387) a8cae92
- Add a scope guard for logging to help us capture all exit paths (pytorch/kineto#1383) ce13b13
- Remove roctracer support (pytorch/kineto#1419) 2a3a002
Pull Request resolved: #187440
Approved by: https://github.com/ryanzhang22, https://github.com/Skylion007
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
Includes the following commits:

- surface HSA queue ID (pytorch/kineto#1425) 1d43601
- Add TypedMetadata to CUPTI activities (pytorch/kineto#1434) 461a26c
- Move around methods so they are accurately described by the comments (pytorch/kineto#1435) ff95265
- Introduce TypedMetadata structs (pytorch/kineto#1433) 965a14d
- Add unit tests for sync/async interleaving behavior (pytorch/kineto#1431) 67612e6
- Restrict on-demand trace output path to a safe directory (pytorch/kineto#1426) 9ea826e
- Add a cancellation state to the state machine and remove syncTraceActive_ (pytorch/kineto#1355) 3289139
- Move state machine from profiler into async handler (pytorch/kineto#1352) eb578c5
- map kernel and copy events to logical stream ID instead of HSA queue ID (pytorch/kineto#1424) 25856f7
- Speedup and fix PyTorch CI build (pytorch/kineto#1428) e675bbb
- Add logging for async rejections (pytorch/kineto#1422) 14becfb
- Make sure we clear the logger observer before starting a new session (pytorch/kineto#1387) a8cae92
- Add a scope guard for logging to help us capture all exit paths (pytorch/kineto#1383) ce13b13
- Remove roctracer support (pytorch/kineto#1419) 2a3a002
Pull Request resolved: pytorch#187440
Approved by: https://github.com/ryanzhang22, https://github.com/Skylion007
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
Includes the following commits:

- surface HSA queue ID (pytorch/kineto#1425) 1d43601
- Add TypedMetadata to CUPTI activities (pytorch/kineto#1434) 461a26c
- Move around methods so they are accurately described by the comments (pytorch/kineto#1435) ff95265
- Introduce TypedMetadata structs (pytorch/kineto#1433) 965a14d
- Add unit tests for sync/async interleaving behavior (pytorch/kineto#1431) 67612e6
- Restrict on-demand trace output path to a safe directory (pytorch/kineto#1426) 9ea826e
- Add a cancellation state to the state machine and remove syncTraceActive_ (pytorch/kineto#1355) 3289139
- Move state machine from profiler into async handler (pytorch/kineto#1352) eb578c5
- map kernel and copy events to logical stream ID instead of HSA queue ID (pytorch/kineto#1424) 25856f7
- Speedup and fix PyTorch CI build (pytorch/kineto#1428) e675bbb
- Add logging for async rejections (pytorch/kineto#1422) 14becfb
- Make sure we clear the logger observer before starting a new session (pytorch/kineto#1387) a8cae92
- Add a scope guard for logging to help us capture all exit paths (pytorch/kineto#1383) ce13b13
- Remove roctracer support (pytorch/kineto#1419) 2a3a002
Pull Request resolved: pytorch#187440
Approved by: https://github.com/ryanzhang22, https://github.com/Skylion007
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant