Skip to content
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

Support external (i.e. user-defined) trace annotations #195

Merged
merged 5 commits into from
Nov 11, 2022

Conversation

jrmadsen
Copy link
Collaborator

@jrmadsen jrmadsen commented Nov 3, 2022

  • tweaked the python examples to be more balanced
  • updated the user-api example to conform to user API changes
  • moved the get/set for State and ThreadState to state.{hpp,cpp}
  • introduced user-provided trace annotations
  • added perfetto python category
  • moved coverage impl files around
  • created enumerations for mapping category enums to category types
  • created enumerations for mapping annotation type enums to annotation values
  • moved tracing::add_perfetto_annotations to tracing/annotation.hpp
  • utility make_index_sequence_range
  • libomnitrace-dl: omnitrace_push_category_region
  • libomnitrace-dl: omnitrace_pop_category_region
  • libomnitrace-user: omnitrace_user_push_annotated_region
  • libomnitrace-user: omnitrace_user_pop_annotated_region
  • libpyomnitrace: support extra annotations via annotate_trace config value
    • filename
    • line
    • last attempted instr in bytecode (lasti)
    • argcount
    • num local variables
    • stacksize
  • omnitrace-python: -a / --annotate-traces option

Perfetto Python Annotations

Screen Shot 2022-11-03 at 11 45 22 AM

Updated User API

#include <omnitrace/user.h>

int
custom_push_region(const char* name);

namespace
{
// instance holding custom callbacks
omnitrace_user_callbacks_t custom_callbacks   = OMNITRACE_USER_CALLBACKS_INIT;
// instance holding former callbacks
omnitrace_user_callbacks_t original_callbacks = OMNITRACE_USER_CALLBACKS_INIT;
}  // namespace

int
main(int argc, char** argv)
{
    // set the callback for pushing a region
    custom_callbacks.push_region = &custom_push_region;
    // update the config
    //   OMNITRACE_USER_UNION_CONFIG will only update config with non-null callbacks
    //   OMNITRACE_USER_REPLACE_CONFIG will swap in entire config
    omnitrace_user_configure(OMNITRACE_USER_UNION_CONFIG, custom_callbacks,
                             &original_callbacks);

    // ... etc. ...
    return 0;
}

int
custom_push_region(const char* name)
{
    // check we have the push_annotated_region callback
    if(!original_callbacks.push_annotated_region)
        return OMNITRACE_USER_ERROR_NO_BINDING;

    // store data for annotation
    int32_t _err = errno;
    char*   _msg = nullptr;
    char    _buff[1024];
    if(_err != 0) _msg = strerror_r(_err, _buff, sizeof(_buff));

    // annotate the global errno and if non-zero, annotate the error string
    omnitrace_annotation_t _annotations[] = {
        { "errno", OMNITRACE_INT32, &_err }, { "strerror", OMNITRACE_STRING, _msg }
    };

    errno = 0;  // reset errno
    return (*original_callbacks.push_annotated_region)(
        name, _annotations, sizeof(_annotations) / sizeof(omnitrace_annotation_t));
}

@jrmadsen jrmadsen added enhancement New feature or request perfetto Issue affects/involves perfetto features/capabilities libomnitrace Involves omnitrace library libomnitrace-dl Involves omnitrace-dl library libomnitrace-user Involves omnitrace-user library omnitrace-python Involves the omnitrace python profiler executable libpyomnitrace Involves the omnitrace python bindings testing Extends/improves/modifies testing examples Adds new example or modifies existing example cmake Modifies the CMake build system labels Nov 3, 2022
@jrmadsen jrmadsen requested a review from koomie November 3, 2022 16:58
@jrmadsen
Copy link
Collaborator Author

jrmadsen commented Nov 3, 2022

@koomie Looking for feedback on how the user-defined annotations should be specified. Example at the bottom of the first comment. LMK if you have any questions.

