Subversion Repositories shark

Rev

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