Skip to content

Commit efa77e9

Browse files
committed
Add comments
1 parent 0948b0f commit efa77e9

File tree

5 files changed

+108
-4
lines changed

5 files changed

+108
-4
lines changed

src/mercury.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,9 @@ HG_Finalize(hg_class_t *hg_class)
10191019
hg_thread_spin_destroy(&private_class->register_lock);
10201020
free(private_class);
10211021

1022+
/* Finalize PVAR data structures */
1023+
hg_prof_pvar_finalize();
1024+
10221025
done:
10231026
return ret;
10241027
}
@@ -1929,7 +1932,6 @@ HG_Forward(hg_handle_t handle, hg_cb_t callback, void *arg, void *in_struct)
19291932
HG_Error_to_string(ret));
19301933

19311934
/* PVAR profiling support: Increment the value of the PVAR with the name "hg_pvar_hg_forward_count" */
1932-
fprintf(stderr, "[MERCURY_PROF_INTERFACE] Incrementing the value of PVAR with name hg_pvar_hg_forward_count\n");
19331935
HG_PROF_PVAR_COUNTER_INC(hg_pvar_hg_forward_count, 1);
19341936

19351937
done:

src/mercury_prof_interface.c

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ HG_Prof_init(hg_class_t *hg_class) {
9292

9393
hg_prof_set_is_initialized(hg_private_class);
9494
hg_private_class->num_pvars = NUM_PVARS;
95+
hg_private_class->session = NULL;
9596

9697
return HG_SUCCESS;
9798
}
@@ -104,9 +105,9 @@ HG_Prof_finalize(hg_class_t *hg_class) {
104105

105106
if(hg_prof_get_is_initialized(hg_private_class)) {
106107
hg_prof_set_is_initialized(hg_private_class);
108+
hg_private_class->session = NULL;
107109
}
108110

109-
fprintf(stderr, "[MERCURY_PROF_INTERFACE] Successfully shutting down profiling interface\n");
110111
return HG_SUCCESS;
111112
}
112113

@@ -168,6 +169,21 @@ HG_Prof_pvar_session_create(hg_class_t *hg_class, hg_prof_pvar_session_t *sessio
168169
return HG_SUCCESS;
169170
}
170171

172+
/*---------------------------------------------------------------------------*/
173+
hg_return_t
174+
HG_Prof_pvar_session_destroy(hg_class_t *hg_class, hg_prof_pvar_session_t *session) {
175+
176+
struct hg_private_class *hg_private_class = (struct hg_private_class *)(hg_class);
177+
178+
if(!hg_prof_get_is_initialized(hg_private_class))
179+
return HG_NA_ERROR;
180+
181+
free((*session)->pvar_handle_array);
182+
free((*session));
183+
hg_private_class->session = NULL;
184+
185+
return HG_SUCCESS;
186+
}
171187
/*---------------------------------------------------------------------------*/
172188
hg_return_t
173189
HG_Prof_pvar_handle_alloc(hg_prof_pvar_session_t session, int pvar_index, void *obj_handle, hg_prof_pvar_handle_t *handle, int *count) {
@@ -201,7 +217,22 @@ HG_Prof_pvar_handle_alloc(hg_prof_pvar_session_t session, int pvar_index, void *
201217
/* Return handle */
202218
*handle = s.pvar_handle_array[pvar_index];
203219

204-
fprintf(stderr, "[MERCURY_PROF_INTERFACE] Successfully allocated handle for PVAR: %s\n", (*s.pvar_handle_array[pvar_index]).name);
220+
return HG_SUCCESS;
221+
}
222+
223+
/*---------------------------------------------------------------------------*/
224+
hg_return_t
225+
HG_Prof_pvar_handle_free(hg_prof_pvar_session_t session, int pvar_index, hg_prof_pvar_handle_t *handle) {
226+
227+
if(!hg_prof_get_session_is_initialized(session))
228+
return HG_NA_ERROR;
229+
230+
231+
struct hg_prof_pvar_session s = *session;
232+
assert(s.pvar_handle_array[pvar_index] == *handle);
233+
free(s.pvar_handle_array[pvar_index]);
234+
s.pvar_handle_array[pvar_index] = NULL;
235+
*handle = NULL;
205236

206237
return HG_SUCCESS;
207238
}
@@ -217,6 +248,17 @@ HG_Prof_pvar_start(hg_prof_pvar_session_t session, hg_prof_pvar_handle_t handle)
217248
return HG_SUCCESS;
218249
}
219250

