10 #ifdef ABT_CONFIG_USE_DEBUG_LOG
12 void ABTI_log_debug(
const char *format, ...)
14 ABTI_global *p_global = ABTI_global_get_global_or_null();
15 if (!p_global || p_global->use_logging ==
ABT_FALSE)
17 ABTI_local *p_local = ABTI_local_get_local_uninlined();
19 const char *prefix_fmt = NULL, *prefix = NULL;
20 char static_buffer[256], *newfmt;
25 ABTI_xstream *p_local_xstream = ABTI_local_get_xstream_or_null(p_local);
26 if (p_local_xstream) {
27 ABTI_ythread *p_ythread =
28 ABTI_thread_get_ythread(p_local_xstream->p_thread);
29 if (p_ythread == NULL) {
30 if (p_local_xstream->type != ABTI_XSTREAM_TYPE_PRIMARY) {
31 prefix_fmt =
"<U%" PRIu64
":E%d> %s";
32 rank = p_local_xstream->rank;
39 rank = p_local_xstream->rank;
40 prefix_fmt =
"<U%" PRIu64
":E%d> %s";
41 tid = ABTI_thread_get_id(&p_ythread->thread);
50 const int len_tid_rank = 50;
51 newfmt_len = 6 + len_tid_rank + strlen(format);
52 if (
sizeof(static_buffer) >= newfmt_len + 1) {
53 newfmt = static_buffer;
55 int abt_errno =
ABTU_malloc(newfmt_len + 1, (
void **)&newfmt);
59 sprintf(newfmt, prefix_fmt, tid, rank, format);
61 newfmt_len = strlen(prefix) + strlen(format);
62 if (
sizeof(static_buffer) >= newfmt_len + 1) {
63 newfmt = static_buffer;
65 int abt_errno =
ABTU_malloc(newfmt_len + 1, (
void **)&newfmt);
69 sprintf(newfmt, prefix_fmt, prefix, format);
72 #ifndef ABT_CONFIG_USE_DEBUG_LOG_DISCARD
74 va_start(list, format);
75 vfprintf(stderr, newfmt, list);
83 if (newfmt != static_buffer) {
88 void ABTI_log_debug_thread(
const char *msg, ABTI_thread *p_thread)
92 ABTI_log_debug(
"%s [unknown ULT]\n", msg);
93 }
else if (p_thread->type & ABTI_THREAD_TYPE_ROOT) {
95 }
else if (p_thread->type & ABTI_THREAD_TYPE_PRIMARY) {
97 ABTI_log_debug(
"%s U%" PRIu64
" (primary)\n", msg,
98 ABTI_thread_get_id(p_thread));
99 }
else if (p_thread->type & ABTI_THREAD_TYPE_MAIN_SCHED) {
101 ABTI_log_debug(
"%s U%" PRIu64
" (main sched)\n", msg,
102 ABTI_thread_get_id(p_thread));
103 }
else if (p_thread->type & ABTI_THREAD_TYPE_YIELDABLE) {
105 ABTI_log_debug(
"%s U%" PRIu64
"\n", msg, ABTI_thread_get_id(p_thread));
108 ABTI_log_debug(
"%s T%" PRIu64
"\n", msg, ABTI_thread_get_id(p_thread));
112 void ABTI_log_pool_push(ABTI_pool *p_pool,
ABT_unit unit)
114 ABTI_global *p_global = ABTI_global_get_global_or_null();
115 if (!p_global || p_global->use_logging ==
ABT_FALSE)
120 ABTI_thread *p_thread = ABTI_unit_get_thread(p_global, unit);
121 char unit_type = (p_thread->type & ABTI_THREAD_TYPE_YIELDABLE) ?
'U' :
'T';
122 if (p_thread->p_last_xstream) {
123 ABTI_log_debug(
"[%c%" PRIu64
":E%d] pushed to P%" PRIu64
"\n",
124 unit_type, ABTI_thread_get_id(p_thread),
125 p_thread->p_last_xstream->rank, p_pool->id);
127 ABTI_log_debug(
"[%c%" PRIu64
"] pushed to P%" PRIu64
"\n", unit_type,
128 ABTI_thread_get_id(p_thread), p_pool->id);
132 void ABTI_log_pool_remove(ABTI_pool *p_pool,
ABT_unit unit)
134 ABTI_global *p_global = ABTI_global_get_global_or_null();
135 if (!p_global || p_global->use_logging ==
ABT_FALSE)
140 ABTI_thread *p_thread = ABTI_unit_get_thread(p_global, unit);
141 char unit_type = (p_thread->type & ABTI_THREAD_TYPE_YIELDABLE) ?
'U' :
'T';
142 if (p_thread->p_last_xstream) {
143 ABTI_log_debug(
"[%c%" PRIu64
":E%d] removed from P%" PRIu64
"\n",
144 unit_type, ABTI_thread_get_id(p_thread),
145 p_thread->p_last_xstream->rank, p_pool->id);
147 ABTI_log_debug(
"[%c%" PRIu64
"] removed from P%" PRIu64
"\n", unit_type,
148 ABTI_thread_get_id(p_thread), p_pool->id);
152 void ABTI_log_pool_pop(ABTI_pool *p_pool,
ABT_thread thread)
154 ABTI_global *p_global = ABTI_global_get_global_or_null();
155 if (!p_global || p_global->use_logging ==
ABT_FALSE)
160 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
161 char unit_type = (p_thread->type & ABTI_THREAD_TYPE_YIELDABLE) ?
'U' :
'T';
162 if (p_thread->p_last_xstream) {
163 ABTI_log_debug(
"[%c%" PRIu64
":E%d] popped from P%" PRIu64
"\n",
164 unit_type, ABTI_thread_get_id(p_thread),
165 p_thread->p_last_xstream->rank, p_pool->id);
167 ABTI_log_debug(
"[%c%" PRIu64
"] popped from P%" PRIu64
"\n", unit_type,
168 ABTI_thread_get_id(p_thread), p_pool->id);
172 void ABTI_log_pool_pop_many(ABTI_pool *p_pool,
const ABT_thread *threads,
176 for (i = 0; i < num; i++) {
177 ABTI_log_pool_pop(p_pool, threads[i]);
181 void ABTI_log_pool_push_many(ABTI_pool *p_pool,
const ABT_unit *units,
185 for (i = 0; i < num; i++) {
186 ABTI_log_pool_push(p_pool, units[i]);