File: eztrace_convert_main.c

package info (click to toggle)
eztrace 2.0%2Brepack-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,132 kB
  • sloc: ansic: 23,501; perl: 910; sh: 857; cpp: 771; makefile: 696; fortran: 327; f90: 320; python: 57
file content (228 lines) | stat: -rw-r--r-- 6,082 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
 * Copyright (C) CNRS, INRIA, Université Bordeaux 1, Télécom SudParis
 * See COPYING in top-level directory.
 */

#include <stdio.h>
#include <GTG.h>
#include "eztrace_convert.h"


#include "main_ev_codes.h"

int eztrace_convert_main_init();

int handle_main_events(eztrace_event_t *ev);
int handle_main_stats(eztrace_event_t *ev);
void print_main_stats();


void handleEZTRACE_bin_function_1() ;
void handleEZTRACE_bin_function_2() ;

void handleEZTRACE_lib_function_1() ;
void handleEZTRACE_lib_function_2() ;


/* thread-specific structure */
struct main_thread_info_t {
  struct thread_info_t *p_thread;

  /* TO COMPLETE: You can add per-thread counters here */
};

static struct main_thread_info_t *__register_thread_hook(
    struct thread_info_t *p_thread) {
  struct main_thread_info_t *ptr = (struct main_thread_info_t*) malloc(
      sizeof(struct main_thread_info_t));

  ptr->p_thread = p_thread;

  /* TO COMPLETE: If you added per-thread counters, initialize them here*/

  /* add the hook in the thread info structure */
  ezt_hook_list_add(&ptr->p_thread->hooks, ptr,
                   (uint8_t) main_EVENTS_ID);
  return ptr;
}

#define  INIT_main_THREAD_INFO(p_thread, var)                      \
  struct main_thread_info_t *var = (struct main_thread_info_t*)        \
    ezt_hook_list_retrieve_data(&p_thread->hooks, (uint8_t)main_EVENTS_ID); \
  if(!(var)) {                                                         \
    var = __register_thread_hook(p_thread);                            \
  }


/* Constructor of the plugin.
 * This function registers the current module to eztrace_convert
 */
struct eztrace_convert_module main_module;
void libinit(void) __attribute__ ((constructor));
void libinit(void)
{
  main_module.api_version = EZTRACE_API_VERSION;

  /* Specify the initialization function.
   * This function will be called once all the plugins are loaded
   * and the trace is started.
   * This function usually declared StateTypes, LinkTypes, etc.
   */
  main_module.init = eztrace_convert_main_init;

  /* Specify the function to call for handling an event
   */
  main_module.handle = handle_main_events;

  /* Specify the function to call for handling an event when
   * eztrace_stats is called
   */
  main_module.handle_stats = handle_main_stats;

  /* Specify the function to call for printinf statistics
   */
  main_module.print_stats = print_main_stats;

  /* Specify the module prefix */
  main_module.module_prefix = main_EVENTS_ID;

  asprintf(&main_module.name, "main");
  asprintf(&main_module.description, "Module for the main program");

  main_module.token.data = &main_module;

  /* Register the module to eztrace_convert */
  eztrace_convert_register_module(&main_module);

  //printf("module main loaded\n");
}

void libfinalize(void) __attribute__ ((destructor));
void libfinalize(void)
{
}



/*
 * This function will be called once all the plugins are loaded
 * and the trace is started.
 * This function usually declared StateTypes, LinkTypes, etc.
 */
int
eztrace_convert_main_init()
{
    if(get_mode() == EZTRACE_CONVERT) {
	addEntityValue("main_STATE_0", "ST_Thread", "Doing function lib_function", GTG_DARKGREY);
    }
    if(get_mode() == EZTRACE_CONVERT) {
	addEntityValue("main_STATE_1", "ST_Thread", "Doing function bin_function", GTG_DARKGREY);
    }
}


/* This function is called by eztrace_convert for each event to
 * handle.
 * It shall return 1 if the event was handled successfully or
 * 0 otherwise.
 */
int
handle_main_events(eztrace_event_t *ev)
{

  if(! CUR_TRACE->start)
    return 0;

  switch (LITL_READ_GET_CODE(ev)) {
  case EZTRACE_bin_function_1:
    handleEZTRACE_bin_function_1();
    break;
  case EZTRACE_bin_function_2:
    handleEZTRACE_bin_function_2();
    break;

  case EZTRACE_lib_function_1:
    handleEZTRACE_lib_function_1();
    break;
  case EZTRACE_lib_function_2:
    handleEZTRACE_lib_function_2();
    break;

  default:
    /* The event was not handled */
    return 0;
  }
  return 1;
}

/* This function is called by eztrace_stats for each event to
 * handle.
 * It shall return 1 if the event was handled successfully or
 * 0 otherwise.
 */
int
handle_main_stats(eztrace_event_t *ev)
{
  /* By default, use the same function as for eztrace_convert */
  return handle_main_events(ev);
}


void
print_main_stats()
{
  printf("\nmain:\n");
  printf("-------\n");

  int i;
  /* Browse the list of processes */
  for (i = 0; i < NB_TRACES; i++) {
    struct eztrace_container_t *p_process = GET_PROCESS_CONTAINER(i);
    int j;
    /* For each process, browse the list of threads */
    for(j=0; j<p_process->nb_children; j++) {
      struct eztrace_container_t *thread_container = p_process->children[j];
      struct thread_info_t *p_thread = (struct thread_info_t*) thread_container->container_info;
      if(!p_thread)
       continue;
      INIT_main_THREAD_INFO(p_thread, ptr);
      printf("\tThread %s\n", thread_container->name);

      /* TO COMPLETE: you can print per-thread counters here */
    }
  }

}

void handleEZTRACE_bin_function_1() {
    FUNC_NAME;
    DECLARE_THREAD_ID_STR(thread_id, CUR_INDEX, CUR_THREAD_ID);
    DECLARE_CUR_THREAD(p_thread);
    INIT_main_THREAD_INFO(p_thread, ptr);
    CHANGE() pushState (CURRENT, "ST_Thread", thread_id, "main_STATE_1");
}
void handleEZTRACE_bin_function_2() {
    FUNC_NAME;
    DECLARE_THREAD_ID_STR(thread_id, CUR_INDEX, CUR_THREAD_ID);
    DECLARE_CUR_THREAD(p_thread);
    INIT_main_THREAD_INFO(p_thread, ptr);
    CHANGE() popState (CURRENT, "ST_Thread", thread_id);
}



void handleEZTRACE_lib_function_1() {
    FUNC_NAME;
    DECLARE_THREAD_ID_STR(thread_id, CUR_INDEX, CUR_THREAD_ID);
    DECLARE_CUR_THREAD(p_thread);
    INIT_main_THREAD_INFO(p_thread, ptr);
    CHANGE() pushState (CURRENT, "ST_Thread", thread_id, "main_STATE_0");
}
void handleEZTRACE_lib_function_2() {
    FUNC_NAME;
    DECLARE_THREAD_ID_STR(thread_id, CUR_INDEX, CUR_THREAD_ID);
    DECLARE_CUR_THREAD(p_thread);
    INIT_main_THREAD_INFO(p_thread, ptr);
    CHANGE() popState (CURRENT, "ST_Thread", thread_id);
}