Skip to content

Refactor the code to introduce new Trace object.#307

Draft
BBBela wants to merge 4 commits intofacebookresearch:mainfrom
intel-staging:trace-system-refactor
Draft

Refactor the code to introduce new Trace object.#307
BBBela wants to merge 4 commits intofacebookresearch:mainfrom
intel-staging:trace-system-refactor

Conversation

@BBBela
Copy link
Copy Markdown

@BBBela BBBela commented Nov 17, 2025

What does this PR do?

This PR refactors the code to make future changes to enable vendor-specific behavior easier.
Traces from Intel XPU differ from those from CUDA. To enable using HTA to analyze traces from XPU, there is a need to introduce vendor-specific code in several places of the code.

This PR introduces possibility to create a trace class object, representing single trace file. Such object contains vendor-specific behaviors and data. It can be inherited and adjusted for other vendors in a clean way.

This way we have a list of Trace objects (from several trace files) and each of them is child class adjusted for specific vendor. All have the same API, but they perform vendor-specific computing where needed.

Main stages of refactoring:

  1. It renames Trace object to TraceCollection with all the needed imports and name changes. In this approach the meaning of trace is the trace data from one JSON file and the TraceCollection is collection of several traces from several files.
  2. It introduces singletrace module that contain vendor-specific Trace classes.
  3. It adjusts the whole HTA code to use this newly introduced approach.

With this approach it is much easier to add vendor-specific code to the Trace objects. With this solution we basically create one if-else statement when creating the Trace object when parsing trace file. Everywhere else in the code we use the Trace object's methods and attributes no matter what vendor it came from.

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos, doc improvements)
    • N/A
  • Did you write any new necessary tests?
    This PR is refactoring. HTA tests were adjusted to introduced changes and all pass.
  • Did you make sure to update the docs?
    Went through all the changed functions and their descriptions to adjust docstrings to introduced changes.
  • Did you update the changelog?
    • N/A

Rename Trace class to TraceCollection and its file
trace.py to trace_collection.py.
Adjusted the whole code to work with changed names.

Signed-off-by: Benedykt Bela <benedykt.bela@intel.com>
Signed-off-by: Benedykt Bela <benedykt.bela@intel.com>
The approach is to get the trace DataFrame directly from
TraceCollection object instead of getting Trace object first
and then accessing its DataFrame attribute.

My current approach is to use the Trace objects directly when:
- A method has more than one argument that is aggregated by Trace
  object. This way we reduce the number of parameters in that method.
- A method passes the whole Trace object to another method.
- A method returns more than one attribute that is aggregated by Trace
  object. This way we reduce the number of return values.

With this approach we don't need to modify all the methods that use
pd.DataFrame as input/output parameters.
When there is a need to pass the Trace object to use its methods or
attributes, we can simply adjust the methods that need it.

Signed-off-by: Benedykt Bela <benedykt.bela@intel.com>
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 17, 2025
Signed-off-by: Benedykt Bela <benedykt.bela@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant