develop/projects/rocprofiler-systems/source/lib/rocprof-sys-user/rocprofiler-systems/user.h Source File

develop/projects/rocprofiler-systems/source/lib/rocprof-sys-user/rocprofiler-systems/user.h Source File#

rocprofiler-systems: develop/projects/rocprofiler-systems/source/lib/rocprof-sys-user/rocprofiler-systems/user.h Source File
user.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2022-2025 Advanced Micro Devices, Inc. All Rights Reserved.
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 
23 #ifndef ROCPROFSYS_USER_H_
24 #define ROCPROFSYS_USER_H_
25 
26 #if defined(ROCPROFSYS_USER_SOURCE) && (ROCPROFSYS_USER_SOURCE > 0)
27 # if !defined(ROCPROFSYS_PUBLIC_API)
28 # define ROCPROFSYS_PUBLIC_API __attribute__((visibility("default")))
29 # endif
30 #else
31 # if !defined(ROCPROFSYS_PUBLIC_API)
32 # define ROCPROFSYS_PUBLIC_API
33 # endif
34 #endif
35 
38 
39 #if defined(__cplusplus)
40 extern "C"
41 {
42 #endif
43 
44  /// @fn int rocprofsys_user_start_trace(void)
45  /// @return rocprofsys_user_error_t value
46  /// @brief Enable user defined tracing on this thread and on all subsequently created
47  /// threads.
48  extern int rocprofsys_user_start_trace(void) ROCPROFSYS_PUBLIC_API;
49 
50  /// @fn int rocprofsys_user_stop_trace(void)
51  /// @return rocprofsys_user_error_t value
52  /// @brief Disable user defined tracing on this thread and on all subsequently created
53  /// threads.
54  extern int rocprofsys_user_stop_trace(void) ROCPROFSYS_PUBLIC_API;
55 
56  /// @fn int rocprofsys_user_start_thread_trace(void)
57  /// @return rocprofsys_user_error_t value
58  /// @brief Enable user defined tracing on this specific thread. Does not apply to
59  /// subsequently created threads.
60  extern int rocprofsys_user_start_thread_trace(void) ROCPROFSYS_PUBLIC_API;
61 
62  /// @fn int rocprofsys_user_stop_thread_trace(void)
63  /// @return rocprofsys_user_error_t value
64  /// @brief Disable user defined tracing on this specific thread. Does not apply to
65  /// subsequently created threads.
66  extern int rocprofsys_user_stop_thread_trace(void) ROCPROFSYS_PUBLIC_API;
67 
68  /// @fn int rocprofsys_user_push_region(const char* id)
69  /// @param id The string identifier for the region
70  /// @return rocprofsys_user_error_t value
71  /// @brief Start a user defined region.
72  extern int rocprofsys_user_push_region(const char*) ROCPROFSYS_PUBLIC_API;
73 
74  /// @fn int rocprofsys_user_pop_region(const char* id)
75  /// @param id The string identifier for the region
76  /// @return rocprofsys_user_error_t value
77  /// @brief End a user defined region. In general, user regions should be popped in
78  /// the inverse order that they were pushed, i.e. first-in, last-out (FILO). The
79  /// timemory backend was designed to accommodate asynchronous tasking, where FILO may
80  /// be violated, and will thus compenstate for out-of-order popping, however, the
81  /// perfetto backend will not; thus, out-of-order popping will result in different
82  /// results in timemory vs. perfetto.
83  extern int rocprofsys_user_pop_region(const char*) ROCPROFSYS_PUBLIC_API;
84 
85  /// @typedef rocprofsys_annotation rocprofsys_annotation_t
86  ///
87  /// @fn int rocprofsys_user_push_annotated_region(const char* id,
88  /// rocprofsys_annotation_t* annotations,
89  /// size_t num_annotations)
90  /// @param id The string identifier for the region
91  /// @param annotations Array of @ref rocprofsys_annotation instances
92  /// @param num_annotations Number of annotations
93  /// @return rocprofsys_user_error_t value
94  /// @brief Start a user defined region and adds the annotations to the perfetto trace.
95  extern int rocprofsys_user_push_annotated_region(const char*,
97  size_t) ROCPROFSYS_PUBLIC_API;
98 
99  /// @fn int rocprofsys_user_pop_annotated_region(const char* id,
100  /// rocprofsys_annotation_t* annotations,
101  /// size_t num_annotations)
102  /// @param id The string identifier for the region
103  /// @param annotations Array of @ref rocprofsys_annotation instances
104  /// @param num_annotations Number of annotations
105  /// @return rocprofsys_user_error_t value
106  /// @brief Stop a user defined region and adds the annotations to the perfetto trace.
108  size_t) ROCPROFSYS_PUBLIC_API;
109 
110  /// mark causal progress
111  extern int rocprofsys_user_progress(const char*) ROCPROFSYS_PUBLIC_API;
112 
113  /// mark causal progress with annotations
115  size_t) ROCPROFSYS_PUBLIC_API;
116 
117  /// @fn int rocprofsys_user_configure(rocprofsys_user_configure_mode_t mode,
118  /// rocprofsys_user_callbacks_t inp,
119  /// rocprofsys_user_callbacks_t* out)
120  /// @param[in] mode Specifies how the new callbacks are merged with the old
121  /// callbacks
122  /// @param[in] inp An @ref rocprofsys_user_callbacks instance specifying
123  /// the callbacks which should be invoked by the user API.
124  /// @param[out] out Pointer to @ref rocprofsys_user_callbacks which,
125  /// when non-NULL, will be assigned the former callbacks.
126  /// @return rocprofsys_user_error_t value
127  /// @brief Configure the function pointers invoked by the rocprof-sys user API.
128  /// The initial callbacks are set via the rocprof-sys-dl library when it is loaded but
129  /// the user can user this feature to turn on/off the user API or customize how the
130  /// the user callbacks occur. For example, the user could maintain one set of
131  /// callbacks which discard any annotation data or redirect all unannotated user
132  /// regions to the annotated user regions with annotations about some global state.
133  /// Changing the callbacks is thread-safe but not thread-local.
136  rocprofsys_user_callbacks_t* out) ROCPROFSYS_PUBLIC_API;
137 
138  /// @fn int rocprofsys_user_get_callbacks(int category, void** begin_func, void**
139  /// end_func)
140  /// @param[in] category An @ref ROCPROFSYS_USER_BINDINGS value
141  /// @param[out] begin_func The pointer to the function which corresponds to "starting"
142  /// the category, e.g. rocprofsys_user_start_trace or rocprofsys_user_push_region
143  /// @param[out] end_func The pointer to the function which corresponds to "ending" the
144  /// category, e.g. rocprofsys_user_stop_trace or rocprofsys_user_pop_region
145  /// @return rocprofsys_user_error_t value
146  /// @brief Get the current function pointers for a given category. The initial values
147  /// are assigned by rocprof-sys-dl at start up.
149  ROCPROFSYS_PUBLIC_API;
150 
151  /// @fn const char* rocprofsys_user_error_string(int error_category)
152  /// @param error_category ROCPROFSYS_USER_ERROR value
153  /// @return String descripting the error code
154  /// @brief Return a descriptor for the provided error code
155  extern const char* rocprofsys_user_error_string(int) ROCPROFSYS_PUBLIC_API;
156 
157 #if defined(__cplusplus)
158 }
159 #endif
160 
161 #endif // ROCPROFSYS_USER_H_
A struct containing annotation data to be included in the perfetto trace.
Definition: categories.h:199
enum ROCPROFSYS_USER_CONFIGURE_MODE rocprofsys_user_configure_mode_t
Struct containing the callbacks for the user API.
Definition: types.h:45
const char * rocprofsys_user_error_string(int)
Return a descriptor for the provided error code.
int rocprofsys_user_pop_annotated_region(const char *, rocprofsys_annotation_t *, unsigned long)
int rocprofsys_user_start_thread_trace(void)
Enable user defined tracing on this specific thread. Does not apply to subsequently created threads.
int rocprofsys_user_stop_thread_trace(void)
Disable user defined tracing on this specific thread. Does not apply to subsequently created threads.
int rocprofsys_user_get_callbacks(rocprofsys_user_callbacks_t *)
int rocprofsys_user_annotated_progress(const char *, rocprofsys_annotation_t *, unsigned long)
mark causal progress with annotations
int rocprofsys_user_push_region(const char *)
Start a user defined region.
int rocprofsys_user_configure(rocprofsys_user_configure_mode_t mode, rocprofsys_user_callbacks_t inp, rocprofsys_user_callbacks_t *out)
Configure the function pointers invoked by the rocprof-sys user API. The initial callbacks are set vi...
int rocprofsys_user_push_annotated_region(const char *, rocprofsys_annotation_t *, unsigned long)
int rocprofsys_user_progress(const char *)
mark causal progress
int rocprofsys_user_pop_region(const char *)
End a user defined region. In general, user regions should be popped in the inverse order that they w...
int rocprofsys_user_stop_trace(void)
Disable user defined tracing on this thread and on all subsequently created threads.
int rocprofsys_user_start_trace(void)
Enable user defined tracing on this thread and on all subsequently created threads.