Subversion Repositories shark

Rev

Rev 1504 | Rev 1508 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1494 giacomo 1
#include <stdio.h>
2
#include <stdlib.h>
1499 giacomo 3
#include <math.h>
4
#include <unistd.h>
1500 giacomo 5
#include <string.h>
1494 giacomo 6
 
7
#define MAXCONTEXT 100
8
#define MAXJOB 100000
9
 
10
#define INT_CTX 1
11
#define INT_PID 9999
12
#define PID_NO_DEF -1
13
 
1495 giacomo 14
#define BACKGROUND 0
15
#define PERIODICAL 1
16
#define INTERRUPT  2
17
 
1499 giacomo 18
#define DRAW_NUM 1000
19
 
1495 giacomo 20
struct ctx_exec {
1494 giacomo 21
        int ctx;
22
        unsigned long long dtsc;
23
        unsigned long long start;
24
};
25
 
1495 giacomo 26
struct ctx_to_pid {
1494 giacomo 27
        int ctx;
28
        int pid;
29
};
30
 
1495 giacomo 31
struct endcycle {
1494 giacomo 32
        int ctx;
33
        unsigned long long tsc;
34
};
35
 
36
void Error(int num) {
1495 giacomo 37
        printf("Finite-State machine error: %d\n",num);
1494 giacomo 38
        exit(2);
39
}
40
 
1495 giacomo 41
int context_total = 0,endcycle_total = 0,job_total = 0,exec_total = 0;
42
struct ctx_exec *exec_list;
43
struct ctx_to_pid *context_list;
44
struct endcycle *endcycle_list;
45
struct ctx_exec *job_list;
1494 giacomo 46
 
1497 giacomo 47
unsigned int clk_per_msec = 0;
48
 
1495 giacomo 49
unsigned long long log_start_tsc = 0;
50
unsigned long long log_end_tsc = 0;
1499 giacomo 51
unsigned long long total_dtsc = 0;
1495 giacomo 52
 
1501 giacomo 53
/* Data for gnuplot external call */
1500 giacomo 54
int draw_data[DRAW_NUM+1];
1499 giacomo 55
 
56
int gnuplot_clear() {
57
 
58
   int i;
59
 
60
   for (i=0;i<DRAW_NUM;i++)
61
     draw_data[i] = 0;
62
 
63
   return 0;
64
 
65
}
66
 
1500 giacomo 67
int gnuplot_draw(char *title,unsigned long long max_limit,int type) {
1499 giacomo 68
 
69
   FILE *gnuplot_data, *gnuplot_command;
1500 giacomo 70
   char temp_name[30];
71
   int i,pid,*current_mem;
1499 giacomo 72
 
1500 giacomo 73
   current_mem = malloc(sizeof(int)*(DRAW_NUM+1));
74
   memcpy(current_mem,draw_data,sizeof(int)*(DRAW_NUM+1));
1499 giacomo 75
 
1500 giacomo 76
   pid = fork();
77
   if (pid == 0) {
1499 giacomo 78
 
1500 giacomo 79
     srand(getpid());
1499 giacomo 80
 
1500 giacomo 81
     sprintf(temp_name,"/tmp/pwcet%d",rand()%10000);
82
 
83
     gnuplot_data = fopen(temp_name,"w");
1504 giacomo 84
     gnuplot_command = popen("gnuplot -persist","w");
1500 giacomo 85
 
86
     for (i=0;i<DRAW_NUM;i++)
87
       fprintf(gnuplot_data,"%f\t%f\n",(double)i * (double)max_limit / (double)DRAW_NUM,(float)(current_mem[i]));
88
 
89
     fflush(gnuplot_data);
90
     fclose(gnuplot_data);
91
 
92
     fprintf(gnuplot_command,"set xlabel \"Time [us]\"\n");
93
     if (type == 0) {
94
        fprintf(gnuplot_command,"set ylabel \"Frequency [#]\"\n");
95
 
96
        fprintf(gnuplot_command,"plot \"%s\" using 1:2 title \"%s\" with lines\n",temp_name,title);
97
        fflush(gnuplot_command);
98
     } else {
99
       fprintf(gnuplot_command,"set ylabel \"Time [us]\"\n");
100
 
101
       fprintf(gnuplot_command,"plot \"%s\" using 1:2 title \"%s\" with lines\n",temp_name,title);
102
       fflush(gnuplot_command);
103
     }
104
 
105
     pclose(gnuplot_command);
106
 
107
     exit(0);
108
 
109
   }
110
 
1499 giacomo 111
   return 0;
112
 
113
}
114
 
