Subversion Repositories shark

Rev

Rev 362 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
352 giacomo 1
#include <stdlib.h>
2
#include <tracer.h>
3
 
4
void *StartTracerBuffer;
5
void *EndTracerBuffer;
6
void *CurrentTracerBuffer;
7
int TracerActive = 0;
8
unsigned long long TracerEventsRecorded;
9
extern unsigned int clk_per_msec;
10
 
11
/* Initialize the tracer
12
 *
13
 * Return 0 => Success
14
 * Return 1 => Fail
15
 */
16
int tracer_initialize(int OutputType, int MemorySize)
17
{
18
 
19
  SYS_FLAGS f;
20
 
21
  f = ll_fsave();
22
 
23
  StartTracerBuffer = malloc(MemorySize);
24
  if (!StartTracerBuffer) {
25
    ll_frestore(f);
26
    return 1;
27
  }
28
 
29
  EndTracerBuffer = StartTracerBuffer + MemorySize - 1;
30
  CurrentTracerBuffer = StartTracerBuffer;
31
 
32
  TracerActive = 0;
33
  TracerEventsRecorded = 0;
34
 
35
  ll_frestore(f);
36
  return 0;
37
 
38
}
39
 
40
void tracer_enable() {
41
 
42
  SYS_FLAGS f;
43
 
44
  f = ll_fsave();
45
 
46
  TracerActive = 1;
47
 
48
  ll_frestore(f);
49
 
50
}
51
 
52
void tracer_disable() {
53
 
54
  SYS_FLAGS f;
55
 
56
  f = ll_fsave();
57
 
58
  TracerActive = 0;
59
 
60
  ll_frestore(f);
61
 
62
}
63
 
64
void tracer_print_statistics() {
65
 
66
  SYS_FLAGS f;
67
  void *p;
68
  int i,t,ctx,pid,ctx_current;
69
  unsigned long long ck,delta;  
70
  unsigned long long last_clk;
71
 
72
  struct exec_proc {
73
    int ctx;
74
    unsigned long long total_clk;
75
    unsigned long long start_clk;
76
  };
77
 
78
  struct exec_proc *ec;
79
 
80
  f = ll_fsave();
81
 
82
  cprintf("Total Events %d\n",(int)TracerEventsRecorded);
83
 
84
  for (i=0; i<0xFF; i++) {
85
    p = StartTracerBuffer;
86
    t = 0;
87
    while(p < CurrentTracerBuffer) {
88
      if (*(BYTE *)p == i) t++;
89
      p += *(BYTE *)(p + 9);
90
    }
91
    if (t != 0)
92
      cprintf("Event type %02x => %d\n",i,t);
93
  }
94
 
95
  ec = malloc(sizeof(struct exec_proc) * MAX_PROC);
96
  ctx_current = 0;
97
  last_clk = 0;
98
 
99
  cprintf("Context Switch Analisys\n");
100
  p = StartTracerBuffer;
101
  while(p < CurrentTracerBuffer) {
102
    pid = *(int *)(p + 10);
103
    ctx = *(int *)(p + 14);
104
    ck = (unsigned long long)(*(unsigned int *)(p + 1)) << 32;
105
    ck |= *(unsigned int *)(p + 5);
106
    if (*(BYTE *)p == FTrace_EVT_task_create) {
107
      cprintf("Task Create %d %d\n",pid,ctx);
108
      ec[pid].ctx = ctx;
109
      ec[pid].total_clk = 0;
110
      ec[pid].start_clk = ck;
111
    }
112
    if (*(BYTE *)p == FTrace_EVT_context_switch ||
113
        *(BYTE *)p == FTrace_EVT_timer_wakeup_end) {
114
      ctx = *(int *)(p + 10);
115
      if (ctx_current == 0) {
116
        ctx_current = ctx;
117
        last_clk = ck;
118
      } else {
119
        delta = ck - last_clk;
120
        cprintf("Delta Ctx %d = %d us\n",ctx_current,(int)(delta * 1000000 / clk_per_msec / 1000));
121
        last_clk = ck;
122
        ctx_current = ctx;
123
      }
124
    }
125
    p += *(BYTE *)(p + 9);
126
  }
127
 
128
  ll_frestore(f);
129
 
130
}