ARGOBOTS  66b1c39742507d8df30e8d28c54839b961a14814
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
log.c
Go to the documentation of this file.
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  * See COPYRIGHT in top-level directory.
4  */
5 
6 #include <stdio.h>
7 #include <stdarg.h>
8 #include "abti.h"
9 
10 #ifdef ABT_CONFIG_USE_DEBUG_LOG
11 
12 void ABTI_log_debug(FILE *fh, const char *format, ...)
13 {
14  if (gp_ABTI_global->use_logging == ABT_FALSE)
15  return;
16  ABTI_local *p_local = ABTI_local_get_local_uninlined();
17 
18  char *prefix_fmt = NULL, *prefix = NULL;
19  char *newfmt;
20  uint64_t tid;
21  int rank;
22  size_t newfmt_len;
23 
24  ABTI_xstream *p_local_xstream = ABTI_local_get_xstream_or_null(p_local);
25  if (p_local_xstream) {
26  ABTI_ythread *p_ythread =
27  ABTI_thread_get_ythread(p_local_xstream->p_thread);
28  if (p_ythread == NULL) {
29  if (p_local_xstream->type != ABTI_XSTREAM_TYPE_PRIMARY) {
30  prefix_fmt = "<U%" PRIu64 ":E%d> %s";
31  rank = p_local_xstream->rank;
32  tid = 0;
33  } else {
34  prefix = "<U0:E0> ";
35  prefix_fmt = "%s%s";
36  }
37  } else {
38  rank = p_local_xstream->rank;
39  prefix_fmt = "<U%" PRIu64 ":E%d> %s";
40  tid = ABTI_thread_get_id(&p_ythread->thread);
41  }
42  } else {
43  prefix = "<EXT> ";
44  prefix_fmt = "%s%s";
45  }
46 
47  if (prefix == NULL) {
48  /* Both tid and rank are less than 42 characters in total. */
49  const int len_tid_rank = 50;
50  newfmt_len = 6 + len_tid_rank + strlen(format);
51  int abt_errno = ABTU_malloc(newfmt_len + 1, (void **)&newfmt);
52  if (abt_errno != ABT_SUCCESS)
53  return;
54  sprintf(newfmt, prefix_fmt, tid, rank, format);
55  } else {
56  newfmt_len = strlen(prefix) + strlen(format);
57  int abt_errno = ABTU_malloc(newfmt_len + 1, (void **)&newfmt);
58  if (abt_errno != ABT_SUCCESS)
59  return;
60  sprintf(newfmt, prefix_fmt, prefix, format);
61  }
62 
63 #ifndef ABT_CONFIG_USE_DEBUG_LOG_DISCARD
64  va_list list;
65  va_start(list, format);
66  vfprintf(fh, newfmt, list);
67  va_end(list);
68  fflush(fh);
69 #else
70  /* Discard the log message. This option is used to check if the logging
71  * function works correct (i.e., without any SEGV) but a tester does not
72  * need an actual log since the output can be extremely large. */
73 #endif
74 
75  ABTU_free(newfmt);
76 }
77 
78 void ABTI_log_pool_push(ABTI_pool *p_pool, ABT_unit unit)
79 {
80  if (gp_ABTI_global->use_logging == ABT_FALSE)
81  return;
82 
83  ABTI_ythread *p_ythread = NULL;
84  ABTI_thread *p_task = NULL;
85  switch (p_pool->u_get_type(unit)) {
87  p_ythread = ABTI_ythread_get_ptr(p_pool->u_get_thread(unit));
88  if (p_ythread->thread.p_last_xstream) {
89  LOG_DEBUG("[U%" PRIu64 ":E%d] pushed to P%" PRIu64 "\n",
90  ABTI_thread_get_id(&p_ythread->thread),
91  p_ythread->thread.p_last_xstream->rank, p_pool->id);
92  } else {
93  LOG_DEBUG("[U%" PRIu64 "] pushed to P%" PRIu64 "\n",
94  ABTI_thread_get_id(&p_ythread->thread), p_pool->id);
95  }
96  break;
97 
98  case ABT_UNIT_TYPE_TASK:
99  p_task = ABTI_thread_get_ptr(p_pool->u_get_task(unit));
100  if (p_task->p_last_xstream) {
101  LOG_DEBUG("[T%" PRIu64 ":E%d] pushed to P%" PRIu64 "\n",
102  ABTI_thread_get_id(p_task),
103  p_task->p_last_xstream->rank, p_pool->id);
104  } else {
105  LOG_DEBUG("[T%" PRIu64 "] pushed to P%" PRIu64 "\n",
106  ABTI_thread_get_id(p_task), p_pool->id);
107  }
108  break;
109 
110  default:
111  ABTI_ASSERT(0);
113  }
114 }
115 
116 void ABTI_log_pool_remove(ABTI_pool *p_pool, ABT_unit unit)
117 {
118  if (gp_ABTI_global->use_logging == ABT_FALSE)
119  return;
120 
121  ABTI_ythread *p_ythread = NULL;
122  ABTI_thread *p_task = NULL;
123  switch (p_pool->u_get_type(unit)) {
125  p_ythread = ABTI_ythread_get_ptr(p_pool->u_get_thread(unit));
126  if (p_ythread->thread.p_last_xstream) {
127  LOG_DEBUG("[U%" PRIu64 ":E%d] removed from P%" PRIu64 "\n",
128  ABTI_thread_get_id(&p_ythread->thread),
129  p_ythread->thread.p_last_xstream->rank, p_pool->id);
130  } else {
131  LOG_DEBUG("[U%" PRIu64 "] removed from P%" PRIu64 "\n",
132  ABTI_thread_get_id(&p_ythread->thread), p_pool->id);
133  }
134  break;
135 
136  case ABT_UNIT_TYPE_TASK:
137  p_task = ABTI_thread_get_ptr(p_pool->u_get_task(unit));
138  if (p_task->p_last_xstream) {
139  LOG_DEBUG("[T%" PRIu64 ":E%d] removed from P%" PRIu64 "\n",
140  ABTI_thread_get_id(p_task),
141  p_task->p_last_xstream->rank, p_pool->id);
142  } else {
143  LOG_DEBUG("[T%" PRIu64 "] removed from P%" PRIu64 "\n",
144  ABTI_thread_get_id(p_task), p_pool->id);
145  }
146  break;
147 
148  default:
149  ABTI_ASSERT(0);
151  }
152 }
153 
154 void ABTI_log_pool_pop(ABTI_pool *p_pool, ABT_unit unit)
155 {
156  if (gp_ABTI_global->use_logging == ABT_FALSE)
157  return;
158  if (unit == ABT_UNIT_NULL)
159  return;
160 
161  ABTI_ythread *p_ythread = NULL;
162  ABTI_thread *p_task = NULL;
163  switch (p_pool->u_get_type(unit)) {
165  p_ythread = ABTI_ythread_get_ptr(p_pool->u_get_thread(unit));
166  if (p_ythread->thread.p_last_xstream) {
167  LOG_DEBUG("[U%" PRIu64 ":E%d] popped from "
168  "P%" PRIu64 "\n",
169  ABTI_thread_get_id(&p_ythread->thread),
170  p_ythread->thread.p_last_xstream->rank, p_pool->id);
171  } else {
172  LOG_DEBUG("[U%" PRIu64 "] popped from P%" PRIu64 "\n",
173  ABTI_thread_get_id(&p_ythread->thread), p_pool->id);
174  }
175  break;
176 
177  case ABT_UNIT_TYPE_TASK:
178  p_task = ABTI_thread_get_ptr(p_pool->u_get_task(unit));
179  if (p_task->p_last_xstream) {
180  LOG_DEBUG("[T%" PRIu64 ":E%d] popped from "
181  "P%" PRIu64 "\n",
182  ABTI_thread_get_id(p_task),
183  p_task->p_last_xstream->rank, p_pool->id);
184  } else {
185  LOG_DEBUG("[T%" PRIu64 "] popped from P%" PRIu64 "\n",
186  ABTI_thread_get_id(p_task), p_pool->id);
187  }
188  break;
189 
190  default:
191  ABTI_ASSERT(0);
193  }
194 }
195 
196 #endif /* ABT_CONFIG_USE_DEBUG_LOG */
struct ABT_unit_opaque * ABT_unit
Definition: abt.h:337
#define ABTU_unreachable()
Definition: abtu.h:25
#define ABT_UNIT_NULL
Definition: abt.h:415
static ABTU_ret_err int ABTU_malloc(size_t size, void **p_ptr)
Definition: abtu.h:142
#define ABT_FALSE
Definition: abt.h:285
ABTI_global * gp_ABTI_global
Definition: global.c:18
#define ABT_SUCCESS
Definition: abt.h:64
#define LOG_DEBUG(fmt,...)
Definition: abti_log.h:26
static void ABTU_free(void *ptr)
Definition: abtu.h:135