1501 giacomo 115
int stats_from_execs(int ctx_num, unsigned long long *tot_tsc,
116
                                unsigned long long *min_tsc,
117
                                unsigned long long *mean_tsc,
118
                                unsigned long long *max_tsc,
119
                                unsigned long long *first_tsc,
120
                                int *number) {
121
 
122
   unsigned long long temp_tsc;
123
   int k,i;
124
 
125
   temp_tsc = 0;
126
   *max_tsc = 0;
127
   *mean_tsc = 0;
128
   *min_tsc = 0xFFFFFFFF;
129
   *first_tsc = 0;
130
   k = 0;
131
   for (i=0;i<exec_total;i++)
132
     if (exec_list[i].ctx == context_list[ctx_num].ctx) {
133
       if (*first_tsc == 0) *first_tsc = exec_list[i].start - log_start_tsc;
134
       if (exec_list[i].dtsc > *max_tsc) *max_tsc = exec_list[i].dtsc;
135
       if (exec_list[i].dtsc < *min_tsc) *min_tsc = exec_list[i].dtsc;
136
       temp_tsc += exec_list[i].dtsc;
137
       k++;
138
     }
139
 
140
   *number = k;
141
   *tot_tsc = temp_tsc;
1505 giacomo 142
   if (k != 0) *mean_tsc = temp_tsc / k;
1501 giacomo 143
 
144
   return 0;
145
 
146
}
147
 
148
int stats_from_jobs(int ctx_num, unsigned long long *tot_tsc,
149
                                unsigned long long *min_tsc,
150
                                unsigned long long *mean_tsc,
151
                                unsigned long long *max_tsc,
152
                                unsigned long long *first_tsc,
153
                                int *number) {
154
 
155
   unsigned long long temp_tsc;
156
   int k,i;
157
 
158
   temp_tsc = 0;
159
   *max_tsc = 0;
160
   *mean_tsc = 0;
161
   *min_tsc = 0xFFFFFFFF;
162
   *first_tsc = 0;
163
   k = 0;
164
   for (i=0;i<job_total;i++)
165
     if (job_list[i].ctx == context_list[ctx_num].ctx) {
166
       if (*first_tsc == 0) *first_tsc = job_list[i].start - log_start_tsc;
167
       if (job_list[i].dtsc > *max_tsc) *max_tsc = job_list[i].dtsc;
168
       if (job_list[i].dtsc < *min_tsc) *min_tsc = job_list[i].dtsc;
169
       temp_tsc += job_list[i].dtsc;
170
       k++;
171
     }
172
 
173
   *number = k;
174
   *tot_tsc = temp_tsc;
1505 giacomo 175
   if (k != 0) *mean_tsc = temp_tsc / k;
1501 giacomo 176
 
177
   return 0;
178
 
179
}
180
 
181
int arr_stats_from_execs(int ctx_num, unsigned long long *min_tsc,
182
                                unsigned long long *mean_tsc,
183
                                unsigned long long *max_tsc) {
184
 
185
   unsigned long long last_start,temp_tsc,delta_start;
186
   int i,k;
187
 
188
   last_start = 0;
189
   temp_tsc = 0;
190
   *max_tsc = 0;
191
   *min_tsc = 0xFFFFFFFF;
1505 giacomo 192
   *mean_tsc = 0;
1501 giacomo 193
   k = 0;
194
   for (i=0;i<exec_total;i++)
195
     if (exec_list[i].ctx == context_list[ctx_num].ctx) {
196
        if (last_start == 0) {
197
                last_start = exec_list[i].start;
198
        } else {
199
                delta_start = exec_list[i].start - last_start;
200
                if (delta_start > *max_tsc) *max_tsc = delta_start;
201
                if (delta_start < *min_tsc) *min_tsc = delta_start;
202
                temp_tsc += delta_start;
203
                k++;
204
                last_start = exec_list[i].start;
205
        }
206
      }
207
 
1505 giacomo 208
   if (k != 0) *mean_tsc = temp_tsc / k;
1501 giacomo 209
 
210
   return 0;
211
 
212
}
213
 
214
int arr_stats_from_jobs(int ctx_num, unsigned long long *min_tsc,
215
                                unsigned long long *mean_tsc,
216
                                unsigned long long *max_tsc) {
217
 
218
   unsigned long long last_start,temp_tsc,delta_start;
219
   int i,k;
220
 
221
   last_start = 0;
222
   temp_tsc = 0;
223
   *max_tsc = 0;
224
   *min_tsc = 0xFFFFFFFF;
1505 giacomo 225
   *mean_tsc = 0;
1501 giacomo 226
   k = 0;
227
   for (i=0;i<job_total;i++)
228
     if (job_list[i].ctx == context_list[ctx_num].ctx) {
229
        if (last_start == 0) {
230
                last_start = job_list[i].start;
231
        } else {
232
                delta_start = job_list[i].start - last_start;
233
                if (delta_start > *max_tsc) *max_tsc = delta_start;
234
                if (delta_start < *min_tsc) *min_tsc = delta_start;
235
                temp_tsc += delta_start;
236
                k++;
237
                last_start = job_list[i].start;
238
        }
239
      }
240
 
1505 giacomo 241
   if (k != 0) *mean_tsc = temp_tsc / k;
1501 giacomo 242
 
243
   return 0;
244
 
245
}
246
 
247
int plot_exec_demand_function(int ctx_num, char *pidstr) {
248
 
249
   unsigned long long max_limit;
250
   char tmpstr[50];
251
   int i;
252
 
253
   gnuplot_clear();
254
 
255
   max_limit = total_dtsc*1000/clk_per_msec;
256
 
257
   for (i=0;i<exec_total;i++)
258
     if (exec_list[i].ctx == context_list[ctx_num].ctx) {
259
       int h1,h2,h3;
260
 
261
       h1 = ((exec_list[i].start-log_start_tsc)*1000/clk_per_msec) * DRAW_NUM / max_limit;
262
       h2 = ((exec_list[i].start+exec_list[i].dtsc-log_start_tsc)*1000/clk_per_msec) * DRAW_NUM / max_limit;
263
       for (h3=h1;h3<h2;h3++)
264
         if (h3 <= DRAW_NUM) draw_data[h3] += (exec_list[i].dtsc*1000/clk_per_msec)*(h3-h1)/(h2-h1);
265
       for (h3=h2;h3<=DRAW_NUM;h3++)
266
         if (h3 <= DRAW_NUM) draw_data[h3] += (exec_list[i].dtsc*1000/clk_per_msec);
267
 
268
     }
269
 
270
   sprintf(tmpstr,"Ctx [%d:%s] Demand-Function",context_list[ctx_num].ctx,pidstr);
271
   gnuplot_draw(tmpstr,max_limit,1);
272
 
273
   return 0;
274
 
275
}
276
 
277
int plot_exec_c_distrib(int ctx_num, unsigned long long max_tsc, char *pidstr) {
278
 
279
   unsigned long long max_limit;
280
   char tmpstr[50];
281
   int i,h;
282
 
1505 giacomo 283
   if (max_tsc == 0) return 0;
284
 
1501 giacomo 285
   gnuplot_clear();
286
 
287
   max_limit = max_tsc*1000/clk_per_msec;
288
 
289
   for (i=0;i<exec_total;i++)
290
      if (exec_list[i].ctx == context_list[ctx_num].ctx) {
291
        h = (exec_list[i].dtsc*1000/clk_per_msec) * DRAW_NUM / max_limit;
292
        if (h <= DRAW_NUM) draw_data[h]++;
293
      }
294
 
295
   sprintf(tmpstr,"Ctx [%d:%s] Exec C-dist",context_list[ctx_num].ctx,pidstr);
296
   gnuplot_draw(tmpstr,max_limit,0);
297
 
298
   return 0;
299
 
300
}
301
 
302
int plot_job_c_distrib(int ctx_num, unsigned long long max_tsc, char *pidstr) {
303
 
304
   unsigned long long max_limit;
305
   char tmpstr[50];
306
   int i,h;
307
 
1505 giacomo 308
   if (max_tsc == 0) return 0;
309
 
1501 giacomo 310
   gnuplot_clear();
311
 
312
   max_limit = max_tsc*1000/clk_per_msec;
313
 
314
   for (i=0;i<job_total;i++)
315
      if (job_list[i].ctx == context_list[ctx_num].ctx) {
316
        h = (job_list[i].dtsc*1000/clk_per_msec) * DRAW_NUM / max_limit;
317
        if (h <= DRAW_NUM) draw_data[h]++;
318
      }
319
 
320
   sprintf(tmpstr,"Ctx [%d:%s] Job C-dist",context_list[ctx_num].ctx,pidstr);
321
   gnuplot_draw(tmpstr,max_limit,0);
322
 
323
   return 0;
324
 
325
}
326
 