251+
/*---------------------------------------------------------------------------*/
252+
hg_return_t
253+
HG_Prof_pvar_stop(hg_prof_pvar_session_t session, hg_prof_pvar_handle_t handle) {
254+
if(!hg_prof_get_session_is_initialized(session))
255+
return HG_NA_ERROR;
256+
257+
if (!(*handle).continuous && ((*handle).is_started))
258+
(*handle).is_started = 0;
259+
return HG_SUCCESS;
260+
}
261+
220262
/*---------------------------------------------------------------------------*/
221263
hg_return_t
222264
HG_Prof_pvar_read(hg_prof_pvar_session_t session, hg_prof_pvar_handle_t handle, void *buf) {

src/mercury_prof_interface.h

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,27 @@ HG_PUBLIC hg_return_t
4141
HG_Prof_finalize(hg_class_t *hg_class);
4242

4343
/**
44-
* Create a session. In this case, return a reference to the default session that is currently supported.
44+
* Create a session.
4545
*
46+
* \param hg_class [IN/OUT] pointer to HG_CLASS
4647
* \param session [IN/OUT] pointer to PVAR session object
4748
*
4849
* \return HG_SUCCESS or corresponding HG error code
4950
*/
5051
HG_PUBLIC hg_return_t
5152
HG_Prof_pvar_session_create(hg_class_t *hg_class, hg_prof_pvar_session_t *session);
5253

54+
/**
55+
* Destroy a session.
56+
*
57+
* \param hg_class [IN/OUT] pointer to HG_CLASS
58+
* \param session [IN/OUT] pointer to PVAR session object
59+
*
60+
* \return HG_SUCCESS or corresponding HG error code
61+
*/
62+
HG_PUBLIC hg_return_t
63+
HG_Prof_pvar_session_destroy(hg_class_t *hg_class, hg_prof_pvar_session_t *session);
64+
5365
/**
5466
* Client-side API to retrieve the number of PVARs currently exported.
5567
*
@@ -96,6 +108,19 @@ HG_PUBLIC hg_return_t
96108
HG_Prof_pvar_handle_alloc(hg_prof_pvar_session_t session,
97109
int pvar_index, void *obj_handle, hg_prof_pvar_handle_t *handle, int *count);
98110

111+
/**
112+
* Free handle for a PVAR at a given index.
113+
*
114+
* \param session [IN] opaque PVAR session object
115+
* \param pvar_index [IN] PVAR index
116+
* \param handle [IN/OUT] pointer to the opaque PVAR handle object that is returned to the calling client
117+
*
118+
* \return HG_SUCCESS or corresponding HG error code
119+
*/
120+
HG_PUBLIC hg_return_t
121+
HG_Prof_pvar_handle_free(hg_prof_pvar_session_t session,
122+
int pvar_index, hg_prof_pvar_handle_t *handle);
123+
99124
/**
100125
* Start the PVAR is it is not continuous and has not been started yet.
101126
*
@@ -107,6 +132,17 @@ HG_Prof_pvar_handle_alloc(hg_prof_pvar_session_t session,
107132
HG_PUBLIC hg_return_t
108133
HG_Prof_pvar_start(hg_prof_pvar_session_t session, hg_prof_pvar_handle_t handle);
109134

135+
/**
136+
* Stop the PVAR is it is not continuous and has been started.
137+
*
138+
* \param session [IN] opaque PVAR session object
139+
* \param handle [IN] opaque PVAR handle object
140+
*
141+
* \return HG_SUCCESS or corresponding HG error code
142+
*/
143+
HG_PUBLIC hg_return_t
144+
HG_Prof_pvar_stop(hg_prof_pvar_session_t session, hg_prof_pvar_handle_t handle);
145+
110146
/**
111147
* Read the value of the PVAR when the client supplies the handle.
112148
* Note that the handle is necessary as the input (instead of the pvar_index) because there may be multiple PVAR sessions in flight.

src/mercury_prof_pvar_impl.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,12 @@ return HG_SUCCESS;
105105
}
106106

107107
/*---------------------------------------------------------------------------*/
108+
hg_return_t
109+
hg_prof_pvar_finalize() {
110+
111+
/*Finalize internal PVAR data structures*/
112+
hg_hash_table_free(pvar_table);
113+
pvar_table = NULL;
114+
115+
return HG_SUCCESS;
116+
}

src/mercury_prof_pvar_impl.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ typedef struct hg_prof_pvar_data_t hg_prof_pvar_data_t;
6767
hg_return_t
6868
hg_prof_pvar_init();
6969

70+
/**
71+
* Internal routine that gets invoked during Mercury's own finalization routine.
72+
* General routine for finalizing and freeing the internal PVAR data structures.
73+
*
74+
* \return HG_SUCCESS or corresponding HG error code
75+
*/
76+
hg_return_t
77+
hg_prof_pvar_finalize();
78+
79+
/**
80+
* Internal routine that returns the PVAR address associated with the name.
81+
*
82+
* \param name [IN] PVAR name
83+
* \return hg_atomic_int32_t* that represents the PVAR addr
84+
*/
7085
hg_atomic_int32_t *
7186
hg_prof_get_pvar_addr_from_name(const char* name);
7287

0 commit comments

Comments
 (0)