10 #ifdef ABT_CONFIG_USE_DEBUG_LOG 11 ABTD_XSTREAM_LOCAL ABTI_log *lp_ABTI_log = NULL;
13 void ABTI_log_init(
void)
15 lp_ABTI_log = (ABTI_log *)
ABTU_malloc(
sizeof(ABTI_log));
16 lp_ABTI_log->p_sched = NULL;
19 void ABTI_log_finalize(
void)
25 void ABTI_log_print(FILE *fh,
const char *format, ...)
31 va_start(list, format);
32 vfprintf(fh, format, list);
37 void ABTI_log_event(FILE *fh,
const char *format, ...)
41 ABTI_local *p_local = ABTI_local_get_local_uninlined();
44 ABTI_xstream *p_xstream = NULL;
45 ABTI_thread *p_thread = NULL;
46 ABTI_task *p_task = NULL;
47 char *prefix_fmt = NULL, *prefix = NULL;
51 int tid_len = 0, rank_len = 0;
56 p_xstream = p_local->p_xstream;
57 p_thread = p_local->p_thread;
58 if (p_thread == NULL) {
59 if (p_xstream && p_xstream->type != ABTI_XSTREAM_TYPE_PRIMARY) {
60 prefix_fmt =
"<U%" PRIu64
":E%d> %s";
61 rank = p_xstream->rank;
68 rank = p_xstream->rank;
69 if (lp_ABTI_log->p_sched) {
70 prefix_fmt =
"<S%" PRIu64
":E%d> %s";
71 tid = lp_ABTI_log->p_sched->id;
73 prefix_fmt =
"<U%" PRIu64
":E%d> %s";
74 tid = ABTI_thread_get_id(p_thread);
80 p_xstream = p_local->p_xstream;
81 rank = p_xstream->rank;
82 p_task = p_local->p_task;
83 if (lp_ABTI_log->p_sched) {
84 prefix_fmt =
"<S%" PRIu64
":E%d> %s";
85 tid = lp_ABTI_log->p_sched->id;
87 prefix_fmt =
"<T%" PRIu64
":E%d> %s";
88 tid = ABTI_task_get_id(p_task);
98 prefix =
"<UNKNOWN> ";
103 if (prefix == NULL) {
106 newfmt_len = 6 + tid_len + rank_len + strlen(format);
108 sprintf(newfmt, prefix_fmt, tid, rank, format);
110 newfmt_len = strlen(prefix) + strlen(format);
112 sprintf(newfmt, prefix_fmt, prefix, format);
116 va_start(list, format);
117 vfprintf(fh, newfmt, list);
124 void ABTI_log_debug(FILE *fh,
char *path,
int line,
const char *format, ...)
134 newfmt_len = strlen(path) + line_len + 4 + strlen(format);
136 sprintf(newfmt,
"[%s:%d] %s", path, line, format);
139 va_start(list, format);
140 vfprintf(fh, newfmt, list);
147 void ABTI_log_pool_push(ABTI_pool *p_pool,
ABT_unit unit,
148 ABTI_native_thread_id producer_id)
153 ABTI_thread *p_thread = NULL;
154 ABTI_task *p_task = NULL;
155 switch (p_pool->u_get_type(unit)) {
157 p_thread = ABTI_thread_get_ptr(p_pool->u_get_thread(unit));
158 if (p_thread->p_last_xstream) {
159 LOG_EVENT(
"[U%" PRIu64
":E%d] pushed to P%" PRIu64
" " 160 "(producer: NT %p)\n",
161 ABTI_thread_get_id(p_thread),
162 p_thread->p_last_xstream->rank, p_pool->id,
163 (
void *)producer_id);
165 LOG_EVENT(
"[U%" PRIu64
"] pushed to P%" PRIu64
" " 166 "(producer: NT %p)\n",
167 ABTI_thread_get_id(p_thread), p_pool->id,
168 (
void *)producer_id);
173 p_task = ABTI_task_get_ptr(p_pool->u_get_task(unit));
174 if (p_task->p_xstream) {
175 LOG_EVENT(
"[T%" PRIu64
":E%d] pushed to P%" PRIu64
" " 176 "(producer: NT %p)\n",
177 ABTI_task_get_id(p_task), p_task->p_xstream->rank,
178 p_pool->id, (
void *)producer_id);
180 LOG_EVENT(
"[T%" PRIu64
"] pushed to P%" PRIu64
" " 181 "(producer: NT %p)\n",
182 ABTI_task_get_id(p_task), p_pool->id,
183 (
void *)producer_id);
193 void ABTI_log_pool_remove(ABTI_pool *p_pool,
ABT_unit unit,
194 ABTI_native_thread_id consumer_id)
199 ABTI_thread *p_thread = NULL;
200 ABTI_task *p_task = NULL;
201 switch (p_pool->u_get_type(unit)) {
203 p_thread = ABTI_thread_get_ptr(p_pool->u_get_thread(unit));
204 if (p_thread->p_last_xstream) {
205 LOG_EVENT(
"[U%" PRIu64
":E%d] removed from " 206 "P%" PRIu64
" (consumer: NT %p)\n",
207 ABTI_thread_get_id(p_thread),
208 p_thread->p_last_xstream->rank, p_pool->id,
209 (
void *)consumer_id);
211 LOG_EVENT(
"[U%" PRIu64
"] removed from P%" PRIu64
" " 212 "(consumer: NT %p)\n",
213 ABTI_thread_get_id(p_thread), p_pool->id,
214 (
void *)consumer_id);
219 p_task = ABTI_task_get_ptr(p_pool->u_get_task(unit));
220 if (p_task->p_xstream) {
221 LOG_EVENT(
"[T%" PRIu64
":E%d] removed from " 222 "P%" PRIu64
" (consumer: NT %p)\n",
223 ABTI_task_get_id(p_task), p_task->p_xstream->rank,
224 p_pool->id, (
void *)consumer_id);
226 LOG_EVENT(
"[T%" PRIu64
"] removed from P%" PRIu64
" " 227 "(consumer: NT %p)\n",
228 ABTI_task_get_id(p_task), p_pool->id,
229 (
void *)consumer_id);
239 void ABTI_log_pool_pop(ABTI_pool *p_pool,
ABT_unit unit)
246 ABTI_thread *p_thread = NULL;
247 ABTI_task *p_task = NULL;
248 switch (p_pool->u_get_type(unit)) {
250 p_thread = ABTI_thread_get_ptr(p_pool->u_get_thread(unit));
251 if (p_thread->p_last_xstream) {
252 LOG_EVENT(
"[U%" PRIu64
":E%d] popped from " 254 ABTI_thread_get_id(p_thread),
255 p_thread->p_last_xstream->rank, p_pool->id);
257 LOG_EVENT(
"[U%" PRIu64
"] popped from P%" PRIu64
"\n",
258 ABTI_thread_get_id(p_thread), p_pool->id);
263 p_task = ABTI_task_get_ptr(p_pool->u_get_task(unit));
264 if (p_task->p_xstream) {
265 LOG_EVENT(
"[T%" PRIu64
":E%d] popped from " 267 ABTI_task_get_id(p_task), p_task->p_xstream->rank,
270 LOG_EVENT(
"[T%" PRIu64
"] popped from P%" PRIu64
"\n",
271 ABTI_task_get_id(p_task), p_pool->id);
int ABTU_get_int_len(size_t num)
struct ABT_unit_opaque * ABT_unit
static void * ABTU_malloc(size_t size)
ABTI_global * gp_ABTI_global
#define LOG_EVENT(fmt,...)
static void ABTU_free(void *ptr)