327
int plot_exec_arr_distrib(int ctx_num, unsigned long long max_tsc, char *pidstr) {
328
 
329
  unsigned long long max_limit,last_start,delta_start;
330
  char tmpstr[50];
331
  int i,h;
332
 
1505 giacomo 333
  if (max_tsc == 0) return 0;
334
 
1501 giacomo 335
  gnuplot_clear();
336
 
337
  max_limit = max_tsc*1000/clk_per_msec;
338
 
339
  last_start = 0;
340
  for (i=0;i<exec_total;i++)
341
    if (exec_list[i].ctx == context_list[ctx_num].ctx) {
342
      if (last_start == 0) {
343
              last_start = exec_list[i].start;
344
      } else {
345
              delta_start = exec_list[i].start - last_start;
346
 
347
              h = (delta_start*1000/clk_per_msec) * DRAW_NUM / max_limit;
348
              if (h <= DRAW_NUM) draw_data[h]++;
349
 
350
              last_start = exec_list[i].start;
351
      }
352
    }
353
 
354
  sprintf(tmpstr,"Ctx [%d:%s] Exec Arr.Delta",context_list[ctx_num].ctx,pidstr);
355
  gnuplot_draw(tmpstr,max_limit,0);
356
 
357
  return 0;
358
 
359
}
360
 
361
int plot_job_arr_distrib(int ctx_num, unsigned long long max_tsc, char *pidstr) {
362
 
363
  unsigned long long max_limit,last_start,delta_start;
364
  char tmpstr[50];
365
  int i,h;
366
 
1505 giacomo 367
  if (max_tsc == 0) return 0;
368
 
1501 giacomo 369
  gnuplot_clear();
370
 
371
  max_limit = max_tsc*1000/clk_per_msec;
372
 
373
  last_start = 0;
374
  for (i=0;i<job_total;i++)
375
    if (job_list[i].ctx == context_list[ctx_num].ctx) {
376
      if (last_start == 0) {
377
              last_start = job_list[i].start;
378
      } else {
379
              delta_start = job_list[i].start - last_start;
380
 
381
              h = (delta_start*1000/clk_per_msec) * DRAW_NUM / max_limit;
382
              if (h <= DRAW_NUM) draw_data[h]++;
383
 
384
              last_start = job_list[i].start;
385
      }
386
    }
387
 
388
  sprintf(tmpstr,"Ctx [%d:%s] Job Arr.Delta",context_list[ctx_num].ctx,pidstr);
389
  gnuplot_draw(tmpstr,max_limit,0);
390
 
391
  return 0;
392
 
393
}
394
 