- tweaked the python examples to be more balanced
- updated the user-api example to conform to user API changes
- moved the get/set for State and ThreadState to state.{hpp,cpp}
- introduced user-provided trace annotations
- added perfetto python category
- moved coverage impl files around
- created enumerations for mapping category enums to category types
- created enumerations for mapping annotation type enums to annotation values
- moved tracing::add_perfetto_annotations to tracing/annotation.hpp
- utility make_index_sequence_range
- libomnitrace-dl: omnitrace_push_category_region
- libomnitrace-dl: omnitrace_pop_category_region
- libomnitrace-user: omnitrace_user_push_annotated_region
- libomnitrace-user: omnitrace_user_pop_annotated_region
- libpyomnitrace: support extra annotations via annotate_trace config value
  - filename
  - line
  - last attempted instr in bytecode (lasti)
  - argcount
  - num local variables
  - stacksize
- omnitrace-python: -a / --annotate-traces option
@jrmadsen jrmadsen merged commit 642b6b9 into ROCm:main Nov 11, 2022
@jrmadsen jrmadsen deleted the user-trace-annotations branch November 11, 2022 13:31
jrmadsen added a commit to jrmadsen/omnitrace that referenced this pull request Feb 2, 2023
* Support external (i.e. user-defined) trace annotations

- tweaked the python examples to be more balanced
- updated the user-api example to conform to user API changes
- moved the get/set for State and ThreadState to state.{hpp,cpp}
- introduced user-provided trace annotations
- added perfetto python category
- moved coverage impl files around
- created enumerations for mapping category enums to category types
- created enumerations for mapping annotation type enums to annotation values
- moved tracing::add_perfetto_annotations to tracing/annotation.hpp
- utility make_index_sequence_range
- libomnitrace-dl: omnitrace_push_category_region
- libomnitrace-dl: omnitrace_pop_category_region
- libomnitrace-user: omnitrace_user_push_annotated_region
- libomnitrace-user: omnitrace_user_pop_annotated_region
- libpyomnitrace: support extra annotations via annotate_trace config value
  - filename
  - line
  - last attempted instr in bytecode (lasti)
  - argcount
  - num local variables
  - stacksize
- omnitrace-python: -a / --annotate-traces option

* tweak ubuntu-focal workflow

* Fix installation of omnitrace-user headers

* ubuntu-focal-codecov workflow update

- Install texinfo

* Update timemory submodule
jrmadsen added a commit to jrmadsen/omnitrace that referenced this pull request Feb 2, 2023
* Support external (i.e. user-defined) trace annotations

- tweaked the python examples to be more balanced
- updated the user-api example to conform to user API changes
- moved the get/set for State and ThreadState to state.{hpp,cpp}
- introduced user-provided trace annotations
- added perfetto python category
- moved coverage impl files around
- created enumerations for mapping category enums to category types
- created enumerations for mapping annotation type enums to annotation values
- moved tracing::add_perfetto_annotations to tracing/annotation.hpp
- utility make_index_sequence_range
- libomnitrace-dl: omnitrace_push_category_region
- libomnitrace-dl: omnitrace_pop_category_region
- libomnitrace-user: omnitrace_user_push_annotated_region
- libomnitrace-user: omnitrace_user_pop_annotated_region
- libpyomnitrace: support extra annotations via annotate_trace config value
  - filename
  - line
  - last attempted instr in bytecode (lasti)
  - argcount
  - num local variables
  - stacksize
- omnitrace-python: -a / --annotate-traces option

* tweak ubuntu-focal workflow

* Fix installation of omnitrace-user headers

* ubuntu-focal-codecov workflow update

- Install texinfo

* Update timemory submodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Modifies the CMake build system enhancement New feature or request examples Adds new example or modifies existing example libomnitrace Involves omnitrace library libomnitrace-dl Involves omnitrace-dl library libomnitrace-user Involves omnitrace-user library libpyomnitrace Involves the omnitrace python bindings omnitrace-python Involves the omnitrace python profiler executable perfetto Issue affects/involves perfetto features/capabilities testing Extends/improves/modifies testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant