Subversion Repositories shark

Rev

Rev 374 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
352 giacomo 1
#include <stdlib.h>
2
#include <tracer.h>
3
 
445 giacomo 4
void *StartTracerBuffer; // Buffer Start 0
5
void *EndTracerBuffer; // Buffer End 4
6
void *LastBeforeEndTracerBuffer; //8
7
void *CurrentTracerBuffer; //The Actual Write Point For The Next Event 12
8
void *FirstTracerBuffer; //The First Valid Event 16
362 giacomo 9
 
445 giacomo 10
 
11
int TracerActive = 0; //20
12
int TracerOutputType = TRACER_NO_OUTPUT; //24
13
unsigned long long TracerEventsRecorded; //28
14
unsigned int TracerEventsPresent; //36
15
 
352 giacomo 16
extern unsigned int clk_per_msec;
17
 
369 giacomo 18
#define TRACER_DEBUG
19
 
352 giacomo 20
/* Initialize the tracer
21
 *
22
 * Return 0 => Success
23
 * Return 1 => Fail
24
 */
365 giacomo 25
int tracer_initialize(int MemorySize)
352 giacomo 26
{
27
 
28
  SYS_FLAGS f;
29
 
30
  f = ll_fsave();
31
 
32
  StartTracerBuffer = malloc(MemorySize);
33
  if (!StartTracerBuffer) {
34
    ll_frestore(f);
35
    return 1;
36
  }
37
 
38
  EndTracerBuffer = StartTracerBuffer + MemorySize - 1;
39
  CurrentTracerBuffer = StartTracerBuffer;
362 giacomo 40
  FirstTracerBuffer = StartTracerBuffer;
41
  LastBeforeEndTracerBuffer = EndTracerBuffer;
352 giacomo 42
 
43
  TracerActive = 0;
44
  TracerEventsRecorded = 0;
369 giacomo 45
  TracerEventsPresent = 0;
352 giacomo 46
 
47
  ll_frestore(f);
48
  return 0;
49
 
50
}
51
 
52
void tracer_enable() {
53
 
54
  SYS_FLAGS f;
55
 
56
  f = ll_fsave();
57
 
58
  TracerActive = 1;
59
 
60
  ll_frestore(f);
61
 
62
}
63
 
64
void tracer_disable() {
65
 
66
  SYS_FLAGS f;
67
 
68
  f = ll_fsave();
69
 
70
  TracerActive = 0;
71
 
72
  ll_frestore(f);
73
 
74
}
75
 
364 giacomo 76
int send_udp_event(void *p, int size);
369 giacomo 77
void send_remaining_udp_buffer();
364 giacomo 78
 
79
/* Send NumberOfEvents out of the system
80
 * If NumberOfEvents = -1 all the events will be sent */
374 giacomo 81
int tracer_send_logged_events(int NumberOfEvents) {
364 giacomo 82
 
83
  void *p;
84
  int s,err;
85
 
86
  SYS_FLAGS f;
87
 
88
  f = ll_fsave();
89
 
369 giacomo 90
  if (NumberOfEvents == 0 || TracerEventsPresent == 0) {
364 giacomo 91
    ll_frestore(f);
92
    return 0;
93
  }
94
 
95
  p = FirstTracerBuffer;
96
  s = 0;
445 giacomo 97
  while(((p == CurrentTracerBuffer && s == 0) || p != CurrentTracerBuffer) &&
98
          s != NumberOfEvents &&
99
          TracerEventsPresent != 0) {
364 giacomo 100
 
101
    switch (TracerOutputType) {
102
      case TRACER_NO_OUTPUT:
369 giacomo 103
          #ifdef TRACER_DEBUG
104
            cprintf("Event Type %02x Sent To NULL\n",*(BYTE *)(p));
105
          #endif
364 giacomo 106
        break;
107
      case TRACER_UDP_OUTPUT:
108
          err = send_udp_event(p,*(BYTE *)(p + 9));
109
          if (err != 0) {
110
            ll_frestore(f);
111
            return s;
112
          }
113
        break;
114
      default:
369 giacomo 115
          #ifdef TRACER_DEBUG
116
            cprintf("Error: Tracer Output Not Defined\n");
117
          #endif
118
          ll_frestore(f);
364 giacomo 119
          return -1;
120
        break;
121
    }
122
 
123
    p += *(BYTE *)(p + 9);
124
    if (p >= LastBeforeEndTracerBuffer) p = StartTracerBuffer;
125
 
126
    FirstTracerBuffer = p;
369 giacomo 127
    TracerEventsPresent--;
364 giacomo 128
 
129
    s++;
130
 
131
  }
132
 
133
  ll_frestore(f);
134
  return s;
135
 
136
}
137
 
369 giacomo 138
//Flush the events that are ready to send
139
void tracer_flush_sent_events() {
140
 
141
  switch (TracerOutputType) {
142
    case TRACER_UDP_OUTPUT:
143
        send_remaining_udp_buffer();
144
      break;
145
  }
146
 
147
}
148
 
352 giacomo 149
void tracer_print_statistics() {
150
 
151
  SYS_FLAGS f;
152
  void *p;
363 giacomo 153
  int i,t,s;
352 giacomo 154
 
362 giacomo 155
  f = ll_fsave();
352 giacomo 156
 
363 giacomo 157
  cprintf("\nStart Tracer Buffer:           %08x\n",(int)StartTracerBuffer);
362 giacomo 158
  cprintf("End Tracer Buffer:             %08x\n",(int)EndTracerBuffer);
159
  cprintf("Current Tracer Buffer:         %08x\n",(int)CurrentTracerBuffer);
160
  cprintf("First Tracer Buffer:           %08x\n",(int)FirstTracerBuffer);
161
  cprintf("Last Before End Tracer Buffer: %08x\n\n",(int)LastBeforeEndTracerBuffer);
352 giacomo 162
 
369 giacomo 163
  cprintf("Events Logged:  %d\n",(int)TracerEventsRecorded);
164
  cprintf("Events Present: %d\n",TracerEventsPresent);
352 giacomo 165
 
369 giacomo 166
  if (TracerEventsPresent == 0) {
167
    ll_frestore(f);
168
    return;
169
  }
367 giacomo 170
 
352 giacomo 171
  for (i=0; i<0xFF; i++) {
362 giacomo 172
    p = FirstTracerBuffer;
352 giacomo 173
    t = 0;
363 giacomo 174
    s = 0;
175
    while((p == CurrentTracerBuffer && s == 0) || p != CurrentTracerBuffer) {
176
      s++;
352 giacomo 177
      if (*(BYTE *)p == i) t++;
363 giacomo 178
      p += *(BYTE *)(p + 9);
179
      if (p >= LastBeforeEndTracerBuffer) p = StartTracerBuffer;
352 giacomo 180
    }
181
    if (t != 0)
182
      cprintf("Event type %02x => %d\n",i,t);
183
  }
184
 
185
  ll_frestore(f);
186
 
187
}