1495 giacomo 395
int create_lists(char *filename) {
396
 
1494 giacomo 397
  FILE *input_file;
398
 
1495 giacomo 399
  int type,par1,par2,k,i,state;
400
 
1494 giacomo 401
  int current_context = 0;
1495 giacomo 402
  int current_exec = 0;
1494 giacomo 403
  int current_endcycle = 0;
404
 
1495 giacomo 405
  unsigned long long last_tsc, tsc;
1494 giacomo 406
 
1495 giacomo 407
  input_file = fopen(filename,"r");
1494 giacomo 408
 
1495 giacomo 409
  /* Memory alloc */
410
  exec_list = malloc(sizeof(struct ctx_exec) * MAXJOB);
411
  context_list = malloc(sizeof(struct ctx_to_pid) * MAXCONTEXT);
412
  endcycle_list = malloc(sizeof(struct endcycle) * MAXJOB);
1494 giacomo 413
 
1495 giacomo 414
  /* Finite-State machine
415
   *
416
   * FS-Machine states:
1494 giacomo 417
 
418
 
419
        1 - Context running
420
        2 - Interrupt running
421
 
422
        10 - End
423
 
1495 giacomo 424
   */
1494 giacomo 425
 
426
  for(i=0;i<MAXCONTEXT;i++) {
1495 giacomo 427
    context_list[i].ctx = 0;
428
    context_list[i].pid = PID_NO_DEF;
1494 giacomo 429
  }
430
 
431
  /* The start context + interrupt context */
1495 giacomo 432
  context_total = 2;
1494 giacomo 433
  current_context = 0;
434
  last_tsc = 0;
435
  context_list[0].ctx = 0;
436
  context_list[0].pid = PID_NO_DEF;
437
  context_list[1].ctx = INT_CTX;
438
  context_list[1].pid = INT_PID;
439
 
440
  state = 0;
441
 
442
  k = 0;
443
  while(!feof(input_file)) {
444
 
445
    fscanf(input_file,"%d %llu",&type,&tsc);
446
    k++;
447
 
448
    switch (type) {
449
 
450
        case 0:
451
        case 1:
452
 
453
                /* No par */
454
                break;
455
 
456
        case 2:
457
        case 3:
458
        case 4:
459
        case 6:
460
        case 7:
461
        case 8:
462
 
463
                /* 1 par */
464
                fscanf(input_file,"%d",&par1);
465
                break;
466
 
467
        case 5:
468
                /* 2 par */
469
                fscanf(input_file,"%d %d",&par1,&par2);
470
                break;
471
 
472
    }
473
 
474
    switch (type) {
475
 
476
        case 0:
477
                if (state != 0) Error(1);
478
                printf("EVT:Log starts at [%12llu]\n",tsc);
479
                last_tsc = tsc;
480
                log_start_tsc = tsc;
1495 giacomo 481
                exec_list[current_exec].start = tsc;
1494 giacomo 482
                state = 1;
483
                break;
484
 
485
        case 1:
486
                printf("EVT:Log   ends at [%12llu]\n",tsc);
1495 giacomo 487
                exec_list[current_exec].dtsc = tsc - last_tsc;
488
                exec_list[current_exec].ctx = current_context;
489
                current_exec++;
1494 giacomo 490
                last_tsc = tsc;
491
                log_end_tsc = tsc;
492
                state = 10;
493
                break;
494
 
495
        /* Int start */
496
        case 2:
497
                if (state == 0) Error(2);
1495 giacomo 498
                exec_list[current_exec].dtsc = tsc - last_tsc;
499
                exec_list[current_exec].ctx = current_context;
500
                current_exec++;
1494 giacomo 501
                last_tsc = tsc;
502
                current_context = INT_CTX;
1495 giacomo 503
                exec_list[current_exec].start = tsc;
1494 giacomo 504
                state = 2;
505
                break;
506
 
507
        /* Int end */
508
        case 3:
509
                if (state != 2) Error(3);              
1495 giacomo 510
                exec_list[current_exec].dtsc = tsc - last_tsc;
511
                exec_list[current_exec].ctx = current_context;
512
                current_exec++;
1494 giacomo 513
                last_tsc = tsc;
514
                current_context = par1;
515
 
1495 giacomo 516
                for (i=0;i<context_total;i++)
1494 giacomo 517
                        if (par1 == context_list[i].ctx) break;
1495 giacomo 518
                if (i == context_total) {
519
                        context_list[context_total].ctx = par1;
520
                        context_total++;
1494 giacomo 521
                }
522
 
1495 giacomo 523
                exec_list[current_exec].start = tsc;
1494 giacomo 524
                state = 1;
525
                break;
526
 
527
        /* Change ctx */
528
        case 4:
529
 
1495 giacomo 530
                exec_list[current_exec].dtsc = tsc - last_tsc;
531
                exec_list[current_exec].ctx = current_context;
532
                current_exec++;
1494 giacomo 533
                last_tsc = tsc;
534
                current_context = par1;
535
 
1495 giacomo 536
                for (i=0;i<context_total;i++)
1494 giacomo 537
                        if (par1 == context_list[i].ctx) break;
1495 giacomo 538
                if (i == context_total) {
539
                        context_list[context_total].ctx = par1;
540
                        context_total++;
1494 giacomo 541
                }
542
 
1495 giacomo 543
                exec_list[current_exec].start = tsc;
1494 giacomo 544
                state = 1;
545
                break;
546
 
547
        /* Task create */
548
        case 5:
549
 
1495 giacomo 550
                for (i=0;i<context_total;i++)
1494 giacomo 551
                        if (par1 == context_list[i].ctx) break;
1495 giacomo 552
                if (i == context_total) {
553
                        context_list[context_total].ctx = par1;
554
                        context_list[context_total].pid = par2;
555
                        context_total++;
1494 giacomo 556
                }
557
 
558
                break;
559
 
560
        /* Task endcycle */
561
        case 8:
562
 
1495 giacomo 563
                for (i=0;i<context_total;i++)
1494 giacomo 564
                        if (par1 == context_list[i].ctx) break;
1495 giacomo 565
                if (i == context_total) Error(4);
1494 giacomo 566
 
567
                endcycle_list[current_endcycle].ctx = par1;
568
                endcycle_list[current_endcycle].tsc = tsc;
569
                current_endcycle++;
570
 
571
                break;
572
 
573
    }
574
 
1495 giacomo 575
    if (current_exec == MAXJOB-1) {
576
        printf("Too many execs...\n");
1494 giacomo 577
        exit(3);
578
    }
579
 
580
    if (current_endcycle == MAXJOB-1) {
581
        printf("Too many endcycle...\n");
582
        exit(4);
583
    }
584
 
585
    if (state == 10) break;
586
 
587
  }
588
 
1495 giacomo 589
  endcycle_total = current_endcycle;
590
  exec_total = current_exec;
1494 giacomo 591
 
1495 giacomo 592
  return k;
1494 giacomo 593
 
1495 giacomo 594
}
1494 giacomo 595
 
1495 giacomo 596
int create_job_list() {
1494 giacomo 597
 
1495 giacomo 598
  int current_job = 0, h, i, k;
599
  int temp_ctx;
600
  unsigned long long temp_tsc, endcycle_start_tsc;
601
  unsigned long long endcycle_end_tsc;
1494 giacomo 602
 
1495 giacomo 603
  job_list = malloc(sizeof(struct ctx_exec) * MAXJOB);
1494 giacomo 604
 
1495 giacomo 605
  for (k=0;k<context_total;k++) {
1494 giacomo 606
 
1495 giacomo 607
    temp_ctx = context_list[k].ctx;
608
    endcycle_start_tsc = 0;
1494 giacomo 609
 
1495 giacomo 610
    for (h=0;h<endcycle_total;h++) {
1494 giacomo 611
 
1495 giacomo 612
      if (endcycle_list[h].ctx == temp_ctx) {
1494 giacomo 613
 
1495 giacomo 614
        if (endcycle_start_tsc == 0)
615
          endcycle_start_tsc = log_start_tsc;
1494 giacomo 616
 
617
        endcycle_end_tsc = endcycle_list[h].tsc;
618
        temp_tsc = 0;
619
 
1495 giacomo 620
        job_list[current_job].start = 0;
1494 giacomo 621
 
1495 giacomo 622
        for(i=0;i<exec_total;i++)
623
                if (exec_list[i].ctx == temp_ctx) {
624
                        if (exec_list[i].start < endcycle_end_tsc &&
625
                                exec_list[i].start >= endcycle_start_tsc) {
626
                                if (job_list[current_job].start == 0)
627
                                  job_list[current_job].start = exec_list[i].start;
628
                                temp_tsc += exec_list[i].dtsc;
1494 giacomo 629
                        }
630
                }
631
 
1495 giacomo 632
        job_list[current_job].dtsc = temp_tsc;
633
        job_list[current_job].ctx = temp_ctx;
634
        current_job++;
1494 giacomo 635
 
636
        endcycle_start_tsc = endcycle_end_tsc;
637
 
1495 giacomo 638
      }
1494 giacomo 639
 
1495 giacomo 640
    }
1494 giacomo 641
 
1495 giacomo 642
  }    
643
 
644
  job_total = current_job;
645
 
1494 giacomo 646
  return 0;
647
 
648
}
649
 
1495 giacomo 650
int elaborate_statistics(int num, int task_type) {
651
 
1501 giacomo 652
  char pidstr[10];
653
  unsigned long long tot_tsc,mean_tsc,max_tsc,min_tsc,first_tsc;
654
  int number;
1495 giacomo 655
 
656
  switch (context_list[num].pid) {
657
      case PID_NO_DEF:
658
        sprintf(pidstr,"NODEF");
659
        break;
660
      case INT_PID:
661
        sprintf(pidstr,"  INT");
662
        break;
663
      default:
664
        sprintf(pidstr,"%5d",context_list[num].pid);
665
        break;
666
  }
667
 
668
  if (task_type == BACKGROUND) {
669
 
670
    printf("Background Task CTX [%5d] PID [%s]\n",context_list[num].ctx,pidstr);
671
 
1501 giacomo 672
    stats_from_execs(num,&tot_tsc,&min_tsc,&mean_tsc,&max_tsc,&first_tsc,&number);    
673
 
674
    printf("  Total Execution dTSC [%12llu] us [%12llu]\n",tot_tsc,tot_tsc*1000/clk_per_msec);
675
    printf("  Mean  CPU Bandwidth  [%11f%c]\n",(double)(tot_tsc)/(double)(total_dtsc)*100.0,'%');
676
    printf("    after first exec   [%11f%c]\n",(double)(tot_tsc)/(double)(total_dtsc-first_tsc)*100.0,'%');
677
    printf("  Execs Number         [%12d]\n",number);
1499 giacomo 678
    printf("  Min  Exec       dTSC [%12llu] us [%12llu]\n",min_tsc, min_tsc*1000/clk_per_msec);
1501 giacomo 679
    printf("  Mean Exec       dTSC [%12llu] us [%12llu]\n",mean_tsc, mean_tsc*1000/clk_per_msec);
1497 giacomo 680
    printf("  Max  Exec       dTSC [%12llu] us [%12llu]\n\n",max_tsc, max_tsc*1000/clk_per_msec);
1495 giacomo 681
 
1501 giacomo 682
    plot_exec_demand_function(num,pidstr);
1500 giacomo 683
 
1495 giacomo 684
  }
685
 
686
  if (task_type == INTERRUPT) {
687
 
688
    printf("Interrupts\n");
689
 
1501 giacomo 690
    stats_from_execs(num,&tot_tsc,&min_tsc,&mean_tsc,&max_tsc,&first_tsc,&number);
1499 giacomo 691
 
1501 giacomo 692
    printf("  Total Execution dTSC [%12llu] us [%12llu]\n",tot_tsc,tot_tsc*1000/clk_per_msec);
693
    printf("  Mean  CPU Bandwidth  [%11f%c]\n",(double)(tot_tsc)/(double)(total_dtsc)*100.0,'%');
694
    printf("    after first int    [%11f%c]\n",(double)(tot_tsc)/(double)(total_dtsc-first_tsc)*100.0,'%');
695
    printf("  Interrupts Number    [%12d]\n",number);
1499 giacomo 696
    printf("  Min  Interrupt  dTSC [%12llu] us [%12llu]\n",min_tsc,min_tsc*1000/clk_per_msec);
1501 giacomo 697
    printf("  Mean Interrupt  dTSC [%12llu] us [%12llu]\n",mean_tsc,mean_tsc*1000/clk_per_msec);
1497 giacomo 698
    printf("  Max  Interrupt  dTSC [%12llu] us [%12llu]\n\n",max_tsc,max_tsc*1000/clk_per_msec);
1495 giacomo 699
 
1501 giacomo 700
    plot_exec_c_distrib(num,max_tsc,pidstr);
1500 giacomo 701
 
1501 giacomo 702
    arr_stats_from_execs(num,&min_tsc,&mean_tsc,&max_tsc);
1499 giacomo 703
 
1505 giacomo 704
    if (max_tsc > 0) {
1496 giacomo 705
 
1505 giacomo 706
      printf("  Min  Arr. Delta dTSC [%12llu] us [%12llu]\n",min_tsc,min_tsc*1000/clk_per_msec);
707
      printf("  Mean Arr. Delta dTSC [%12llu] us [%12llu]\n",mean_tsc,mean_tsc*1000/clk_per_msec);
708
      printf("  Max  Arr. Delta dTSC [%12llu] us [%12llu]\n\n",max_tsc,max_tsc*1000/clk_per_msec);
1499 giacomo 709
 
1505 giacomo 710
      plot_exec_arr_distrib(num,max_tsc,pidstr);
711
 
712
    }
713
 
1495 giacomo 714
  }
715
 
716
  if (task_type == PERIODICAL) {
717
 
718
    printf("Periodical Task CTX [%5d] PID [%s]\n",context_list[num].ctx,pidstr);    
719
 
1501 giacomo 720
    stats_from_execs(num,&tot_tsc,&min_tsc,&mean_tsc,&max_tsc,&first_tsc,&number);
721
 
722
    printf("  Total Execution dTSC [%12llu] us [%12llu]\n",tot_tsc,tot_tsc*1000/clk_per_msec);
723
    printf("  Mean  CPU Bandwidth  [%11f%c]\n",(double)(tot_tsc)/(double)(total_dtsc)*100.0,'%');
724
    printf("    after first exec   [%11f%c]\n",(double)(tot_tsc)/(double)(total_dtsc-first_tsc)*100.0,'%');
725
    printf("  Execs Number         [%12d]\n",number);
1499 giacomo 726
    printf("  Min  Exec       dTSC [%12llu] us [%12llu]\n",min_tsc,min_tsc*1000/clk_per_msec);
1501 giacomo 727
    printf("  Mean Exec       dTSC [%12llu] us [%12llu]\n",mean_tsc,mean_tsc*1000/clk_per_msec);
1497 giacomo 728
    printf("  Max  Exec       dTSC [%12llu] us [%12llu]\n\n",max_tsc,max_tsc*1000/clk_per_msec);    
1495 giacomo 729
 
1501 giacomo 730
    plot_exec_demand_function(num,pidstr);
1500 giacomo 731
 
1501 giacomo 732
    stats_from_jobs(num,&tot_tsc,&min_tsc,&mean_tsc,&max_tsc,&first_tsc,&number);  
733
 
734
    printf("  Total Job Exec  dTSC [%12llu] us [%12llu]\n",tot_tsc,tot_tsc*1000/clk_per_msec);
735
    printf("  Jobs Number          [%12d]\n",number);
1499 giacomo 736
    printf("  Min  Job        dTSC [%12llu] us [%12llu]\n",min_tsc,min_tsc*1000/clk_per_msec);
1501 giacomo 737
    printf("  Mean Job        dTSC [%12llu] us [%12llu]\n",mean_tsc,mean_tsc*1000/clk_per_msec);
1497 giacomo 738
    printf("  Max  Job        dTSC [%12llu] us [%12llu]\n\n",max_tsc,max_tsc*1000/clk_per_msec);
1496 giacomo 739
 
1501 giacomo 740
    plot_job_c_distrib(num,max_tsc,pidstr);
1499 giacomo 741
 
1501 giacomo 742
    arr_stats_from_jobs(num,&min_tsc,&mean_tsc,&max_tsc);
1499 giacomo 743
 
1505 giacomo 744
    if (max_tsc > 0) {
745
 
746
      printf("  Min  Arr. Delta dTSC [%12llu] us [%12llu]\n",min_tsc,min_tsc*1000/clk_per_msec);
747
      printf("  Mean Arr. Delta dTSC [%12llu] us [%12llu]\n",mean_tsc,mean_tsc*1000/clk_per_msec);
748
      printf("  Max  Arr. Delta dTSC [%12llu] us [%12llu]\n\n",max_tsc,max_tsc*1000/clk_per_msec);
1495 giacomo 749
 
1505 giacomo 750
      plot_job_arr_distrib(num,max_tsc,pidstr);
1499 giacomo 751
 
1505 giacomo 752
    }
753
 
1495 giacomo 754
  }
755
 
756
  return 0;
757
 
758
}
759
 
760
int main(int argc, char *argv[]) {
761
 
762
  int events_total,k,i;
763
  int task_type;
764
  unsigned long long total_tsc;
765
 
1500 giacomo 766
  srand(getpid());
767
 
1497 giacomo 768
  if (argc < 3) {
769
    printf("%s: Enter the input file name and clk_per_msec [%s filename clk_per_msec]\n",argv[0],argv[0]);
1495 giacomo 770
    exit(1);
771
  }
772
 
773
  printf("\n");
1497 giacomo 774
 
775
  clk_per_msec = atoi(argv[2]);
776
 
777
  printf("Clk/msec = %u\n\n",clk_per_msec);
778
 
1495 giacomo 779
  events_total = create_lists(argv[1]);
780
 
1499 giacomo 781
  total_dtsc = log_end_tsc - log_start_tsc;
1495 giacomo 782
 
1499 giacomo 783
  printf("\nTotal dTSC [%12llu] us [%12llu]\n", total_dtsc, total_dtsc*1000/clk_per_msec);
784
  printf("Events     [%12d]\n",events_total);
785
  printf("Execs      [%12d]\n",exec_total);
786
  printf("EndCycles  [%12d]\n",endcycle_total);
787
 
1495 giacomo 788
  total_tsc = 0;
789
  for (i=0;i<exec_total;i++)
790
        total_tsc += exec_list[i].dtsc;
791
 
792
  /* Exec total execution check */
793
  printf("\nExec TSC sum = %llu (%2.2f)\n",total_tsc,(float)total_tsc/((float)(log_end_tsc - log_start_tsc))*100.0);
794
 
795
  printf("\nPreemption Removing.... \n");
796
 
797
  /* Remove preemption from the computation time */
798
  create_job_list();
1500 giacomo 799
/*
1495 giacomo 800
  for (k=0;k<job_total;k++)
801
        printf("Job CTX [%5d] Start [%12llu] dTSC [%12llu]\n",
802
                job_list[k].ctx,job_list[k].start,job_list[k].dtsc);
1500 giacomo 803
*/
1495 giacomo 804
  printf("\nCompute Task Statistics.... \n\n");
805
 
806
  for (i=0;i<context_total;i++) {
807
 
808
        task_type = BACKGROUND;
809
 
810
        if (context_list[i].ctx == INT_CTX) task_type = INTERRUPT;
811
 
812
        for (k=0;k<job_total;k++)
813
                if (job_list[k].ctx == context_list[i].ctx) {
814
                  task_type = PERIODICAL;
815
                  break;
816
                }
817
 
818
        elaborate_statistics(i,task_type);
819
 
820
  }
1500 giacomo 821
 
1495 giacomo 822
  return 0;
823
 
824
}
825