meta-agl-bsp: Update i.MX8MQ EVK support for kirkstone
[AGL/meta-agl.git] / meta-agl-bsp / meta-ti / recipes-arago / weston / weston / 0001-Add-soc-performance-monitor-utilites.patch
1 From 7830118ecb980766f4a6e3997769d7ae326bee77 Mon Sep 17 00:00:00 2001
2 From: Karthik Ramanan <a0393906@ti.com>
3 Date: Fri, 3 Jun 2016 18:32:50 +0530
4 Subject: [PATCH] Add soc performance monitor utilites
5
6 Signed-off-by: Karthik Ramanan <a0393906@ti.com>
7 ---
8  Makefile.am                       |   17 +-
9  clients/Dra7xx_ddrstat_speed.c    |  494 +++++++++++++
10  clients/soc_performance_monitor.c |  630 ++++++++++++++++
11  clients/soc_performance_monitor.h |   40 ++
12  clients/statcoll.c                | 1433 +++++++++++++++++++++++++++++++++++++
13  clients/statcoll.h                |  152 ++++
14  clients/statcoll_gui.h            |  101 +++
15  clients/time_bar_graph.c          |  515 +++++++++++++
16  clients/time_bar_graph.h          |   93 +++
17  10 files changed, 4873 insertions(+), 1 deletion(-)
18  create mode 100644 clients/Dra7xx_ddrstat_speed.c
19  create mode 100644 clients/soc_performance_monitor.c
20  create mode 100644 clients/soc_performance_monitor.h
21  create mode 100644 clients/statcoll.c
22  create mode 100644 clients/statcoll.h
23  create mode 100644 clients/statcoll_gui.h
24  create mode 100644 clients/time_bar_graph.c
25  create mode 100644 clients/time_bar_graph.h
26
27 diff --git a/Makefile.am b/Makefile.am
28 index 62719c9..55aed6d 100644
29 --- a/Makefile.am
30 +++ b/Makefile.am
31 @@ -432,7 +432,9 @@ demo_clients =                                      \
32         weston-fullscreen                       \
33         weston-stacking                         \
34         weston-calibrator                       \
35 -       weston-scaler
36 +       weston-scaler                           \
37 +       soc-performance-monitor                 \
38 +       soc-ddr-bw-visualizer
39  
40  if INSTALL_DEMO_CLIENTS
41  bin_PROGRAMS += $(demo_clients)
42 @@ -570,6 +572,19 @@ weston_image_SOURCES = clients/image.c
43  weston_image_LDADD = libtoytoolkit.la
44  weston_image_CFLAGS = $(AM_CFLAGS) $(CLIENT_CFLAGS)
45  
46 +noinst_LTLIBRARIES += libtimebargraph.la
47 +libtimebargraph_la_SOURCES = clients/time_bar_graph.c clients/time_bar_graph.h
48 +libtimebargraph_la_LIBADD = libtoytoolkit.la
49 +libtimebargraph_la_CFLAGS = $(AM_CFLAGS) $(CLIENT_CFLAGS) $(CAIRO_CFLAGS) $(CAIRO_EGL_CFLAGS)
50 +
51 +soc_performance_monitor_SOURCES = clients/soc_performance_monitor.c clients/soc_performance_monitor.h 
52 +soc_performance_monitor_LDADD = libtoytoolkit.la libtimebargraph.la
53 +soc_performance__CFLAGS = $(AM_CFLAGS) $(CLIENT_CFLAGS)
54 +
55 +soc_ddr_bw_visualizer_SOURCES = clients/statcoll.c clients/Dra7xx_ddrstat_speed.c  clients/statcoll.h clients/statcoll_gui.h 
56 +soc_ddr_bw_visualizer_LDADD = libtoytoolkit.la libtimebargraph.la 
57 +soc_ddr_bw_visualizer__CFLAGS = $(AM_CFLAGS) $(CLIENT_CFLAGS)
58 +
59  weston_cliptest_SOURCES =                              \
60         clients/cliptest.c                              \
61         src/vertex-clipping.c                           \
62 diff --git a/clients/Dra7xx_ddrstat_speed.c b/clients/Dra7xx_ddrstat_speed.c
63 new file mode 100644
64 index 0000000..af06733
65 --- /dev/null
66 +++ b/clients/Dra7xx_ddrstat_speed.c
67 @@ -0,0 +1,494 @@
68 +/*
69 + * Copyright (C) 2015 Texas Instruments
70 + * Author: Karthik Ramanan <karthik.ramanan@ti.com>
71 + *
72 + * This program is free software; you can redistribute it and/or modify it
73 + * under the terms of the GNU General Public License version 2 as published by
74 + * the Free Software Foundation.
75 + *
76 + * This program is distributed in the hope that it will be useful, but WITHOUT
77 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
79 + * more details.
80 + *
81 + * You should have received a copy of the GNU General Public License along with
82 + * this program.  If not, see <http://www.gnu.org/licenses/>.
83 + */
84 +
85 +#include <stdio.h>
86 +#include <stdlib.h>
87 +#include <stdint.h>
88 +#include <string.h>
89 +#include <sys/mman.h>
90 +#include <sys/time.h>
91 +#include <unistd.h>
92 +#include <fcntl.h>
93 +#include "statcoll.h"
94 +
95 +#define PAGE_SIZE 4096
96 +
97 +#define EMIF1_BASE 0x4c000000
98 +#define EMIF2_BASE 0x4d000000
99 +
100 +#define EMIF_PERF_CNT_1     0x80
101 +#define EMIF_PERF_CNT_2     0x84
102 +#define EMIF_PERF_CNT_CFG   0x88
103 +#define EMIF_PERF_CNT_TIM   0x90
104 +
105 +static unsigned
106 +tv_diff(struct timeval *tv1, struct timeval *tv2)
107 +{
108 +    return (tv2->tv_sec - tv1->tv_sec) * 1000000 +
109 +        (tv2->tv_usec - tv1->tv_usec);
110 +}
111 +
112 +
113 +struct emif_perf {
114 +    int code;
115 +    const char *name;
116 +};
117 +
118 +static const struct emif_perf emif_perf_tab[] = {
119 +    {  0, "access"     },
120 +    {  1, "activate"   },
121 +    {  2, "read"       },
122 +    {  3, "write"      },
123 +    {  4, "fifo_cmd"   },
124 +    {  5, "fifo_write" },
125 +    {  6, "fifo_read"  },
126 +    {  7, "fifo_ret"   },
127 +    {  8, "prio"       },
128 +    {  9, "cmd_pend"   },
129 +    { 10, "data"       },
130 +};
131 +
132 +static void *emif1, *emif2;
133 +static int BANDWIDTH=0;
134 +static int DELAY = 1;
135 +static int EMIF_PERF_CFG1 = 9;
136 +static int EMIF_PERF_CFG2 = 10;
137 +
138 +
139 +static int STATCOLL=0;
140 +static int TOTAL_TIME;
141 +static int INTERVAL_US;
142 +
143 +struct timeval t1, t2;
144 +
145 +FILE* outfile;
146 +struct emif_stats {
147 +    uint32_t cycles;
148 +    uint32_t cnt1;
149 +    uint32_t cnt2;
150 +};
151 +
152 +static struct emif_stats emif1_start, emif1_end;
153 +static struct emif_stats emif2_start, emif2_end;
154 +
155 +static void *emif_init(int fd, unsigned base)
156 +{
157 +    void *mem =
158 +        mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, base);
159 +    volatile uint32_t *emif = mem,temp;
160 +    
161 +   if (mem == MAP_FAILED){
162 +        return NULL;
163 +    }
164 +
165 +    emif[EMIF_PERF_CNT_CFG>>2] = EMIF_PERF_CFG2 << 16 | EMIF_PERF_CFG1;
166 +   
167 +    return mem;
168 +}
169 +
170 +static void emif_read(volatile uint32_t *emif, struct emif_stats *st)
171 +{
172 +    st->cycles = emif[EMIF_PERF_CNT_TIM>>2];
173 +    st->cnt1   = emif[EMIF_PERF_CNT_1>>2];
174 +    st->cnt2   = emif[EMIF_PERF_CNT_2>>2];
175 +}
176 +
177 +static void emif_print(const char *tag, struct emif_stats *st1,
178 +                       struct emif_stats *st2)
179 +{
180 +    uint32_t cycles = st2->cycles - st1->cycles;
181 +    uint32_t cnt1   = st2->cnt1   - st1->cnt1;
182 +    uint32_t cnt2   = st2->cnt2   - st1->cnt2;
183 +    printf("%s %s %2llu%% %s %2llu%%", tag,
184 +           emif_perf_tab[EMIF_PERF_CFG1].name, 100ull*cnt1/cycles,
185 +           emif_perf_tab[EMIF_PERF_CFG2].name, 100ull*cnt2/cycles);
186 +    fprintf(outfile,"%s%s= %2llu,%s%s= %2llu,", 
187 +           tag, emif_perf_tab[EMIF_PERF_CFG1].name, 100ull*cnt1/cycles,
188 +           tag, emif_perf_tab[EMIF_PERF_CFG2].name, 100ull*cnt2/cycles);
189 +}
190 +
191 +static int perf_init(void)
192 +{
193 +    int fd = open("/dev/mem", O_RDWR);
194 +    int err = 0;
195 +
196 +    if (fd == -1){
197 +       printf("error fd=open() \n");     
198 +       return -1;
199 +    }
200 +    emif1 = emif_init(fd, EMIF1_BASE);
201 +    emif2 = emif_init(fd, EMIF2_BASE);
202 +
203 +    if (!emif1 || !emif2){
204 +         printf("error if (!emif1 || !emif2) \n");       
205 +         err = -1;
206 +    }
207 +
208 +    close(fd);
209 +    return err;
210 +}
211 +
212 +static void perf_start(void)
213 +{
214 +    if (emif1) {
215 +        emif_read(emif1, &emif1_start);
216 +        emif_read(emif2, &emif2_start);
217 +    }
218 +}
219 +
220 +static void perf_stop(void)
221 +{
222 +    if (emif1) {
223 +        emif_read(emif1, &emif1_end);
224 +        emif_read(emif2, &emif2_end);
225 +    }
226 +}
227 +
228 +static void perf_print(void)
229 +{
230 +    if (emif1) {
231 +        emif_print("EMIF1", &emif1_start, &emif1_end);
232 +        printf("\t");
233 +        emif_print("EMIF2", &emif2_start, &emif2_end);
234 +        printf("\r");
235 +       fprintf(outfile, "\n");
236 +       fflush(outfile);
237 +       fflush(stdout);
238 +    }
239 +}
240 +
241 +static void perf_close(void)
242 +{
243 +    if (emif1) munmap(emif1, PAGE_SIZE);
244 +    if (emif2) munmap(emif2, PAGE_SIZE);
245 +}
246 +
247 +static int get_cfg(const char *name, int def)
248 +{
249 +    char *end;
250 +    int n = strtol(name, &end, 0);
251 +    int i;
252 +
253 +    if (!*end)
254 +        return n;
255 +
256 +    for (i = 0; i < sizeof(emif_perf_tab)/sizeof(emif_perf_tab[0]); i++)
257 +        if (!strcmp(name, emif_perf_tab[i].name))
258 +            return emif_perf_tab[i].code;
259 +
260 +    return def;
261 +}
262 +
263 +
264 +unsigned int emif_freq()
265 +{
266 +    volatile unsigned *tim1;
267 +    unsigned v1, v2;
268 +    int fd;
269 +    
270 +    /*calculation EMIF frequency 
271 +      EMIF_PERF_CNT_TIM = \n32-bit counter that 
272 +      continuously counts number for 
273 +      EMIF_FCLK clock cycles elapsed 
274 +      after EMIFis brought out of reset*/
275 +
276 +    fd = open("/dev/mem", O_RDONLY);
277 +    if (fd == -1) {
278 +        perror("/dev/mem");
279 +        return 1;
280 +    }
281 +
282 +    void *mem =
283 +    mem = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, fd, EMIF1_BASE);
284 +    if (mem == MAP_FAILED) {
285 +        perror("mmap");
286 +        exit(1);
287 +    }
288 +
289 +    tim1 = (unsigned *)((char*)mem + EMIF_PERF_CNT_TIM);
290 +
291 +    v1 = *tim1;
292 +    gettimeofday(&t1, NULL);
293 +    sleep(2);
294 +    v2 = *tim1;
295 +    gettimeofday(&t2, NULL);
296 +    
297 +    munmap(mem, PAGE_SIZE);
298 +    close(fd);
299 +
300 +    return (v2 - v1) / tv_diff(&t1, &t2);
301 +
302 +}
303 +
304 +
305 +char config_file_path[100];
306 +char keylist[][50] = {
307 +       "DELAY",
308 +       "EMIF_PERF_CFG1",
309 +       "EMIF_PERF_CFG2",
310 +       "BANDWIDTH",
311 +       "STATCOLL",
312 +       "TOTAL_TIME",
313 +       "INTERVAL_US",
314 +       "INITIATORS",
315 +};
316 +
317 +char line[512], *p;
318 +char tokens[6][512];
319 +int temp, flag = 0;
320 +char *keyvalue, *pair;
321 +char key[100];
322 +int linecount=0;
323 +
324 +
325 +int debug=0;
326 +
327 +void print_valid_options(void)
328 +{
329 +   int i;
330 +        printf("Invalid key found\n");
331 +       printf("Supported keys are :\n");
332 +       for(i=0; i<sizeof(keylist)/sizeof(keylist[0]); i++)
333 +               printf("\t\t %s\n", keylist[i]);
334 +
335 +}
336 +int validatekey(char *ptr)
337 +{
338 +       int i;
339 +       for(i=0; i<sizeof(keylist)/sizeof(keylist[0]); i++)
340 +               if(strcmp(ptr, keylist[i]) == 0)
341 +                       return 0;
342 +
343 +       return 1;
344 +}
345 +
346 +void add_key_value(char *key, int value)
347 +{
348 +       printd("%s", "Inside add_key_value\n");
349 +       
350 +       if(strcmp(key, "BANDWIDTH") == 0) {
351 +               BANDWIDTH = value;
352 +               return;
353 +       }
354 +       if(strcmp(key, "STATCOLL") == 0) {
355 +               STATCOLL = value;
356 +               return;
357 +       }
358 +       else
359 +               printd("%s", "********** UNKNOWN**********");
360 +
361 +       if(BANDWIDTH == 1) {
362 +               if(strcmp(key, "DELAY") == 0)
363 +                       DELAY = value;
364 +               else if(strcmp(key, "EMIF_PERF_CFG1") == 0)
365 +                       EMIF_PERF_CFG1 = value;
366 +               else if(strcmp(key, "EMIF_PERF_CFG2") == 0)
367 +                       EMIF_PERF_CFG2 = value;
368 +       }
369 +       else
370 +               printf("NOTE: BANDWIDTH is not enabled, ignoring %s\n", key);
371 +
372 +
373 +        if(STATCOLL == 1) {
374 +               if(strcmp(key, "INTERVAL_US") == 0)
375 +                       INTERVAL_US = value;
376 +               else if(strcmp(key, "TOTAL_TIME") == 0)
377 +                       TOTAL_TIME = value;
378 +        }
379 +       else
380 +               printf("NOTE: STATCOLL is not enabled, ignoring %s\n", key);
381 +}
382 +
383 +void bandwidth_usage() {
384 +
385 +    printf("#########################################################\n##\n"
386 +
387 +           "##  usage    : ./Dra7xx_ddrstat   <DELAY>  <EMIF_PERF_CFG1>  <EMIF_PERF_CFG2> \n"
388 +           "##  default  :                    DELAY=1  EMIF_PERF_CFG1=9  EMIF_PERF_CFG2=10\n"  
389 +           "##  option   : for EMIF_PERF_CFG1 and EMIF_PERF_CFG2\n"
390 +           "##             0  -> access,\n"  
391 +           "##             1  -> activate,\n"
392 +           "##             2  -> read,\n"
393 +           "##             3  -> write,\n"
394 +           "##             4  -> fifo_cmd,\n"
395 +           "##             5  -> fifo_write,\n"
396 +           "##             6  -> fifo_read,\n"
397 +           "##             7  -> fifo_ret,\n"
398 +           "##             8  -> prio,\n"
399 +           "##             9  -> cmd_pend,\n"
400 +           "##             10 -> data    \n##\n"
401 +
402 +           "##  EMIF frq : %d MHz\n\n", emif_freq() );
403 +}
404 +
405 +
406 +int main(int argc, char **argv)
407 +{
408 +    int option;
409 +    FILE *fp;
410 +    int i;
411 +    int xpos = 600, ypos = 40;
412 +    
413 +    
414 +    /* Read config file */
415 +    /* Initialize this to turn off verbosity of getopt */
416 +    opterr = 0;
417 +
418 +//    while ((option = getopt (argc, argv, "df:")) != -1)
419 +    while ((option = getopt (argc, argv, "dx:y:")) != -1)
420 +    {
421 +           switch(option)
422 +           {
423 +#if 0
424 +                   case 'f':
425 +                           strcpy(config_file_path, optarg);
426 +                           break;
427 +#endif
428 +                   case 'd':
429 +                           debug=1;
430 +                           break;
431 +                   case 'x':
432 +                           xpos=atoi(optarg);
433 +                           break;
434 +                   case 'y':
435 +                           ypos=atoi(optarg);
436 +                           break;
437 +                   
438 +                   default:
439 +                           printf("Invalid option.. Exiting\n");
440 +                           exit(0);
441 +           }
442 +    }
443 +
444 +    printf("xpos = %d, ypos = %d\n", xpos, ypos);
445 +
446 +    strcpy(config_file_path,"config.ini");
447 +    fp = fopen(config_file_path, "r");
448 +    if (fp == NULL) {
449 +           fprintf(stderr, "couldn't open the specified file\n");
450 +           return -1;
451 +    }
452 +
453 +    while (fgets(line, sizeof line, fp)) {
454 +           printd("Line is = %s", line);
455 +
456 +           if (line[0] == '#' || line[0] == '\n') {
457 +                   continue;
458 +           }
459 +
460 +           memset(tokens, 0, sizeof(tokens));
461 +           i = 0;
462 +
463 +           pair = strtok (line," ,");
464 +           while (pair != NULL)
465 +           {
466 +                   printd ("\tPair is = %s\n",pair);
467 +                   strcpy(tokens[i++], pair);
468 +                   pair = strtok (NULL, " ,.-");
469 +           }
470 +
471 +           for(temp=0; temp< i; temp++)
472 +           {
473 +                   printd("Line %d: %s\n", temp, tokens[temp]);
474 +
475 +                   keyvalue = strtok (tokens[temp]," =");
476 +                   while (keyvalue != NULL)
477 +                   {
478 +                           if(flag == 0)
479 +                           {
480 +                                   if(validatekey(keyvalue))
481 +                                   {
482 +                                            print_valid_options();
483 +                                           exit(0);
484 +                                   }
485 +                                   strcpy(key, keyvalue);
486 +                                   printd ("\tKey is = %s\n",key);
487 +                                   flag++;
488 +                           }
489 +                           else
490 +                           {
491 +                                   printd ("\tValue is = %s",keyvalue);
492 +                                   printd (" (%d)\n", atoi(keyvalue));
493 +                                   add_key_value(key, atoi(keyvalue));
494 +                                   flag = 0;
495 +                           }
496 +                           keyvalue = strtok (NULL, " =");
497 +                   }
498 +           }
499 +
500 +
501 +
502 +           linecount++;
503 +           printd("%s", "------------------- \n");
504 +
505 +    }
506 +
507 +    fclose(fp);
508 +
509 +    printf("\n\nCOMPLETED: Parsing of the user specified parameters.. \n \
510 +                \nConfiguring device now.. \n\n");
511 +    if(BANDWIDTH == 1) {
512 +           bandwidth_usage();
513 +           if (DELAY <= 0)
514 +                   DELAY = 1;
515 +
516 +           if (perf_init()){
517 +                   printf("perf_init return non zero \n");
518 +                   return 1;
519 +           }
520 +
521 +           outfile = fopen("emif-performance.csv", "w+");
522 +           if (!outfile) {
523 +                   printf("\n Error opening file");
524 +           }
525 +           for (;;) {
526 +                   perf_start();
527 +                   sleep(DELAY);
528 +                   perf_stop();
529 +                   perf_print();
530 +           }
531 +
532 +           fclose(outfile);
533 +           perf_close();
534 +           return 0;
535 +    }
536 +
537 +    if(STATCOLL == 1) {
538 +           printf("STATISTICS COLLECTOR option chosen\n");
539 +            printf("------------------------------------------------\n\n");
540 +           fp = fopen("initiators.cfg", "r");
541 +           if (fp == NULL) {
542 +                   fprintf(stderr, "couldn't open the specified file initiators.cfg'\n");
543 +                   return -1;
544 +           }
545 +
546 +           int i=0;
547 +            char list[100][50];
548 +           memset(list, sizeof(list), 0);
549 +           while (fgets(line, sizeof line, fp)) {
550 +                   printf("Line is = %s", line);
551 +                   /* Slightly strange way to chop off the \n character */
552 +                   strtok(line, "\n");
553 +                   strcpy(list[i++], line);
554 +           }
555 +           fclose(fp);
556 +
557 +           statcoll_start(TOTAL_TIME, INTERVAL_US, list, xpos, ypos);
558 +    }
559 +
560 +}
561 +
562 diff --git a/clients/soc_performance_monitor.c b/clients/soc_performance_monitor.c
563 new file mode 100644
564 index 0000000..5d1db32
565 --- /dev/null
566 +++ b/clients/soc_performance_monitor.c
567 @@ -0,0 +1,630 @@
568 +/*
569 + * Copyright (C) 2016 Texas Instruments
570 + * Author: Karthik Ramanan <karthik.ramanan@ti.com>
571 + *
572 + * This program is free software; you can redistribute it and/or modify it
573 + * under the terms of the GNU General Public License version 2 as published by
574 + * the Free Software Foundation.
575 + *
576 + * This program is distributed in the hope that it will be useful, but WITHOUT
577 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
578 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
579 + * more details.
580 + *
581 + * You should have received a copy of the GNU General Public License along with
582 + * this program.  If not, see <http://www.gnu.org/licenses/>.
583 + */
584 +
585 +#include <stdint.h>
586 +#include <stdio.h>
587 +#include <stdlib.h>
588 +#include <string.h>
589 +#include <stdint.h>
590 +#include <signal.h>
591 +#include <time.h>
592 +#include <math.h>
593 +#include <unistd.h>
594 +#include <sys/time.h>
595 +#include <pthread.h>
596 +#include <errno.h>
597 +#include <unistd.h>
598 +#include <fcntl.h>
599 +#include <sys/stat.h>
600 +
601 +#include "time_bar_graph.h"
602 +
603 +#include "soc_performance_monitor.h"
604 +
605 +static int debug=0;
606 +
607 +static char readfifo[100]; 
608 +static int MAX_WIDTH=1920;
609 +static int MAX_HEIGHT=1080;
610 +static int x_pos=0;
611 +static int y_pos=40;
612 +
613 +void *ctx;
614 +struct time_graph_create_params tg_p;
615 +struct bar_graph_create_params bg_p;
616 +
617 +static int cpu_load_offset = 0;
618 +static int total_cpu_load_items = 0;
619 +static int total_elements = 0;
620 +
621 +struct _bar_graph_y_config *y_cfg;
622 +struct _text_config *t_cfg;
623 +char *tg_text[100]; 
624 +char *bg_text[100]; 
625 +
626 +
627 +int command_handler(int command, double *y, char **text)
628 +{
629 +       static int fd;
630 +       char buf[MAX_BUF];
631 +       int i, bytes, offset;
632 +
633 +       switch(command)
634 +       {
635 +               case OPEN:
636 +                       fd = open(readfifo, O_RDONLY|O_NONBLOCK);
637 +                       break;
638 +
639 +               case READ:
640 +
641 +                       /* open, read, and display the message from the FIFO */
642 +                       bytes=read(fd, buf, MAX_BUF);
643 +                       buf[bytes]='\0';
644 +                       if(bytes > 0) 
645 +                       {
646 +                               char command[100];
647 +                               char string[100];
648 +                               sscanf(buf, "%s %s", command, string);
649 +                               printd("Received %s\n", buf);
650 +                               if(strcmp(command, "TABLE:") == 0) 
651 +                               {
652 +                                       char field[100], value[100], unit[100];
653 +                                       sscanf(buf, "%s %s %s %s", command, field, value, unit);
654 +                                       for(i=0; i<cpu_load_offset; i++) {
655 +                                               if(strcmp(text[i*2], field) == 0) {
656 +                                                       printd("Updating value(%s), unit(%s)\n", value, unit);
657 +                                                       sprintf(text[i*2+1], "%s %s", value, unit);
658 +                                               }
659 +                                       }
660 +                               }
661 +                               else if(strcmp(command, "CPULOAD:") == 0) 
662 +                               {
663 +                                       char field[100], value[100];
664 +
665 +                                       sscanf(buf, "%s %s %s", command, field, value);
666 +
667 +                                       for(i=cpu_load_offset; i<cpu_load_offset+total_cpu_load_items; i++) {
668 +                                               if(strcmp(text[i*2], field) == 0) {
669 +                                                       if(strlen(value) <= 2) {
670 +                                                               y[i*2+1] = atoi(value)/100.0;
671 +                                                               sprintf(text[i*2+1], " %02s%s", value,"%");
672 +                                                               printd("CPULOAD: Updating %s with %s\n", field, value);
673 +                                                       }
674 +                                                       else {
675 +                                                               printf("Ignoring value: %s\n", value);
676 +                                                       }
677 +                                               }
678 +                                       }
679 +                               }
680 +                               else if(strcmp(command, "MOVE:") == 0) 
681 +                               {
682 +                                       char value[100];
683 +                                       printd("Received MOVE command : %s\n", buf);
684 +                                       sscanf(string, "%s", value);
685 +                                       sprintf(tg_p.title, "CPU Usage[@position-req=%sx%d]", value, y_pos);
686 +                                       move_graph(ctx, &tg_p);
687 +                               }
688 +                               else
689 +                               {
690 +                                       printf("ERROR: Received unexpected data from FIFO - \" %s \" \n", buf);
691 +                               }
692 +                               memset(buf, 0x0, sizeof(buf));
693 +                       }
694 +
695 +                       break;
696 +
697 +               case CLOSE:
698 +                       close(fd);
699 +                       break;
700 +       }
701 +       return bytes;
702 +}
703 +
704 +volatile sig_atomic_t sigtermed = 0;
705 +
706 +void my_signal_handler(int signum)
707 +{
708 +       if (signum == SIGTERM || signum == SIGINT) {
709 +               sigtermed = 1;
710 +       }
711 +}
712 +
713 +int get_strings_in_section(char *string, char **output)
714 +{
715 +       FILE *fd;
716 +       char line[512];
717 +       int total_strings = 0;
718 +       
719 +       fd = fopen("soc_performance_monitor.cfg", "r");
720 +       if(fd == NULL) {
721 +               fprintf(stderr, "ERROR: Unable to open file soc_performance_monitor.cfg\n");
722 +               fprintf(stderr, "       Please copy the file from /etc/visualization_scripts into current directory\n");
723 +               exit(0);
724 +       }
725 +       
726 +       while(fgets(line, sizeof line, fd)) {
727 +           if(strstr(line, string)) {
728 +               printf("\n-------------------------------------------------\n");
729 +               printf("CONFIG FILE PARSE: Found section %s in line : %s\n", string, line);
730 +               break;
731 +           }
732 +       }
733 +
734 +       while(fgets(line, sizeof line, fd)) {
735 +           printd("Line is = %s", line);
736 +
737 +           if (line[0] == '#' || line[0] == '\n' || line[0] == '[') {
738 +                   break;
739 +           }
740 +
741 +           line[strlen(line) - 1] = '\0';
742 +           strcpy(output[total_strings++], line);
743 +           
744 +       }
745 +       fclose(fd);
746 +
747 +       return total_strings;
748 +}
749 +
750 +
751 +void fill_cpu_load_details(int start_offset, int end_offset, char **output, struct table_configuration *table_config)
752 +{
753 +       int i;
754 +
755 +       const int BL_START_X = table_config->BL_START_X;
756 +       const int BL_START_Y = table_config->BL_START_Y;
757 +       const int BAR_GAP = table_config->BAR_GAP;
758 +       const int BAR_HEIGHT = table_config->BAR_HEIGHT;
759 +       const int BAR_WIDTH = table_config->BAR_WIDTH;
760 +       const int TR_START_X = table_config->TR_START_X;
761 +       const int TR_START_Y = table_config->TR_START_Y;
762 +       const int FONT_SIZE = table_config->FONT_SIZE;
763 +       printf("Filling from %d to %d\n", start_offset, end_offset);
764 +       cpu_load_offset = start_offset;
765 +
766 +       for(i=start_offset; i< end_offset-1; i++) {
767 +               y_cfg[i*2].region.bottom_left.x = BL_START_X + (i-start_offset) * (BAR_GAP + BAR_WIDTH);
768 +               y_cfg[i*2].region.bottom_left.y = BL_START_Y;
769 +               y_cfg[i*2].region.top_right.x = TR_START_X + (i-start_offset) * (BAR_GAP + BAR_WIDTH);
770 +               y_cfg[i*2].region.top_right.y = TR_START_Y;
771 +               y_cfg[i*2].line_color.r = 1.0;
772 +               y_cfg[i*2].line_color.g = 1.0;
773 +               y_cfg[i*2].line_color.b = 1.0;
774 +               y_cfg[i*2].line_color.a = 1.0;
775 +               y_cfg[i*2].fill_color.r = 0.0;
776 +               y_cfg[i*2].fill_color.g = 0.0;
777 +               y_cfg[i*2].fill_color.b = 1.0;
778 +               y_cfg[i*2].fill_color.a = 0.7;
779 +
780 +               y_cfg[i*2+1].region.bottom_left.x = BL_START_X +(i-start_offset) * (BAR_GAP + BAR_WIDTH);
781 +               y_cfg[i*2+1].region.bottom_left.y = BL_START_Y;
782 +               y_cfg[i*2+1].region.top_right.x = TR_START_X + (i-start_offset) * (BAR_GAP + BAR_WIDTH);
783 +               y_cfg[i*2+1].region.top_right.y = TR_START_Y;
784 +               y_cfg[i*2+1].line_color.r = 1.0;
785 +               y_cfg[i*2+1].line_color.g = 1.0;
786 +               y_cfg[i*2+1].line_color.b = 1.0;
787 +               y_cfg[i*2+1].line_color.a = 1.0;
788 +               y_cfg[i*2+1].fill_color.r = 1.0;
789 +               y_cfg[i*2+1].fill_color.g = 0.0;
790 +               y_cfg[i*2+1].fill_color.b = 0.0;
791 +               y_cfg[i*2+1].fill_color.a = 1.0;
792 +
793 +       
794 +               t_cfg[i*2].color.r = 1.0;
795 +               t_cfg[i*2].color.g = 1.0;
796 +               t_cfg[i*2].color.b = 1.0;
797 +               t_cfg[i*2].color.a = 1.0;
798 +               t_cfg[i*2].at.x = BL_START_X + (i-start_offset) * (BAR_GAP + BAR_WIDTH);
799 +               t_cfg[i*2].at.y = BL_START_Y + FONT_SIZE;
800 +               t_cfg[i*2].fontsize = FONT_SIZE;
801 +
802 +               t_cfg[i*2+1].color.r = 1.0;
803 +               t_cfg[i*2+1].color.g = 1.0;
804 +               t_cfg[i*2+1].color.b = 1.0;
805 +               t_cfg[i*2+1].color.a = 1.0;
806 +               t_cfg[i*2+1].at.x = BL_START_X + (i-start_offset) * (BAR_GAP + BAR_WIDTH);
807 +               t_cfg[i*2+1].at.y = BL_START_Y - BAR_HEIGHT -  FONT_SIZE;
808 +               t_cfg[i*2+1].fontsize = FONT_SIZE;
809 +
810 +               strcpy(bg_text[i*2], output[i - start_offset]);
811 +               strcpy(bg_text[i*2+1], "0%");
812 +       }
813 +
814 +       t_cfg[(end_offset-1)*2].color.r = 0.0;
815 +       t_cfg[(end_offset-1)*2].color.g = 1.0;
816 +       t_cfg[(end_offset-1)*2].color.b = 1.0;
817 +       t_cfg[(end_offset-1)*2].color.a = 1.0;
818 +       t_cfg[(end_offset-1)*2].at.x = BL_START_X + 80;
819 +       t_cfg[(end_offset-1)*2].at.y = TR_START_Y - 40;
820 +       t_cfg[(end_offset-1)*2].fontsize = FONT_SIZE + 3;
821 +
822 +       printd("Copying title string %s\n", output[end_offset - start_offset -1]);
823 +       strcpy(bg_text[(end_offset-1)*2], output[end_offset - start_offset-1]);
824 +}
825 +
826 +void fill_table_details(int start_offset, int end_offset, char **output, struct table_configuration *table_config)
827 +{
828 +       int i;
829 +
830 +       const int BL_START_X = table_config->BL_START_X;
831 +       const int BL_START_Y = table_config->BL_START_Y;
832 +       const int BAR_GAP = table_config->BAR_GAP;
833 +       const int BAR_HEIGHT = table_config->BAR_HEIGHT;
834 +       const int BAR_WIDTH = table_config->BAR_WIDTH;
835 +       const int TR_START_X = table_config->TR_START_X;
836 +       const int TR_START_Y = table_config->TR_START_Y;
837 +       const int FONT_SIZE = table_config->FONT_SIZE;
838 +       printf("Filling from %d to %d\n", start_offset, end_offset);
839 +
840 +       
841 +        char tokenize[200];
842 +       char tokens[10][100];
843 +       char *pair, *key, *value;
844 +       int k=0;
845 +       char title[100], unit[100];
846 +
847 +       strcpy(tokenize, output[end_offset - start_offset - 1]);
848 +       memset(tokens, 0, sizeof(tokens));
849 +
850 +       k=0;
851 +       pair = strtok (tokenize,",");
852 +       while (pair != NULL) {
853 +               strcpy(tokens[k++], pair);
854 +               pair = strtok (NULL, ",");
855 +       }
856 +
857 +       i=0;
858 +       memset(title, 0, sizeof(title));
859 +       memset(unit, 0, sizeof(unit));
860 +       while(i < k) {
861 +               key=strtok(tokens[i], "=");
862 +               if(key != NULL) {
863 +                       if(strcmp(key,"TITLE") == 0) {
864 +                               value = strtok(NULL, "=");
865 +                               if(value != NULL) {
866 +                                       strcpy(title, value);
867 +                               }
868 +                       }
869 +                       if(strcmp(key,"UNIT") == 0) {
870 +                               value = strtok(NULL, "=");
871 +                               if(value != NULL) {
872 +                                       strcpy(unit, value);
873 +                               }
874 +                       }
875 +               }
876 +               i++;
877 +       }
878 +
879 +       for(i=start_offset; i< end_offset-1; i++) {
880 +               y_cfg[i*2].region.bottom_left.x = BL_START_X;
881 +               y_cfg[i*2].region.bottom_left.y = BL_START_Y + (i - start_offset) * (BAR_GAP + BAR_HEIGHT);
882 +               y_cfg[i*2].region.top_right.x = TR_START_X; 
883 +               y_cfg[i*2].region.top_right.y = TR_START_Y + (i - start_offset) * (BAR_GAP + BAR_HEIGHT);
884 +               y_cfg[i*2].line_color.r = 1.0;
885 +               y_cfg[i*2].line_color.g = 1.0;
886 +               y_cfg[i*2].line_color.b = 1.0;
887 +               y_cfg[i*2].line_color.a = 1.0;
888 +               y_cfg[i*2].fill_color.r = 0.0;
889 +               y_cfg[i*2].fill_color.g = 0.3;
890 +               y_cfg[i*2].fill_color.b = 0.0;
891 +               y_cfg[i*2].fill_color.a = 0.7;
892 +
893 +               y_cfg[i*2+1].region.bottom_left.x = TR_START_X;
894 +               y_cfg[i*2+1].region.bottom_left.y = BL_START_Y + (i - start_offset) * (BAR_GAP + BAR_HEIGHT);
895 +               y_cfg[i*2+1].region.top_right.x = TR_START_X + (BAR_WIDTH); //+ 1 * BL_START_X;
896 +               y_cfg[i*2+1].region.top_right.y = TR_START_Y + (i - start_offset) * (BAR_GAP + BAR_HEIGHT);;
897 +               y_cfg[i*2+1].line_color.r = 1.0;
898 +               y_cfg[i*2+1].line_color.g = 1.0;
899 +               y_cfg[i*2+1].line_color.b = 1.0;
900 +               y_cfg[i*2+1].line_color.a = 1.0;
901 +               y_cfg[i*2+1].fill_color.r = 0.3;
902 +               y_cfg[i*2+1].fill_color.g = 0.0;
903 +               y_cfg[i*2+1].fill_color.b = 0.0;
904 +               y_cfg[i*2+1].fill_color.a = 0.7;
905 +
906 +       
907 +               t_cfg[i*2].color.r = 1.0;
908 +               t_cfg[i*2].color.g = 1.0;
909 +               t_cfg[i*2].color.b = 1.0;
910 +               t_cfg[i*2].color.a = 1.0;
911 +               t_cfg[i*2].at.x = BL_START_X + 5;
912 +               t_cfg[i*2].at.y = BL_START_Y + (i - start_offset) * (BAR_GAP+BAR_HEIGHT) -5;
913 +               t_cfg[i*2].fontsize = FONT_SIZE;
914 +
915 +               t_cfg[i*2+1].color.r = 1.0;
916 +               t_cfg[i*2+1].color.g = 1.0;
917 +               t_cfg[i*2+1].color.b = 1.0;
918 +               t_cfg[i*2+1].color.a = 1.0;
919 +               t_cfg[i*2+1].at.x = TR_START_X + 50;//BAR_WIDTH + TR_START_X;
920 +               t_cfg[i*2+1].at.y = BL_START_Y + (i - start_offset) * (BAR_GAP + BAR_HEIGHT) -5;
921 +               t_cfg[i*2+1].fontsize = FONT_SIZE;
922 +
923 +               printd("Copying string %s at %d\n", output[i-start_offset], i);
924 +               strcpy(bg_text[i*2], output[i-start_offset]);
925 +               printd("Setting text 0  %s at %d\n", unit, i*2+1);
926 +               sprintf(bg_text[i*2+1], "0 %s", unit);
927 +       }
928 +       for(i=start_offset; i< end_offset*2; i++) {
929 +               printd("%d - (%d, %d) to (%d, %d)\n", i, y_cfg[i].region.bottom_left.x,  y_cfg[i].region.bottom_left.y,  y_cfg[i].region.top_right.x,  y_cfg[i].region.top_right.y);
930 +       }
931 +
932 +       t_cfg[(end_offset-1)*2].color.r = 0.0;
933 +       t_cfg[(end_offset-1)*2].color.g = 1.0;
934 +       t_cfg[(end_offset-1)*2].color.b = 1.0;
935 +       t_cfg[(end_offset-1)*2].color.a = 1.0;
936 +       t_cfg[(end_offset-1)*2].at.x = BL_START_X + 80;
937 +       t_cfg[(end_offset-1)*2].at.y = BL_START_Y - 40;
938 +       t_cfg[(end_offset-1)*2].fontsize = FONT_SIZE + 3;
939 +
940 +       printd("Copying title string %s\n", title);
941 +       strcpy(bg_text[(end_offset-1)*2], title);
942 +
943 +}
944 +       
945 +
946 +int get_key_value_from_string(char *string, char *limiter, char *key, char *value)
947 +{
948 +       char *mykey, *myvalue;
949 +
950 +       mykey=strtok(string, limiter);
951 +       if(mykey != NULL) {
952 +               myvalue = strtok(NULL, "=");
953 +               strtok(myvalue, "\n");
954 +               if(myvalue == NULL) {
955 +                       return -1;
956 +               }
957 +       }
958 +       else {
959 +               return -1;
960 +       }
961 +       printd("Key is %s\n", mykey);
962 +       printd("Value is %s\n", myvalue);
963 +       strcpy(key, mykey);
964 +       strcpy(value, myvalue);
965 +       return 0;
966 +
967 +}
968 +
969 +void populate_table_configuration(struct table_configuration *tbl_cfg, int cur_items, char **item_list)
970 +{
971 +       static int total_items = 0;
972 +       static int total_tables = 0;
973 +       
974 +       tbl_cfg->BAR_HEIGHT = 25;
975 +       tbl_cfg->BAR_WIDTH = 150;
976 +       tbl_cfg->BL_START_X = 40;
977 +       tbl_cfg->BL_START_Y = 80 + (total_items + total_tables) * tbl_cfg->BAR_HEIGHT;
978 +       tbl_cfg->BAR_GAP = 0;
979 +       tbl_cfg->TR_START_X = tbl_cfg->BL_START_X + tbl_cfg->BAR_WIDTH;
980 +       tbl_cfg->TR_START_Y = tbl_cfg->BL_START_Y - tbl_cfg->BAR_HEIGHT;
981 +       tbl_cfg->FONT_SIZE = 15;
982 +
983 +       printf("Proceeding with filling out details...\n");
984 +       if(cur_items > 0)
985 +               fill_table_details(total_items, total_items+cur_items, item_list, tbl_cfg);
986 +
987 +       total_items += cur_items;
988 +       if(cur_items > 0)
989 +               total_tables++;
990 +
991 +       printf("total_items = %d, total_tables = %d\n", total_items, total_tables);
992 +       return;
993 +}
994 +
995 +int fill_list_from_section(char **section_list, char *section_name)
996 +{
997 +       int total_items, j;
998 +
999 +       for(j=0; j<20; j++) {
1000 +               section_list[j] = malloc(100);
1001 +       }
1002 +
1003 +       total_items = get_strings_in_section(section_name, section_list);
1004 +       printf("\tThe total values in the section %s are %d\n", section_name, total_items);
1005 +       for(j=0; j<total_items; j++) {
1006 +               printf("\t\tThe returned strings for BOOT_TIME are %s\n", section_list[j]);
1007 +       }
1008 +
1009 +       total_elements += total_items;
1010 +
1011 +       return total_items;
1012 +}
1013 +
1014 +int main(int argc, char *argv[])
1015 +{
1016 +       double *bg_y;
1017 +       double *tg_y;
1018 +       int i,j;
1019 +       int refresh_rate;
1020 +
1021 +       if (SIG_ERR == signal(SIGPIPE,SIG_IGN))
1022 +               exit(1);
1023 +
1024 +       if (SIG_ERR == signal(SIGINT,my_signal_handler))
1025 +               exit(1);
1026 +
1027 +       if (SIG_ERR == signal(SIGTERM,my_signal_handler))
1028 +               exit(1);
1029 +
1030 +       if(argc == 2) {
1031 +               printf("Enabling debug\n");
1032 +               debug = atoi(argv[1]);
1033 +       }
1034 +       else {
1035 +               printf("Debug is disabled\n");
1036 +               debug = 0;
1037 +       }
1038 +
1039 +       char *output[20];
1040 +       int total = fill_list_from_section(output, "GLOBAL");
1041 +       for(j=0; j<total; j++) {
1042 +               char key[100], value[100];
1043 +               int ret = get_key_value_from_string(output[j], "=", key, value);
1044 +               if(ret == 0) {
1045 +                       if(strcmp(key, "FIFO") == 0) {
1046 +                               strcpy(readfifo, value);
1047 +                       }
1048 +                       if(strcmp(key, "REFRESH_RATE_USEC") == 0) {
1049 +                               refresh_rate = atoi(value);
1050 +                       }
1051 +                       if(strcmp(key, "MAX_WIDTH") == 0) {
1052 +                               MAX_WIDTH = atoi(value);
1053 +                       }
1054 +                       if(strcmp(key, "MAX_HEIGHT") == 0) {
1055 +                               MAX_HEIGHT = atoi(value);
1056 +                       }
1057 +                       if(strcmp(key, "X_POS") == 0) {
1058 +                               x_pos = atoi(value);
1059 +                       }
1060 +                       if(strcmp(key, "Y_POS") == 0) {
1061 +                               y_pos = atoi(value);
1062 +                       }
1063 +               }
1064 +                               
1065 +       }
1066 +
1067 +       printf("\n-------------------------------------------------\n");
1068 +       printf("Configured REFRESH_RATE is %d\n", refresh_rate);
1069 +       printf("Configured FIFO is %s\n", readfifo);
1070 +       printf("Configured MAX_WIDTH is %d\n", MAX_WIDTH);
1071 +       printf("Configured MAX_HEIGHT is %d\n", MAX_HEIGHT);
1072 +       printf("Configured starting location is (%d, %d)\n", x_pos, y_pos);
1073 +       printf("\n-------------------------------------------------\n");
1074 +
1075 +       int fd = open(readfifo, O_RDONLY|O_NONBLOCK);
1076 +       if (fd != -1) {
1077 +               printf("SUCCESS: Configured FIFO exists\n");
1078 +               close(fd);
1079 +       }
1080 +       else {
1081 +               printf("ERROR: %s not found\nPlease create the fifo by executing mkfifo %s before running the application\n", readfifo, readfifo);
1082 +               exit(0);
1083 +       }
1084 +               
1085 +
1086 +       bg_p.title = malloc(100);
1087 +       sprintf(bg_p.title, "CPU Usage[@position-req=%dx%d]", x_pos, y_pos);
1088 +
1089 +       /* ------------------------------------------------------------------------*/
1090 +       /* Section for populating all lists from cfg sections*/
1091 +       /* ------------------------------------------------------------------------*/
1092 +       char *boot_list[20];
1093 +       int total_boot_items = fill_list_from_section(boot_list, "BOOT_TIME");
1094 +
1095 +       char *temperature_list[20];
1096 +       int total_temperature_items = fill_list_from_section(temperature_list, "TEMPERATURE");
1097 +
1098 +       char *cpu_load_list[20];
1099 +       total_cpu_load_items = fill_list_from_section(cpu_load_list, "CPU_LOAD");
1100 +
1101 +       char *voltage_list[20];
1102 +       int total_voltage_items = fill_list_from_section(voltage_list, "VOLTAGE");
1103 +
1104 +       char *frequency_list[20];
1105 +       int total_frequency_items = fill_list_from_section(frequency_list, "FREQUENCY");
1106 +       /* ------------------------------------------------------------------------*/
1107 +       /* total_elements will be updated inside the fill_list_from_section function */
1108 +
1109 +       t_cfg = malloc(sizeof(struct _text_config) * (total_elements*2 + 1));
1110 +       y_cfg = malloc(sizeof(struct _bar_graph_y_config) * total_elements*2);
1111 +       bg_p.num_of_y_items = total_elements*2;
1112 +       bg_p.y_config_array = y_cfg;
1113 +       bg_p.num_of_text_items = total_elements*2 + 1;
1114 +       bg_p.text_config_array = t_cfg;
1115 +
1116 +       bg_y = malloc(sizeof(double) * total_elements * 2);
1117 +       for(i=0; i< (total_elements*2+1); i++) {
1118 +               bg_text[i] = malloc(150);
1119 +               bg_y[i] = 1.0;
1120 +       }
1121 +
1122 +       tg_y = malloc(sizeof(double) * total_elements * 2);
1123 +       for(i=0; i< (total_elements*2+1); i++) {
1124 +               tg_text[i] = malloc(150);
1125 +               tg_y[i] = 0.1 * i;
1126 +       }
1127 +
1128 +       struct table_configuration boot_table_config; 
1129 +        populate_table_configuration(&boot_table_config, total_boot_items, boot_list);
1130 +
1131 +       struct table_configuration temp_table_config; 
1132 +        populate_table_configuration(&temp_table_config, total_temperature_items, temperature_list);
1133 +
1134 +       struct table_configuration voltage_table_config; 
1135 +        populate_table_configuration(&voltage_table_config, total_voltage_items, voltage_list);
1136 +
1137 +       struct table_configuration frequency_table_config; 
1138 +        populate_table_configuration(&frequency_table_config, total_frequency_items, frequency_list);
1139 +
1140 +       struct table_configuration cpu_load_config; 
1141 +       cpu_load_config.BL_START_X = 40;
1142 +       cpu_load_config.BL_START_Y = 80 + (total_boot_items + total_temperature_items + total_voltage_items + total_frequency_items+ 4) * boot_table_config.BAR_HEIGHT + 80 /*cpu_load_config.BAR_HEIGHT */;
1143 +       cpu_load_config.BAR_GAP = 20;
1144 +       cpu_load_config.BAR_HEIGHT = 80;
1145 +       cpu_load_config.BAR_WIDTH = 40;
1146 +       cpu_load_config.TR_START_X = cpu_load_config.BL_START_X + cpu_load_config.BAR_WIDTH;
1147 +       cpu_load_config.TR_START_Y = cpu_load_config.BL_START_Y - cpu_load_config.BAR_HEIGHT;
1148 +       cpu_load_config.FONT_SIZE = 15;
1149 +       if(total_cpu_load_items > 0) {
1150 +               fill_cpu_load_details(total_boot_items+total_temperature_items+total_voltage_items+total_frequency_items, total_boot_items+total_temperature_items+total_voltage_items+total_frequency_items+total_cpu_load_items, cpu_load_list, &cpu_load_config);
1151 +       }
1152 +       else {
1153 +               cpu_load_offset = total_boot_items + total_temperature_items + total_voltage_items + total_frequency_items;
1154 +       }
1155 +
1156 +       tg_p.title=(char *)malloc(100);
1157 +       sprintf(tg_p.title, "CPU Usage[@position-req=%dx%d]", x_pos, y_pos);
1158 +       tg_p.height = MAX_HEIGHT;
1159 +       tg_p.width = MAX_WIDTH;
1160 +
1161 +       struct _y_config *tg_y_cfg = malloc(tg_p.num_of_y_items * sizeof(struct _y_config));
1162 +       tg_p.y_config_array = tg_y_cfg;
1163 +       tg_p.text_config_array = t_cfg;
1164 +
1165 +        printf("Proceeding to create starting visualization...\n");
1166 +       ctx = time_graph_create(argc, argv, &tg_p);
1167 +       if (!ctx) {
1168 +               printf("Unable to create time_graph... \n");
1169 +               exit(0);
1170 +       }
1171 +
1172 +       ctx = bar_graph_create(argc, argv, &bg_p);
1173 +       if (!ctx) {
1174 +               printf("Error creating context\n");
1175 +               exit(0);
1176 +       }
1177 +
1178 +       command_handler(OPEN, NULL, NULL);
1179 +
1180 +       /* Plot the graph first time */
1181 +       time_graph_plot(ctx, tg_y, (const char **)tg_text);
1182 +       bar_graph_plot(ctx, bg_y, (const char **)bg_text);
1183 +
1184 +       while (!sigtermed)
1185 +       {
1186 +               usleep(refresh_rate);
1187 +               int bytes_read = command_handler(READ, bg_y, bg_text);
1188 +               if(bytes_read > 0) {
1189 +                       time_graph_plot(ctx, tg_y, (const char **)tg_text);
1190 +                       bar_graph_plot(ctx, bg_y, (const char **)bg_text);
1191 +               }
1192 +       }
1193 +
1194 +       bar_graph_destroy(ctx);
1195 +       command_handler(CLOSE, NULL, NULL);
1196 +       return 0;
1197 +}
1198 diff --git a/clients/soc_performance_monitor.h b/clients/soc_performance_monitor.h
1199 new file mode 100644
1200 index 0000000..861c8c7
1201 --- /dev/null
1202 +++ b/clients/soc_performance_monitor.h
1203 @@ -0,0 +1,40 @@
1204 +#define __SLEEP  usleep(1000000)
1205 +
1206 +#define MAX_BUF 1024
1207 +#define OPEN 1
1208 +#define READ 2
1209 +#define CLOSE 3
1210 +
1211 +#define MAX_COLORS 12
1212 +
1213 +#define printd(fmt, ...) \
1214 +       do { if (debug) fprintf(stderr, fmt, __VA_ARGS__); } while (0)
1215 +
1216 +
1217 +struct _rgba pallette[MAX_COLORS] = 
1218 +{
1219 +       { 1.0, 0.0, 0.0, 1.0 },
1220 +       { 0.0, 0.5, 0.0, 1.0 },
1221 +       { 0.0, 0.0, 1.0, 1.0 },
1222 +       { 0.0, 0.0, 0.0, 1.0 },
1223 +       { 0.0, 0.5, 1.0, 1.0 },
1224 +       { 1.0, 0.0, 1.0, 1.0 },
1225 +       { 0.5, 0.5, 1.0, 1.0 },
1226 +       { 1.0, 0.5, 0.0, 1.0 },
1227 +       { 0.5, 0.5, 0.25, 1.0 },
1228 +       { 0.5, 0.0, 0.0, 1.0 },
1229 +       { 1.0, 0.5, 0.5, 1.0 },
1230 +       { 0.0, 0.0, 0.20, 1.0 }
1231 +};
1232 +
1233 +struct table_configuration {
1234 +       int BL_START_X;
1235 +       int BL_START_Y;
1236 +       int BAR_GAP;
1237 +       int BAR_HEIGHT;
1238 +       int BAR_WIDTH;
1239 +       int TR_START_X;
1240 +       int TR_START_Y;
1241 +       int FONT_SIZE;
1242 +};
1243 +
1244 diff --git a/clients/statcoll.c b/clients/statcoll.c
1245 new file mode 100644
1246 index 0000000..5d5cae7
1247 --- /dev/null
1248 +++ b/clients/statcoll.c
1249 @@ -0,0 +1,1433 @@
1250 +/*
1251 + * Copyright (C) 2015 Texas Instruments
1252 + * created by prash@ti.com on 16 Jan 2013
1253 + * Adapted to Linux with changes in framework: Karthik R <karthik.ramanan@ti.com>
1254 + *
1255 + * This program is free software; you can redistribute it and/or modify it
1256 + * under the terms of the GNU General Public License version 2 as published by
1257 + * the Free Software Foundation.
1258 + *
1259 + * This program is distributed in the hope that it will be useful, but WITHOUT
1260 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1261 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
1262 + * more details.
1263 + *
1264 + * You should have received a copy of the GNU General Public License along with
1265 + * this program.  If not, see <http://www.gnu.org/licenses/>.
1266 + */
1267 +
1268 +#include <stdio.h>
1269 +#include <stdlib.h>
1270 +#include <string.h>
1271 +#include <sys/mman.h>
1272 +#include <fcntl.h>
1273 +#include <signal.h>
1274 +#include <unistd.h>
1275 +#include <sys/time.h>
1276 +
1277 +#include "statcoll.h"
1278 +#include "statcoll_gui.h"
1279 +#include "time_bar_graph.h"
1280 +
1281 +#define ENABLE_MODE      0x0
1282 +#define READ_STATUS_MODE 0x1
1283 +
1284 +
1285 +
1286 +#define OPEN 1
1287 +#define READ 2
1288 +#define CLOSE 3
1289 +
1290 +
1291 +#if 1
1292 +#define __SLEEP  sleep(1)
1293 +#else
1294 +#define __SLEEP  usleep(100000)
1295 +#endif
1296 +//#define DUMMY_MODE
1297 +
1298 +#define MAX_COLORS 12
1299 +
1300 +struct _rgba pallette[MAX_COLORS] = 
1301 +{
1302 +       { 1.0, 0.0, 0.0, 1.0 },
1303 +       { 0.0, 0.5, 0.0, 1.0 },
1304 +       { 0.0, 0.0, 1.0, 1.0 },
1305 +       { 0.0, 0.0, 0.0, 1.0 },
1306 +       { 0.0, 0.5, 1.0, 1.0 },
1307 +       { 1.0, 0.0, 1.0, 1.0 },
1308 +       { 0.5, 0.5, 1.0, 1.0 },
1309 +       { 1.0, 0.5, 0.0, 1.0 },
1310 +       { 0.5, 0.5, 0.25, 1.0 },
1311 +       { 0.5, 0.0, 0.0, 1.0 },
1312 +       { 1.0, 0.5, 0.5, 1.0 },
1313 +       { 0.0, 0.0, 0.20, 1.0 }
1314 +};
1315 +
1316 +const struct list_of_initiators initiators[STATCOL_MAX] =
1317 +{
1318 +    { STATCOL_EMIF1_SYS, "STATCOL_EMIF1_SYS" },
1319 +    { STATCOL_EMIF2_SYS,"STATCOL_EMIF2_SYS" },
1320 +    { STATCOL_MA_MPU_P1,"STATCOL_MPU_P1" },
1321 +    { STATCOL_MA_MPU_P2,"STATCOL_MPU_P2" },
1322 +    { STATCOL_MPU1,"STATCOL_MPU1" },
1323 +    { STATCOL_MMU1,"STATCOL_MMU1" },
1324 +    { STATCOL_TPTC_RD1,"STATCOL_TPTC_RD1" },
1325 +    { STATCOL_TPTC_WR1,"STATCOL_TPTC_WR1" },
1326 +    { STATCOL_TPTC_RD2,"STATCOL_TPTC_RD2" },
1327 +    { STATCOL_TPTC_WR2,"STATCOL_TPTC_WR2" },
1328 +    { STATCOL_VIP1_P1,"STATCOL_VIP1_P1" },
1329 +    { STATCOL_VIP1_P2,"STATCOL_VIP1_P2" },
1330 +    { STATCOL_VIP2_P1,"STATCOL_VIP2_P1" },
1331 +    { STATCOL_VIP2_P2,"STATCOL_VIP2_P2" },
1332 +    { STATCOL_VIP3_P1,"STATCOL_VIP3_P1" },
1333 +    { STATCOL_VIP3_P2,"STATCOL_VIP3_P2" },
1334 +    { STATCOL_VPE_P1,"STATCOL_VPE_P1" },
1335 +    { STATCOL_VPE_P2,"STATCOL_VPE_P2" },
1336 +    { STATCOL_EVE1_TC0,"STATCOL_EVE1_TC0" },
1337 +    { STATCOL_EVE1_TC1,"STATCOL_EVE1_TC1" },
1338 +    { STATCOL_EVE2_TC0,"STATCOL_EVE2_TC0" },
1339 +    { STATCOL_EVE2_TC1,"STATCOL_EVE2_TC1" },
1340 +    { STATCOL_EVE3_TC0,"STATCOL_EVE3_TC0" },
1341 +    { STATCOL_EVE3_TC1,"STATCOL_EVE3_TC1" },
1342 +    { STATCOL_EVE4_TC0,"STATCOL_EVE4_TC0" },
1343 +    { STATCOL_EVE4_TC1,"STATCOL_EVE4_TC1" },
1344 +    { STATCOL_DSP1_MDMA,"STATCOL_DSP1_MDMA" },
1345 +    { STATCOL_DSP1_EDMA,"STATCOL_DSP1_EDMA" },
1346 +    { STATCOL_DSP2_MDMA,"STATCOL_DSP2_MDMA" },
1347 +    { STATCOL_DSP2_EDMA,"STATCOL_DSP2_EDMA" },
1348 +    { STATCOL_IVA,"STATCOL_IVA" },
1349 +    { STATCOL_GPU_P1,"STATCOL_GPU_P1" },
1350 +    { STATCOL_GPU_P2,"STATCOL_GPU_P2" },
1351 +    { STATCOL_BB2D_P1,"STATCOL_BB2D_P1" },
1352 +    { STATCOL_DSS,"STATCOL_DSS" },
1353 +    { STATCOL_CSI2_2,"STATCOL_CSI2_2" },
1354 +    { STATCOL_MMU2,"STATCOL_MMU2" },
1355 +    { STATCOL_IPU1,"STATCOL_IPU1" },
1356 +    { STATCOL_IPU2,"STATCOL_IPU2" },
1357 +    { STATCOL_DMA_SYSTEM_RD,"STATCOL_DMA_SYSTEM_RD" },
1358 +    { STATCOL_DMA_SYSTEM_WR,"STATCOL_DMA_SYSTEM_WR" },
1359 +    { STATCOL_CSI2_1,"STATCOL_CSI2_1" },
1360 +    { STATCOL_USB3_SS,"STATCOL_USB3_SS" },
1361 +    { STATCOL_USB2_SS,"STATCOL_USB2_SS" },
1362 +    { STATCOL_USB2_ULPI_SS1,"STATCOL_USB2_ULPI_SS1" },
1363 +    { STATCOL_USB2_ULPI_SS2,"STATCOL_USB2_ULPI_SS2" },
1364 +    { STATCOL_PCIE_SS1,"STATCOL_PCIE_SS1" },
1365 +    { STATCOL_PCIE_SS2,"STATCOL_PCIE_SS2" },
1366 +    { STATCOL_DSP1_CFG,"STATCOL_DSP1_CFG" },
1367 +    { STATCOL_DSP2_CFG,"STATCOL_DSP2_CFG" },
1368 +    { STATCOL_GMAC_SW,"STATCOL_GMAC_SW" },
1369 +    { STATCOL_PRUSS1_P1,"STATCOL_PRUSS1_P1" },
1370 +    { STATCOL_PRUSS1_P2,"STATCOL_PRUSS1_P2" },
1371 +    { STATCOL_PRUSS2_P1,"STATCOL_PRUSS2_P1" },
1372 +    { STATCOL_PRUSS2_P2,"STATCOL_PRUSS2_P2" },
1373 +    { STATCOL_DMA_CRYPTO_RD,"STATCOL_DMA_CRYPTO_RD" },
1374 +    { STATCOL_DMA_CRYPTO_WR,"STATCOL_DMA_CRYPTO_WR" },
1375 +    { STATCOL_MPU2,"STATCOL_MPU2" },
1376 +    { STATCOL_MMC1,"STATCOL_MMC1" },
1377 +    { STATCOL_MMC2,"STATCOL_MMC2" },
1378 +    { STATCOL_SATA,"STATCOL_SATA" },
1379 +    { STATCOL_MLBSS,"STATCOL_MLBSS" },
1380 +    { STATCOL_BB2D_P2,"STATCOL_BB2D_P2" },
1381 +    { STATCOL_IEEE1500,"STATCOL_IEEE1500" },
1382 +    { STATCOL_DBG,"STATCOL_DBG" },
1383 +    { STATCOL_VCP1,"STATCOL_VCP1" },
1384 +    { STATCOL_OCMC_RAM1,"STATCOL_OCMC_RAM1" },
1385 +    { STATCOL_OCMC_RAM2,"STATCOL_OCMC_RAM2" },
1386 +    { STATCOL_OCMC_RAM3,"STATCOL_OCMC_RAM3" },
1387 +    { STATCOL_GPMC,"STATCOL_GPMC" },
1388 +    { STATCOL_MCASP1,"STATCOL_MCASP1" },
1389 +    { STATCOL_MCASP2,"STATCOL_MCASP2" },
1390 +    { STATCOL_MCASP3,"STATCOL_MCASP3" },
1391 +    { STATCOL_VCP2,  "STATCOL_VCP2" }
1392 +}; 
1393 +
1394 +StatCollectorObj gStatColState;
1395 +
1396 +static void *statcoll_base_mem;
1397 +static int *l3_3_clkctrl;
1398 +
1399 +static UInt32 *statCountDSS = NULL;
1400 +static UInt32 *statCountIVA = NULL;
1401 +static UInt32 *statCountBB2DP1 = NULL;
1402 +static UInt32 *statCountBB2DP2 = NULL;
1403 +static UInt32 *statCountUSB4 = NULL;
1404 +static UInt32 *statCountSata = NULL;
1405 +static UInt32 *statCountEmif1 = NULL;
1406 +static UInt32 *statCountEmif2 = NULL;
1407 +
1408 +
1409 +static statcoll_initiators_object global_object[STATCOL_MAX];
1410 +UInt32 statCountIdx = 0;
1411 +UInt32 TRACE_SZ = 0;
1412 +
1413 +void create_overall_box(struct _bar_graph_y_config *y_cfg, struct _text_config *t_cfg, char *text[])
1414 +{
1415 +        int i=0;
1416 +
1417 +        memset(y_cfg, 0x0, sizeof(struct _y_config)*25);
1418 +        memset(t_cfg, 0x0, sizeof(struct _text_config)*25);
1419 +
1420 +
1421 +        for(i=0; i<TOTAL_Y_PARAMETERS; i++) {
1422 +                (y_cfg+i)->line_color.r = 1.0;
1423 +                (y_cfg+i)->line_color.g = 1.0;
1424 +                (y_cfg+i)->line_color.b = 1.0;
1425 +                (y_cfg+i)->line_color.a = 0.7;
1426 +                (y_cfg+i)->fill_color.r = 0.0;
1427 +                (y_cfg+i)->fill_color.g = 0.0;
1428 +                (y_cfg+i)->fill_color.b = 0.0;
1429 +                (y_cfg+i)->fill_color.a = 0.1;
1430 +        }
1431 +
1432 +        (y_cfg+0)->region.bottom_left.x = 0;
1433 +        (y_cfg+0)->region.bottom_left.y = MAX_HEIGHT - HEIGHT_EMIF_AREA;
1434 +        (y_cfg+0)->region.top_right.x = MAX_WIDTH;
1435 +        (y_cfg+0)->region.top_right.y = 0;
1436 +
1437 +        (t_cfg+0)->at.x = MAX_WIDTH/2 - 8*FONT_SIZE - 50;
1438 +        (t_cfg+0)->at.y = BORDER - FONT_SIZE + 6;
1439 +        strcpy(text[0], string_list[0]);
1440 +
1441 +        (y_cfg+1)->region.bottom_left.x = TIME_GRAPH_AREA_BL_X;
1442 +        (y_cfg+1)->region.bottom_left.y = TIME_GRAPH_AREA_BL_Y;
1443 +        (y_cfg+1)->region.top_right.x = TIME_GRAPH_AREA_TR_X;
1444 +        (y_cfg+1)->region.top_right.y = TIME_GRAPH_AREA_TR_Y;
1445 +
1446 +        (t_cfg+1)->at.x = TIME_GRAPH_AREA_BL_X - 2*FONT_SIZE;
1447 +        (t_cfg+1)->at.y = TIME_GRAPH_AREA_TR_Y;
1448 +        strcpy(text[1],string_list[1]);
1449 +
1450 +        for(i=2; i<7; i++)
1451 +        {
1452 +                (y_cfg+i)->region.bottom_left.x = TIME_GRAPH_AREA_BL_X;
1453 +                (y_cfg+i)->region.bottom_left.y = TIME_GRAPH_AREA_BL_Y;// - (i-2) * (30);
1454 +                (y_cfg+i)->region.top_right.x = TIME_GRAPH_AREA_TR_X;
1455 +                (y_cfg+i)->region.top_right.y = TIME_GRAPH_AREA_TR_Y + (i-1) * ((TIME_GRAPH_AREA_BL_Y - TIME_GRAPH_AREA_TR_Y)/5);
1456 +                (t_cfg+i)->at.x = TIME_GRAPH_AREA_BL_X - 2*FONT_SIZE;
1457 +                (t_cfg+i)->at.y = TIME_GRAPH_AREA_TR_Y + (i-1) * ((TIME_GRAPH_AREA_BL_Y - TIME_GRAPH_AREA_TR_Y)/5);//TIME_GRAPH_AREA_TR_Y;
1458 +                strcpy(text[i],string_list[i]);
1459 +        }
1460 +
1461 +#if 1
1462 +        (y_cfg+7)->region.bottom_left.x = EMIF_AREA_BL_X;
1463 +        (y_cfg+7)->region.bottom_left.y = EMIF_AREA_BL_Y;
1464 +        (y_cfg+7)->region.top_right.x = EMIF_AREA_TR_X;
1465 +        (y_cfg+7)->region.top_right.y = EMIF_AREA_TR_Y;
1466 +
1467 +        (t_cfg+7)->at.x = WIDTH_EMIF_AREA/2 - 2*FONT_SIZE;
1468 +        (t_cfg+7)->at.y = EMIF_AREA_TR_Y + FONT_SIZE;
1469 +        strcpy(text[7],string_list[7]);
1470 +
1471 +        for(i=8; i<12; i=i+2)
1472 +        {
1473 +                (y_cfg+i)->region.bottom_left.x = EMIF_AREA_BL_X + BORDER + (i-8)*(BAR_WIDTH+BAR_GAP)/2;
1474 +                (y_cfg+i)->region.bottom_left.y = EMIF_AREA_BL_Y - BORDER/2;// - (i-2) * (30);
1475 +                (y_cfg+i)->region.top_right.x = EMIF_AREA_BL_X + BORDER + BAR_WIDTH + (i-8) * (BAR_WIDTH + BAR_GAP)/2;
1476 +                (y_cfg+i)->region.top_right.y = EMIF_AREA_TR_Y + BORDER * 1.2;
1477 +
1478 +                (y_cfg+i)->fill_color.r = 1.0;
1479 +                (y_cfg+i)->fill_color.g = 0.0;
1480 +                (y_cfg+i)->fill_color.b = 0.0;
1481 +                (y_cfg+i)->fill_color.a = 0.1;
1482 +
1483 +                (y_cfg+i+1)->region.bottom_left.x = EMIF_AREA_BL_X + BORDER + (i-8) * (BAR_WIDTH + BAR_GAP)/2;
1484 +                (y_cfg+i+1)->region.bottom_left.y = EMIF_AREA_BL_Y - BORDER/2;
1485 +                (y_cfg+i+1)->region.top_right.x = EMIF_AREA_BL_X + BORDER + BAR_WIDTH + (i-8) * (BAR_WIDTH + BAR_GAP)/2;
1486 +                (y_cfg+i+1)->region.top_right.y = EMIF_AREA_TR_Y + BORDER*1.2;
1487 +
1488 +                (y_cfg+i+1)->fill_color.r = 0.0;
1489 +                (y_cfg+i+1)->fill_color.g = 1.0;
1490 +                (y_cfg+i+1)->fill_color.b = 0.0;
1491 +                (y_cfg+i+1)->fill_color.a = 1.0;
1492 +
1493 +                (t_cfg+i)->at.x = EMIF_AREA_BL_X + BAR_WIDTH + BORDER + (i-8) * (BAR_WIDTH + BAR_GAP)/2- 2.2*FONT_SIZE;
1494 +                (t_cfg+i)->at.y = EMIF_AREA_TR_Y + BORDER*1.2 -5;
1495 +
1496 +                /* Fixed strings */
1497 +                (t_cfg+i+1)->at.x = EMIF_AREA_BL_X + BORDER + (i-8) * (BAR_WIDTH + BAR_GAP)/2;
1498 +                (t_cfg+i+1)->at.y = EMIF_AREA_BL_Y;// - BORDER + FONT_SIZE;
1499 +
1500 +                strcpy(text[i],string_list[i]);
1501 +                strcpy(text[i+1],string_list[i+1]);
1502 +        }
1503 +
1504 +        (y_cfg+12)->region.bottom_left.x = INITIATORS_AREA_BL_X;
1505 +        (y_cfg+12)->region.bottom_left.y = INITIATORS_AREA_BL_Y;
1506 +        (y_cfg+12)->region.top_right.x = INITIATORS_AREA_TR_X;
1507 +        (y_cfg+12)->region.top_right.y = INITIATORS_AREA_TR_Y;
1508 +
1509 +        (t_cfg+12)->at.x = EMIF_AREA_TR_X + (INITIATORS_AREA_TR_X - INITIATORS_AREA_BL_X)/2 - 4 * FONT_SIZE;
1510 +        (t_cfg+12)->at.y = INITIATORS_AREA_TR_Y + FONT_SIZE;
1511 +        strcpy(text[12],string_list[12]);
1512 +
1513 +        for(i=13; i<25; i=i+2)
1514 +        {
1515 +                (y_cfg+i)->region.bottom_left.x = INITIATORS_AREA_BL_X + BORDER + (i-13)*(BAR_WIDTH+BAR_GAP)/2;
1516 +                (y_cfg+i)->region.bottom_left.y = INITIATORS_AREA_BL_Y - BORDER/2;// - (i-2) * (30);
1517 +                (y_cfg+i)->region.top_right.x = INITIATORS_AREA_BL_X + BORDER + BAR_WIDTH + (i-13) * (BAR_WIDTH + BAR_GAP)/2;
1518 +                (y_cfg+i)->region.top_right.y = INITIATORS_AREA_TR_Y + BORDER*1.2;
1519 +
1520 +                (y_cfg+i)->fill_color.r = 1.0;
1521 +                (y_cfg+i)->fill_color.g = 0.0;
1522 +                (y_cfg+i)->fill_color.b = 0.0;
1523 +                (y_cfg+i)->fill_color.a = 0.1;
1524 +
1525 +                (y_cfg+i+1)->region.bottom_left.x = INITIATORS_AREA_BL_X + BORDER + (i-13) * (BAR_WIDTH + BAR_GAP)/2;
1526 +                (y_cfg+i+1)->region.bottom_left.y = INITIATORS_AREA_BL_Y - BORDER/2;// - (i-2) * (30);
1527 +                (y_cfg+i+1)->region.top_right.x = INITIATORS_AREA_BL_X + BORDER + BAR_WIDTH + (i-13) * (BAR_WIDTH + BAR_GAP)/2;
1528 +                (y_cfg+i+1)->region.top_right.y = INITIATORS_AREA_TR_Y + BORDER* 1.2;
1529 +
1530 +                (y_cfg+i+1)->fill_color.r = 0.0;
1531 +                (y_cfg+i+1)->fill_color.g = 1.0;
1532 +                (y_cfg+i+1)->fill_color.b = 0.0;
1533 +                (y_cfg+i+1)->fill_color.a = 1.0;
1534 +
1535 +                (t_cfg+i)->at.x = INITIATORS_AREA_BL_X + BORDER + BAR_WIDTH + (i-13) * (BAR_WIDTH + BAR_GAP)/2 - 2.2* FONT_SIZE;
1536 +                (t_cfg+i)->at.y = INITIATORS_AREA_TR_Y + BORDER*1.2 -5;
1537 +
1538 +                (t_cfg+i+1)->at.x = INITIATORS_AREA_BL_X + BORDER + (i-13)*(BAR_WIDTH+BAR_GAP)/2;
1539 +                (t_cfg+i+1)->at.y = INITIATORS_AREA_BL_Y;
1540 +
1541 +                strcpy(text[i],string_list[i]);
1542 +                strcpy(text[i+1],string_list[i+1]);
1543 +        }
1544 +#endif
1545 +
1546 +#if 0
1547 +        for(i=0; i<25; i++)
1548 +                printf("(%d, %d) to (%d, %d)\n", (y_cfg +i)->region.bottom_left.x,(y_cfg +i)->region.bottom_left.y,(y_cfg +i)->region.top_right.x, (y_cfg +i)->region.top_right.y);
1549 +#endif
1550 +
1551 +
1552 +
1553 +        for(i=0; i<25; i++) {
1554 +                (t_cfg+i)->color.r = 0.0;
1555 +                (t_cfg+i)->color.g = 1.0;
1556 +                (t_cfg+i)->color.b = 1.0;
1557 +                (t_cfg+i)->color.a = 1.0;
1558 +                (t_cfg+i)->fontsize = FONT_SIZE;
1559 +        }
1560 +                (t_cfg+0)->fontsize = 20;
1561 +
1562 +
1563 +}
1564 +
1565 +
1566 +void statCollectorInit()
1567 +{
1568 +    int index;
1569 +
1570 +    gStatColState.stat0_filter_cnt = 0;
1571 +    gStatColState.stat1_filter_cnt = 0;
1572 +    gStatColState.stat2_filter_cnt = 0;
1573 +    gStatColState.stat3_filter_cnt = 0;
1574 +    gStatColState.stat4_filter_cnt = 0;
1575 +    gStatColState.stat5_filter_cnt = 0;
1576 +    gStatColState.stat6_filter_cnt = 0;
1577 +    gStatColState.stat7_filter_cnt = 0;
1578 +    gStatColState.stat8_filter_cnt = 0;
1579 +    gStatColState.stat9_filter_cnt = 0;
1580 +
1581 +    for(index=STATCOL_EMIF1_SYS; index < STATCOL_MAX; index++)
1582 +    {
1583 +       global_object[index].b_enabled = 0;
1584 +
1585 +       strcpy(global_object[index].name, initiators[index].name); 
1586 +
1587 +       global_object[index].readings = malloc(TRACE_SZ * sizeof(UInt32));
1588 +       memset(global_object[index].readings, 0, TRACE_SZ * sizeof(UInt32));
1589 +
1590 +       global_object[index].timestamp = NULL;
1591 +
1592 +       global_object[index].group_id = 0xFF;
1593 +       global_object[index].counter_id = 0;
1594 +       global_object[index].base_address = 0;
1595 +       global_object[index].mux_req = 0;
1596 +    }
1597 +
1598 +}
1599 +
1600 +void wr_stat_reg(UInt32 address, UInt32 data)
1601 +{
1602 +    UInt32 *mymem = statcoll_base_mem;
1603 +    UInt32 delta = (address - STATCOLL_BASE) / 4;
1604 +#ifndef DUMMY_MODE
1605 +    mymem[delta] = data;
1606 +#else
1607 +    printf("WRITE: Address = 0x%x, Data = 0x%x\n", address, data);
1608 +#endif
1609 +}
1610 +
1611 +UInt32 rd_stat_reg(UInt32 address)
1612 +{
1613 +#ifndef DUMMY_MODE
1614 +    UInt32 *mymem = statcoll_base_mem;
1615 +    UInt32 data;
1616 +    UInt32 delta = (address - STATCOLL_BASE) / 4;
1617 +    data = mymem[delta];
1618 +    return data;
1619 +#else
1620 +    printf("READ: Address = 0x%x\n", address);
1621 +#endif
1622 +}
1623 +
1624 +UInt32 statCollectorControlInitialize(UInt32 instance_id)
1625 +{
1626 +    UInt32 cur_base_address = 0;
1627 +    UInt32 cur_event_mux_req;
1628 +    UInt32 cur_event_mux_resp;
1629 +    UInt32 cur_stat_filter_cnt;
1630 +
1631 +    switch (instance_id)
1632 +    {
1633 +    case STATCOL_EMIF1_SYS:
1634 +        cur_base_address = stat_coll0_base_address;
1635 +        cur_event_mux_req = 0;
1636 +        cur_event_mux_resp = 1;
1637 +        gStatColState.stat0_filter_cnt = gStatColState.stat0_filter_cnt + 1;
1638 +        cur_stat_filter_cnt = gStatColState.stat0_filter_cnt;
1639 +       global_object[instance_id].group_id = 0;
1640 +        break;
1641 +    case STATCOL_EMIF2_SYS:
1642 +        cur_base_address = stat_coll0_base_address;
1643 +        cur_event_mux_req = 2;
1644 +        cur_event_mux_resp = 3;
1645 +        gStatColState.stat0_filter_cnt = gStatColState.stat0_filter_cnt + 1;
1646 +        cur_stat_filter_cnt = gStatColState.stat0_filter_cnt;
1647 +       global_object[instance_id].group_id = 0;
1648 +        break;
1649 +    case STATCOL_MA_MPU_P1:
1650 +        cur_base_address = stat_coll0_base_address;
1651 +        cur_event_mux_req = 4;
1652 +        cur_event_mux_resp = 5;
1653 +        gStatColState.stat0_filter_cnt = gStatColState.stat0_filter_cnt + 1;
1654 +        cur_stat_filter_cnt = gStatColState.stat0_filter_cnt;
1655 +       global_object[instance_id].group_id = 0;
1656 +        break;
1657 +    case STATCOL_MA_MPU_P2:
1658 +        cur_base_address = stat_coll0_base_address;
1659 +        cur_event_mux_req = 6;
1660 +        cur_event_mux_resp = 7;
1661 +        gStatColState.stat0_filter_cnt = gStatColState.stat0_filter_cnt + 1;
1662 +        cur_stat_filter_cnt = gStatColState.stat0_filter_cnt;
1663 +       global_object[instance_id].group_id = 0;
1664 +        break;
1665 +    case STATCOL_MPU1:
1666 +        cur_base_address = stat_coll1_base_address;
1667 +        cur_event_mux_req = 0;
1668 +        cur_event_mux_resp = 1;
1669 +        gStatColState.stat1_filter_cnt = gStatColState.stat1_filter_cnt + 1;
1670 +        cur_stat_filter_cnt = gStatColState.stat1_filter_cnt;
1671 +       global_object[instance_id].group_id = 1;
1672 +        break;
1673 +    case STATCOL_MMU1:
1674 +        cur_base_address = stat_coll1_base_address;
1675 +        cur_event_mux_req = 2;
1676 +        cur_event_mux_resp = 3;
1677 +        gStatColState.stat1_filter_cnt = gStatColState.stat1_filter_cnt + 1;
1678 +        cur_stat_filter_cnt = gStatColState.stat1_filter_cnt;
1679 +       global_object[instance_id].group_id = 1;
1680 +        break;
1681 +    case STATCOL_TPTC_RD1:
1682 +        cur_base_address = stat_coll1_base_address;
1683 +        cur_event_mux_req = 4;
1684 +        cur_event_mux_resp = 5;
1685 +        gStatColState.stat1_filter_cnt = gStatColState.stat1_filter_cnt + 1;
1686 +        cur_stat_filter_cnt = gStatColState.stat1_filter_cnt;
1687 +       global_object[instance_id].group_id = 1;
1688 +        break;
1689 +    case STATCOL_TPTC_WR1:
1690 +        cur_base_address = stat_coll1_base_address;
1691 +        cur_event_mux_req = 6;
1692 +        cur_event_mux_resp = 7;
1693 +        gStatColState.stat1_filter_cnt = gStatColState.stat1_filter_cnt + 1;
1694 +        cur_stat_filter_cnt = gStatColState.stat1_filter_cnt;
1695 +       global_object[instance_id].group_id = 1;
1696 +        break;
1697 +    case STATCOL_TPTC_RD2:
1698 +        cur_base_address = stat_coll1_base_address;
1699 +        cur_event_mux_req = 8;
1700 +        cur_event_mux_resp = 9;
1701 +        gStatColState.stat1_filter_cnt = gStatColState.stat1_filter_cnt + 1;
1702 +        cur_stat_filter_cnt = gStatColState.stat1_filter_cnt;
1703 +       global_object[instance_id].group_id = 1;
1704 +        break;
1705 +    case STATCOL_TPTC_WR2:
1706 +        cur_base_address = stat_coll1_base_address;
1707 +        cur_event_mux_req = 10;
1708 +        cur_event_mux_resp = 11;
1709 +        gStatColState.stat1_filter_cnt = gStatColState.stat1_filter_cnt + 1;
1710 +        cur_stat_filter_cnt = gStatColState.stat1_filter_cnt;
1711 +       global_object[instance_id].group_id = 1;
1712 +        break;
1713 +    case STATCOL_VIP1_P1:
1714 +        cur_base_address = stat_coll2_base_address;
1715 +        cur_event_mux_req = 0;
1716 +        cur_event_mux_resp = 1;
1717 +        gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1718 +        cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1719 +       global_object[instance_id].group_id = 2;
1720 +        break;
1721 +    case STATCOL_VIP1_P2:
1722 +        cur_base_address = stat_coll2_base_address;
1723 +        cur_event_mux_req = 2;
1724 +        cur_event_mux_resp = 3;
1725 +        gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1726 +        cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1727 +       global_object[instance_id].group_id = 2;
1728 +        break;
1729 +    case STATCOL_VIP2_P1:
1730 +        cur_base_address = stat_coll2_base_address;
1731 +        cur_event_mux_req = 4;
1732 +        cur_event_mux_resp = 5;
1733 +        gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1734 +        cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1735 +       global_object[instance_id].group_id = 2;
1736 +        break;
1737 +    case STATCOL_VIP2_P2:
1738 +        cur_base_address = stat_coll2_base_address;
1739 +        cur_event_mux_req = 6;
1740 +        cur_event_mux_resp = 7;
1741 +        gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1742 +        cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1743 +       global_object[instance_id].group_id = 2;
1744 +        break;
1745 +    case STATCOL_VIP3_P1:
1746 +        cur_base_address = stat_coll2_base_address;
1747 +        cur_event_mux_req = 8;
1748 +        cur_event_mux_resp = 9;
1749 +        gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1750 +        cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1751 +       global_object[instance_id].group_id = 2;
1752 +        break;
1753 +    case STATCOL_VIP3_P2:
1754 +        cur_base_address = stat_coll2_base_address;
1755 +        cur_event_mux_req = 10;
1756 +        cur_event_mux_resp = 11;
1757 +        gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1758 +        cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1759 +       global_object[instance_id].group_id = 2;
1760 +        break;
1761 +    case STATCOL_VPE_P1:
1762 +        cur_base_address = stat_coll2_base_address;
1763 +        cur_event_mux_req = 12;
1764 +        cur_event_mux_resp = 13;
1765 +        gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1766 +        cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1767 +       global_object[instance_id].group_id = 2;
1768 +        break;
1769 +    case STATCOL_VPE_P2:
1770 +        cur_base_address = stat_coll2_base_address;
1771 +        cur_event_mux_req = 14;
1772 +        cur_event_mux_resp = 15;
1773 +        gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1774 +        cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1775 +       global_object[instance_id].group_id = 2;
1776 +        break;
1777 +    case STATCOL_EVE1_TC0:
1778 +        cur_base_address = stat_coll3_base_address;
1779 +        cur_event_mux_req = 0;
1780 +        cur_event_mux_resp = 1;
1781 +        gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1782 +        cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1783 +       global_object[instance_id].group_id = 3;
1784 +        break;
1785 +    case STATCOL_EVE1_TC1:
1786 +        cur_base_address = stat_coll3_base_address;
1787 +        cur_event_mux_req = 2;
1788 +        cur_event_mux_resp = 3;
1789 +        gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1790 +        cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1791 +       global_object[instance_id].group_id = 3;
1792 +        break;
1793 +    case STATCOL_EVE2_TC0:
1794 +        cur_base_address = stat_coll3_base_address;
1795 +        cur_event_mux_req = 4;
1796 +        cur_event_mux_resp = 5;
1797 +        gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1798 +        cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1799 +       global_object[instance_id].group_id = 3;
1800 +        break;
1801 +    case STATCOL_EVE2_TC1:
1802 +        cur_base_address = stat_coll3_base_address;
1803 +        cur_event_mux_req = 6;
1804 +        cur_event_mux_resp = 7;
1805 +        gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1806 +        cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1807 +       global_object[instance_id].group_id = 3;
1808 +        break;
1809 +    case STATCOL_EVE3_TC0:
1810 +        cur_base_address = stat_coll3_base_address;
1811 +        cur_event_mux_req = 8;
1812 +        cur_event_mux_resp = 9;
1813 +        gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1814 +        cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1815 +       global_object[instance_id].group_id = 3;
1816 +        break;
1817 +    case STATCOL_EVE3_TC1:
1818 +        cur_base_address = stat_coll3_base_address;
1819 +        cur_event_mux_req = 10;
1820 +        cur_event_mux_resp = 11;
1821 +        gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1822 +        cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1823 +       global_object[instance_id].group_id = 3;
1824 +        break;
1825 +    case STATCOL_EVE4_TC0:
1826 +        cur_base_address = stat_coll3_base_address;
1827 +        cur_event_mux_req = 12;
1828 +        cur_event_mux_resp = 13;
1829 +        gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1830 +        cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1831 +       global_object[instance_id].group_id = 3;
1832 +        break;
1833 +    case STATCOL_EVE4_TC1:
1834 +        cur_base_address = stat_coll3_base_address;
1835 +        cur_event_mux_req = 14;
1836 +        cur_event_mux_resp = 15;
1837 +        gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1838 +        cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1839 +       global_object[instance_id].group_id = 3;
1840 +        break;
1841 +    case STATCOL_DSP1_MDMA:
1842 +        cur_base_address = stat_coll4_base_address;
1843 +        cur_event_mux_req = 0;
1844 +        cur_event_mux_resp = 1;
1845 +        gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1846 +        cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1847 +       global_object[instance_id].group_id = 4;
1848 +        break;
1849 +    case STATCOL_DSP1_EDMA:
1850 +        cur_base_address = stat_coll4_base_address;
1851 +        cur_event_mux_req = 2;
1852 +        cur_event_mux_resp = 3;
1853 +        gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1854 +        cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1855 +       global_object[instance_id].group_id = 4;
1856 +        break;
1857 +    case STATCOL_DSP2_MDMA:
1858 +        cur_base_address = stat_coll4_base_address;
1859 +        cur_event_mux_req = 4;
1860 +        cur_event_mux_resp = 5;
1861 +        gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1862 +        cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1863 +       global_object[instance_id].group_id = 4;
1864 +        break;
1865 +    case STATCOL_DSP2_EDMA:
1866 +        cur_base_address = stat_coll4_base_address;
1867 +        cur_event_mux_req = 6;
1868 +        cur_event_mux_resp = 7;
1869 +        gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1870 +        cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1871 +       global_object[instance_id].group_id = 4;
1872 +        break;
1873 +    case STATCOL_IVA:
1874 +        cur_base_address = stat_coll4_base_address;
1875 +        cur_event_mux_req = 8;
1876 +        cur_event_mux_resp = 9;
1877 +        gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1878 +        cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1879 +       global_object[instance_id].group_id = 4;
1880 +        break;
1881 +    case STATCOL_GPU_P1:
1882 +        cur_base_address = stat_coll4_base_address;
1883 +        cur_event_mux_req = 10;
1884 +        cur_event_mux_resp = 11;
1885 +        gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1886 +        cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1887 +       global_object[instance_id].group_id = 4;
1888 +        break;
1889 +    case STATCOL_GPU_P2:
1890 +        cur_base_address = stat_coll4_base_address;
1891 +        cur_event_mux_req = 12;
1892 +        cur_event_mux_resp = 13;
1893 +        gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1894 +        cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1895 +       global_object[instance_id].group_id = 4;
1896 +        break;
1897 +    case STATCOL_BB2D_P1:
1898 +        cur_base_address = stat_coll4_base_address;
1899 +        cur_event_mux_req = 14;
1900 +        cur_event_mux_resp = 15;
1901 +        gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1902 +        cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1903 +       global_object[instance_id].group_id = 4;
1904 +        break;
1905 +    case STATCOL_DSS:
1906 +        cur_base_address = stat_coll5_base_address;
1907 +        cur_event_mux_req = 0;
1908 +        cur_event_mux_resp = 1;
1909 +        gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1910 +        cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1911 +       global_object[instance_id].group_id = 5;
1912 +        break;
1913 +    case STATCOL_CSI2_2:
1914 +        cur_base_address = stat_coll5_base_address;
1915 +        cur_event_mux_req = 2;
1916 +        cur_event_mux_resp = 3;
1917 +        gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1918 +        cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1919 +       global_object[instance_id].group_id = 5;
1920 +        break;
1921 +    case STATCOL_MMU2:
1922 +        cur_base_address = stat_coll5_base_address;
1923 +        cur_event_mux_req = 4;
1924 +        cur_event_mux_resp = 5;
1925 +        gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1926 +        cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1927 +       global_object[instance_id].group_id = 5;
1928 +        break;
1929 +    case STATCOL_IPU1:
1930 +        cur_base_address = stat_coll5_base_address;
1931 +        cur_event_mux_req = 6;
1932 +        cur_event_mux_resp = 7;
1933 +        gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1934 +        cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1935 +       global_object[instance_id].group_id = 5;
1936 +        break;
1937 +    case STATCOL_IPU2:
1938 +        cur_base_address = stat_coll5_base_address;
1939 +        cur_event_mux_req = 8;
1940 +        cur_event_mux_resp = 9;
1941 +        gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1942 +        cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1943 +       global_object[instance_id].group_id = 5;
1944 +        break;
1945 +    case STATCOL_DMA_SYSTEM_RD:
1946 +        cur_base_address = stat_coll5_base_address;
1947 +        cur_event_mux_req = 10;
1948 +        cur_event_mux_resp = 11;
1949 +        gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1950 +        cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1951 +       global_object[instance_id].group_id = 5;
1952 +        break;
1953 +    case STATCOL_DMA_SYSTEM_WR:
1954 +        cur_base_address = stat_coll5_base_address;
1955 +        cur_event_mux_req = 12;
1956 +        cur_event_mux_resp = 13;
1957 +        gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1958 +        cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1959 +       global_object[instance_id].group_id = 5;
1960 +        break;
1961 +    case STATCOL_CSI2_1:
1962 +        cur_base_address = stat_coll5_base_address;
1963 +        cur_event_mux_req = 14;
1964 +        cur_event_mux_resp = 15;
1965 +        gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1966 +        cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1967 +       global_object[instance_id].group_id = 5;
1968 +        break;
1969 +    case STATCOL_USB3_SS:
1970 +        cur_base_address = stat_coll6_base_address;
1971 +        cur_event_mux_req = 0;
1972 +        cur_event_mux_resp = 1;
1973 +        gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
1974 +        cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
1975 +       global_object[instance_id].group_id = 6;
1976 +        break;
1977 +    case STATCOL_USB2_SS:
1978 +        cur_base_address = stat_coll6_base_address;
1979 +        cur_event_mux_req = 2;
1980 +        cur_event_mux_resp = 3;
1981 +        gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
1982 +        cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
1983 +       global_object[instance_id].group_id = 6;
1984 +        break;
1985 +    case STATCOL_USB2_ULPI_SS1:
1986 +        cur_base_address = stat_coll6_base_address;
1987 +        cur_event_mux_req = 4;
1988 +        cur_event_mux_resp = 5;
1989 +        gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
1990 +        cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
1991 +       global_object[instance_id].group_id = 6;
1992 +        break;
1993 +    case STATCOL_USB2_ULPI_SS2:
1994 +        cur_base_address = stat_coll6_base_address;
1995 +        cur_event_mux_req = 6;
1996 +        cur_event_mux_resp = 7;
1997 +        gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
1998 +        cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
1999 +       global_object[instance_id].group_id = 6;
2000 +        break;
2001 +    case STATCOL_PCIE_SS1:
2002 +        cur_base_address = stat_coll6_base_address;
2003 +        cur_event_mux_req = 8;
2004 +        cur_event_mux_resp = 9;
2005 +        gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
2006 +        cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
2007 +       global_object[instance_id].group_id = 6;
2008 +        break;
2009 +    case STATCOL_PCIE_SS2:
2010 +        cur_base_address = stat_coll6_base_address;
2011 +        cur_event_mux_req = 10;
2012 +        cur_event_mux_resp = 11;
2013 +        gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
2014 +        cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
2015 +       global_object[instance_id].group_id = 6;
2016 +        break;
2017 +    case STATCOL_DSP1_CFG:
2018 +        cur_base_address = stat_coll6_base_address;
2019 +        cur_event_mux_req = 12;
2020 +        cur_event_mux_resp = 13;
2021 +        gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
2022 +        cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
2023 +       global_object[instance_id].group_id = 6;
2024 +        break;
2025 +    case STATCOL_DSP2_CFG:
2026 +        cur_base_address = stat_coll6_base_address;
2027 +        cur_event_mux_req = 14;
2028 +        cur_event_mux_resp = 15;
2029 +        gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
2030 +        cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
2031 +       global_object[instance_id].group_id = 6;
2032 +        break;
2033 +    case STATCOL_GMAC_SW:
2034 +        cur_base_address = stat_coll7_base_address;
2035 +        cur_event_mux_req = 0;
2036 +        cur_event_mux_resp = 1;
2037 +        gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2038 +        cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2039 +       global_object[instance_id].group_id = 7;
2040 +        break;
2041 +    case STATCOL_PRUSS1_P1:
2042 +        cur_base_address = stat_coll7_base_address;
2043 +        cur_event_mux_req = 2;
2044 +        cur_event_mux_resp = 3;
2045 +        gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2046 +        cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2047 +       global_object[instance_id].group_id = 7;
2048 +        break;
2049 +    case STATCOL_PRUSS1_P2:
2050 +        cur_base_address = stat_coll7_base_address;
2051 +        cur_event_mux_req = 4;
2052 +        cur_event_mux_resp = 5;
2053 +        gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2054 +        cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2055 +       global_object[instance_id].group_id = 7;
2056 +        break;
2057 +    case STATCOL_PRUSS2_P1:
2058 +        cur_base_address = stat_coll7_base_address;
2059 +        cur_event_mux_req = 6;
2060 +        cur_event_mux_resp = 7;
2061 +        gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2062 +        cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2063 +       global_object[instance_id].group_id = 7;
2064 +        break;
2065 +    case STATCOL_PRUSS2_P2:
2066 +        cur_base_address = stat_coll7_base_address;
2067 +        cur_event_mux_req = 8;
2068 +        cur_event_mux_resp = 9;
2069 +        gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2070 +        cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2071 +       global_object[instance_id].group_id = 7;
2072 +        break;
2073 +    case STATCOL_DMA_CRYPTO_RD:
2074 +        cur_base_address = stat_coll7_base_address;
2075 +        cur_event_mux_req = 10;
2076 +        cur_event_mux_resp = 11;
2077 +        gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2078 +        cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2079 +       global_object[instance_id].group_id = 7;
2080 +        break;
2081 +    case STATCOL_DMA_CRYPTO_WR:
2082 +        cur_base_address = stat_coll7_base_address;
2083 +        cur_event_mux_req = 12;
2084 +        cur_event_mux_resp = 13;
2085 +        gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2086 +        cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2087 +       global_object[instance_id].group_id = 7;
2088 +        break;
2089 +    case STATCOL_MPU2:
2090 +        cur_base_address = stat_coll7_base_address;
2091 +        cur_event_mux_req = 14;
2092 +        cur_event_mux_resp = 15;
2093 +        gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2094 +        cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2095 +       global_object[instance_id].group_id = 7;
2096 +        break;
2097 +    case STATCOL_MMC1:
2098 +        cur_base_address = stat_coll8_base_address;
2099 +        cur_event_mux_req = 0;
2100 +        cur_event_mux_resp = 1;
2101 +        gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2102 +        cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2103 +       global_object[instance_id].group_id = 8;
2104 +        break;
2105 +    case STATCOL_MMC2:
2106 +        cur_base_address = stat_coll8_base_address;
2107 +        cur_event_mux_req = 2;
2108 +        cur_event_mux_resp = 3;
2109 +        gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2110 +        cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2111 +       global_object[instance_id].group_id = 8;
2112 +        break;
2113 +    case STATCOL_SATA:
2114 +        cur_base_address = stat_coll8_base_address;
2115 +        cur_event_mux_req = 4;
2116 +        cur_event_mux_resp = 5;
2117 +        gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2118 +        cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2119 +       global_object[instance_id].group_id = 8;
2120 +        break;
2121 +    case STATCOL_MLBSS:
2122 +        cur_base_address = stat_coll8_base_address;
2123 +        cur_event_mux_req = 6;
2124 +        cur_event_mux_resp = 7;
2125 +        gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2126 +        cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2127 +       global_object[instance_id].group_id = 8;
2128 +        break;
2129 +    case STATCOL_BB2D_P2:
2130 +        cur_base_address = stat_coll8_base_address;
2131 +        cur_event_mux_req = 8;
2132 +        cur_event_mux_resp = 9;
2133 +        gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2134 +        cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2135 +       global_object[instance_id].group_id = 8;
2136 +        break;
2137 +    case STATCOL_IEEE1500:
2138 +        cur_base_address = stat_coll8_base_address;
2139 +        cur_event_mux_req = 10;
2140 +        cur_event_mux_resp = 11;
2141 +        gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2142 +        cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2143 +       global_object[instance_id].group_id = 8;
2144 +        break;
2145 +    case STATCOL_DBG:
2146 +        cur_base_address = stat_coll8_base_address;
2147 +        cur_event_mux_req = 12;
2148 +        cur_event_mux_resp = 13;
2149 +        gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2150 +        cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2151 +       global_object[instance_id].group_id = 8;
2152 +        break;
2153 +    case STATCOL_VCP1:
2154 +        cur_base_address = stat_coll8_base_address;
2155 +        cur_event_mux_req = 14;
2156 +        cur_event_mux_resp = 15;
2157 +        gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2158 +        cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2159 +       global_object[instance_id].group_id = 8;
2160 +        break;
2161 +    case STATCOL_OCMC_RAM1:
2162 +        cur_base_address = stat_coll9_base_address;
2163 +        cur_event_mux_req = 0;
2164 +        cur_event_mux_resp = 1;
2165 +        gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2166 +        cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2167 +       global_object[instance_id].group_id = 9;
2168 +        break;
2169 +    case STATCOL_OCMC_RAM2:
2170 +        cur_base_address = stat_coll9_base_address;
2171 +        cur_event_mux_req = 2;
2172 +        cur_event_mux_resp = 3;
2173 +        gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2174 +        cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2175 +       global_object[instance_id].group_id = 9;
2176 +        break;
2177 +    case STATCOL_OCMC_RAM3:
2178 +        cur_base_address = stat_coll9_base_address;
2179 +        cur_event_mux_req = 4;
2180 +        cur_event_mux_resp = 5;
2181 +        gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2182 +        cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2183 +       global_object[instance_id].group_id = 9;
2184 +        break;
2185 +    case STATCOL_GPMC:
2186 +        cur_base_address = stat_coll9_base_address;
2187 +        cur_event_mux_req = 6;
2188 +        cur_event_mux_resp = 7;
2189 +        gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2190 +        cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2191 +       global_object[instance_id].group_id = 9;
2192 +        break;
2193 +    case STATCOL_MCASP1:
2194 +        cur_base_address = stat_coll9_base_address;
2195 +        cur_event_mux_req = 8;
2196 +        cur_event_mux_resp = 9;
2197 +        gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2198 +        cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2199 +       global_object[instance_id].group_id = 9;
2200 +        break;
2201 +    case STATCOL_MCASP2:
2202 +        cur_base_address = stat_coll9_base_address;
2203 +        cur_event_mux_req = 10;
2204 +        cur_event_mux_resp = 11;
2205 +        gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2206 +        cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2207 +       global_object[instance_id].group_id = 9;
2208 +        break;
2209 +    case STATCOL_MCASP3:
2210 +        cur_base_address = stat_coll9_base_address;
2211 +        cur_event_mux_req = 12;
2212 +        cur_event_mux_resp = 13;
2213 +        gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2214 +        cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2215 +       global_object[instance_id].group_id = 9;
2216 +        break;
2217 +    case STATCOL_VCP2:
2218 +        cur_base_address = stat_coll9_base_address;
2219 +        cur_event_mux_req = 14;
2220 +        cur_event_mux_resp = 15;
2221 +        gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2222 +        cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2223 +       global_object[instance_id].group_id = 9;
2224 +        break;
2225 +    default:
2226 +       printf("ERROR: Unknown initiator %d\n", instance_id);
2227 +       exit(0);
2228 +    };
2229 +
2230 +    {
2231 +        if ( cur_stat_filter_cnt > 4 )
2232 +        {
2233 +            printf("WARNING: We have exhausted filters/counters.....\n");
2234 +            return 0;
2235 +        }
2236 +        // Global Enable Stat Collector
2237 +        wr_stat_reg(cur_base_address+0x8,0x1);
2238 +
2239 +        // Soft Enable Stat Collector
2240 +        wr_stat_reg(cur_base_address+0xC,0x1);
2241 +
2242 +        wr_stat_reg(cur_base_address+0x18,0x5);
2243 +        // Operation of Stat Collector / RespEvt => Packet
2244 +        wr_stat_reg(cur_base_address+0x1C,0x5);
2245 +
2246 +
2247 +        // Event Sel
2248 +        wr_stat_reg(cur_base_address+0x20+4*(cur_stat_filter_cnt-1),cur_event_mux_req);
2249 +
2250 +        // Op is EventInfo
2251 +        wr_stat_reg(cur_base_address+0x1FC+(0x158*(cur_stat_filter_cnt-1)),2);
2252 +
2253 +        // Event Info Sel Op -> packet length
2254 +        wr_stat_reg(cur_base_address+0x1F8+(0x158*(cur_stat_filter_cnt-1)),0);
2255 +
2256 +        // Filter Global Enable
2257 +        wr_stat_reg(cur_base_address+0xAC+(0x158*(cur_stat_filter_cnt-1)),0x1);
2258 +
2259 +        // Filter Enable
2260 +        wr_stat_reg(cur_base_address+0xBC+(0x158*(cur_stat_filter_cnt-1)),0x1);
2261 +
2262 +        // Manual dump
2263 +        wr_stat_reg(cur_base_address+0x54,0x1);
2264 +        // use send register to reset counters
2265 +
2266 +    }
2267 +
2268 +    global_object[instance_id].mux_req = cur_event_mux_req;
2269 +    global_object[instance_id].base_address = cur_base_address;
2270 +    global_object[instance_id].counter_id = cur_stat_filter_cnt;
2271 +    global_object[instance_id].b_enabled = 1;
2272 +
2273 +    return cur_stat_filter_cnt;
2274 +}
2275 +
2276 +
2277 +
2278 +void statCollectorReadGroup(UInt32 group_id)
2279 +{
2280 +    int i=0;
2281 +    UInt32 cur_base_address = 0x45001000 + ((group_id - 1) * 0x1000);
2282 +
2283 +    wr_stat_reg(cur_base_address+0xC,0x0);
2284 +
2285 +    for(i=0; i < STATCOL_MAX; i++)
2286 +    {
2287 +       if(global_object[i].group_id == (group_id - 1) && 
2288 +          global_object[i].b_enabled == 1)
2289 +       {
2290 +           UInt32 cur_stat_filter_cnt = global_object[i].counter_id;
2291 +
2292 +           global_object[i].readings[statCountIdx] = rd_stat_reg(cur_base_address+0x8C+((cur_stat_filter_cnt-1)*4));
2293 +        }
2294 +    }
2295 +
2296 +    wr_stat_reg(cur_base_address+0xC,0x1);
2297 +}
2298 +
2299 +
2300 +volatile sig_atomic_t sigtermed = 0;
2301 +
2302 +void my_signal_handler(int signum)
2303 +{
2304 +       if (signum == SIGTERM || signum == SIGINT) {
2305 +               sigtermed = 1;
2306 +       }
2307 +}
2308 +
2309 +struct sort
2310 +{
2311 +       int pos;
2312 +       double value;
2313 +};
2314 +
2315 +
2316 +void *ctx;
2317 +struct time_graph_create_params p;
2318 +char xpos_string[100], ypos_string[100];
2319 +
2320 +void mpu_handler(int command)
2321 +{
2322 +#if 1
2323 +        static int fd;
2324 +        char buf[1000];
2325 +        char * tabledata= "/tmp/statcollfifo";
2326 +        int i;
2327 +        int bytes;
2328 +        static int offset = 13;
2329 +
2330 +        switch(command)
2331 +        {
2332 +                case OPEN:
2333 +                        fd = open(tabledata, O_RDONLY|O_NONBLOCK);
2334 +                        break;
2335 +
2336 +                case READ:
2337 +
2338 +                        /* open, read, and display the message from the FIFO */
2339 +                        bytes=read(fd, buf, 1000);
2340 +                        if(bytes > 0)
2341 +                        {
2342 +                                char str[100];
2343 +                                char value[100];
2344 +                                sscanf(buf, "%s %s", str, value);
2345 +                                if(strcmp(str, "MOVE:") == 0)
2346 +                                {
2347 +                                        printf("Received MOVE command : %s\n", buf);
2348 +                                        sprintf(p.title, "CPU Usage[@position-req=%sx%s]", value, ypos_string);
2349 +                                        move_graph(ctx, &p);
2350 +                                }
2351 +                                else
2352 +                                {
2353 +                                        printf("ERROR: Received unexpected data from FIFO - \" %s \" \n", buf);
2354 +                                }
2355 +                                memset(buf, 0x0, sizeof(buf));
2356 +                        }
2357 +
2358 +                        break;
2359 +
2360 +                case CLOSE:
2361 +                        close(fd);
2362 +                        break;
2363 +        }
2364 +#endif
2365 +        return;
2366 +}
2367 +
2368 +
2369 +UInt32 statcoll_start(UInt32 TOTAL_TIME, UInt32 INTERVAL_US, char list[][50], UInt32 xpos, UInt32 ypos)
2370 +{
2371 +    int i, fd, index;
2372 +    UInt32 counterIdDss, counterIdIva, counterIdBB2dP1, counterIdBB2dP2, counterIdUsb4, counterIdSata, counterIdEmif1, counterIdEmif2;
2373 +
2374 +    if (SIG_ERR == signal(SIGPIPE,SIG_IGN))
2375 +           exit(1);
2376 +
2377 +    if (SIG_ERR == signal(SIGINT,my_signal_handler))
2378 +           exit(1);
2379 +
2380 +    if (SIG_ERR == signal(SIGTERM,my_signal_handler))
2381 +           exit(1);
2382 +
2383 +  
2384 +    struct timeval tv1, tv2;
2385 +    gettimeofday(&tv1, NULL);
2386 +    printf("------------------------------------------------\n");
2387 +    printf("Compile time = %s %s\n",__DATE__,  __TIME__);
2388 +    printf("------------------------------------------------\n\n");
2389 +    //printd("Start time = %d\n", time(NULL));
2390 +    //printd("Time seconds = %d, usecs = %d\n", tv.tv_sec, tv.tv_usec);
2391 +
2392 +    statcoll_params params;
2393 +    memset(&params, sizeof(params), 0);
2394 +    params.INTERVAL_US = INTERVAL_US;
2395 +    params.TOTAL_TIME = TOTAL_TIME;
2396 +
2397 +    i=0;
2398 +    index=0;
2399 +
2400 +    while(list[i][0] != 0)
2401 +    {
2402 +       for(index=0; index< STATCOL_MAX; index++) {
2403 +               if(strcmp(list[i], initiators[index].name) == 0)
2404 +               {
2405 +                       strcpy(params.user_config_list[params.no_of_initiators].name, list[i]);
2406 +                       params.user_config_list[params.no_of_initiators++].id = initiators[index].id;
2407 +                       break;
2408 +               }
2409 +       }
2410 +
2411 +       if(index == STATCOL_MAX) {
2412 +               printf("ERROR: Unknown initiator.%d.. .%s. \n", i, list[i]);
2413 +               //exit(0);
2414 +       }
2415 +        i++;
2416 +    }
2417 +
2418 +       struct bar_graph_create_params bg_p;
2419 +       struct _y_config *y_cfg;
2420 +       struct _text_config *t_cfg;
2421 +       double *y;
2422 +       double *bg_y;
2423 +        char *text_list[STATCOL_MAX];
2424 +
2425 +        struct _bar_graph_y_config *bg_y_cfg;
2426 +        struct _text_config *bg_t_cfg;
2427 +       char *bg_text_list[STATCOL_MAX];
2428 +       
2429 +       sprintf(xpos_string, "%d", xpos);
2430 +       sprintf(ypos_string, "%d", ypos);
2431 +       p.title=(char *)malloc(100);
2432 +       sprintf(p.title, "CPU Usage[@position-req=%sx%s]", xpos_string, ypos_string);
2433 +       //p.height = MAX_HEIGHT - HEIGHT_EMIF_AREA;
2434 +       p.height = MAX_HEIGHT;// - HEIGHT_EMIF_AREA;
2435 +       p.width = MAX_WIDTH;
2436 +       p.draw_area.bottom_left.x = TIME_GRAPH_AREA_BL_X;
2437 +       p.draw_area.bottom_left.y = TIME_GRAPH_AREA_BL_Y;
2438 +       p.draw_area.top_right.x = TIME_GRAPH_AREA_TR_X;
2439 +       p.draw_area.top_right.y = TIME_GRAPH_AREA_TR_Y;
2440 +       p.time_span = 120000; // 120 seconds
2441 +       p.num_of_y_items = params.no_of_initiators+1;
2442 +       p.num_of_text_items = 0;//params.no_of_initiators;
2443 +
2444 +
2445 +       y_cfg = malloc((params.no_of_initiators+1) * sizeof(struct _y_config));
2446 +       t_cfg = malloc(params.no_of_initiators * sizeof(struct _text_config));
2447 +       y = malloc((params.no_of_initiators+1) * sizeof(double));
2448 +       p.y_config_array = y_cfg;
2449 +       p.text_config_array = t_cfg;
2450 +
2451 +       bg_y_cfg = malloc(TOTAL_Y_PARAMETERS * sizeof(struct _bar_graph_y_config));
2452 +       bg_t_cfg = malloc(TOTAL_Y_PARAMETERS * sizeof(struct _text_config));
2453 +       bg_y = malloc(TOTAL_Y_PARAMETERS * sizeof(double));
2454 +
2455 +       for(i=0; i<TOTAL_Y_PARAMETERS; i++)
2456 +       {
2457 +               bg_text_list[i] = malloc(100);
2458 +               strcpy(bg_text_list[i],"test");
2459 +       }
2460 +
2461 +       create_overall_box(bg_y_cfg, bg_t_cfg, bg_text_list);
2462 +
2463 +
2464 +       i=0;
2465 +       while(i < params.no_of_initiators)
2466 +       {
2467 +               text_list[i] = malloc(100 * sizeof(char));
2468 +               memset(text_list[i], 0x0, 100);
2469 +
2470 +               ((struct _y_config *)y_cfg+i)->line_color.r = pallette[i%MAX_COLORS].r;
2471 +               ((struct _y_config *)y_cfg+i)->line_color.g = pallette[i%MAX_COLORS].g;
2472 +               ((struct _y_config *)y_cfg+i)->line_color.b = pallette[i%MAX_COLORS].b;
2473 +               ((struct _y_config *)y_cfg+i)->line_color.a = 0.0;//pallette[i%MAX_COLORS].a;
2474 +               
2475 +               ((struct _y_config *)y_cfg+i)->fill_color.r = 0.0;
2476 +               ((struct _y_config *)y_cfg+i)->fill_color.g = 1.0;
2477 +               ((struct _y_config *)y_cfg+i)->fill_color.b = 0.0;
2478 +               ((struct _y_config *)y_cfg+i)->fill_color.a = 0.5;
2479 +               
2480 +               i++;
2481 +       }
2482 +
2483 +       ((struct _y_config *)y_cfg+i)->line_color.r = 0.0;
2484 +       ((struct _y_config *)y_cfg+i)->line_color.g = 0.0;
2485 +       ((struct _y_config *)y_cfg+i)->line_color.b = 0.0;
2486 +       ((struct _y_config *)y_cfg+i)->line_color.a = 0.5;
2487 +       ((struct _y_config *)y_cfg+i)->fill_color.r = 0.1;
2488 +       ((struct _y_config *)y_cfg+i)->fill_color.g = 0.9;
2489 +       ((struct _y_config *)y_cfg+i)->fill_color.b = 0.5;
2490 +       ((struct _y_config *)y_cfg+i)->fill_color.a = 1.0;
2491 +
2492 +        bg_p.title = "CPU Usage";
2493 +       
2494 +        bg_p.num_of_y_items = TOTAL_Y_PARAMETERS;
2495 +        bg_p.y_config_array = bg_y_cfg;
2496 +        bg_p.num_of_text_items = TOTAL_Y_PARAMETERS;
2497 +        bg_p.text_config_array = bg_t_cfg;
2498 +
2499 +
2500 +       int argc;
2501 +       char *argv[10];
2502 +       ctx = time_graph_create(argc, argv, &p);
2503 +       if (!ctx) {
2504 +               printf("Error creating context\n");
2505 +               exit(0);
2506 +       }
2507 +
2508 +       printf("\n Context after time_graph_create = 0x%x\n", ctx);
2509 +       ctx = bar_graph_create(argc, argv, &bg_p);
2510 +       if (!ctx) {
2511 +               printf("Error creating context\n");
2512 +               exit(0);
2513 +       }
2514 +
2515 +       printf("\n Context after bar_graph_create= 0x%x\n", ctx);
2516 +
2517 +    printf("Total configured initiators = %d\n", params.no_of_initiators);
2518 +       
2519 +
2520 +    fd = open("/dev/mem", O_RDWR);
2521 +    if (fd == -1){
2522 +       printf("error fd=open() \n");     
2523 +       return -1;
2524 +    }
2525 +    statcoll_base_mem = mmap(NULL, STATCOLL_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, STATCOLL_BASE);
2526 +    
2527 +   if (statcoll_base_mem == MAP_FAILED){
2528 +        printf("ERROR: mmap failed \n");
2529 +        return;
2530 +    }
2531 +    close(fd);
2532 +
2533 +    fd = open("/dev/mem", O_RDWR);
2534 +    if (fd == -1){
2535 +       printf("error fd=open() \n");     
2536 +       return -1;
2537 +    }
2538 +    l3_3_clkctrl = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, CM_L3INSTR_REGISTER_BASE);
2539 +    if (l3_3_clkctrl == MAP_FAILED){
2540 +        printf("ERROR: mmap failed for CM_L3INSTR_REGISTER_BASE\n");
2541 +        return;
2542 +    }
2543 +    close(fd);
2544 +
2545 +    printf("SUCCESS: Mapped 0x%x to user space address 0x%x\n", STATCOLL_BASE, statcoll_base_mem);
2546 +    printf("INTERVAL = %d usecs\n", INTERVAL_US);
2547 +    printf("TOTAL TIME = %d seconds\n", TOTAL_TIME);
2548 +    TRACE_SZ = (TOTAL_TIME * 1000000)/INTERVAL_US;
2549 +    printf("TRACE SIZE = %d samples\n", TRACE_SZ);
2550 +
2551 +    printf("**************************************\n");
2552 +    printf("Going to initialize the L3 clocks \n"); 
2553 +    l3_3_clkctrl[CM_L3INSTR_L3INSTR_CLKSTCTRL_OFFSET >> 2] = 0x2;
2554 +    l3_3_clkctrl[CM_L3INSTR_L3_MAIN_2_CLKCTRL_OFFSET >> 2] = 0x1;
2555 +    printf("**************************************\n");
2556 +
2557 +    while( (l3_3_clkctrl[CM_L3INSTR_L3_MAIN_2_CLKCTRL_OFFSET >> 2] & 0x30000) != 0x0) 
2558 +    {
2559 +       printf("Waiting on module to be functional\n");
2560 +    }
2561 +
2562 +    statCollectorInit();
2563 +
2564 +    printf("SUCCESS: Initialized STAT COLLECTOR\n");
2565 +    /* Initialize all enabled initiators */
2566 +    for(index =0; index < params.no_of_initiators; index++) {
2567 +        printf("\t\t Initialized %s\n", params.user_config_list[index].name);
2568 +        statCollectorControlInitialize(params.user_config_list[index].id);
2569 +    }
2570 +
2571 +       const char *bg_text = "CPU Utilization";
2572 +
2573 +    int second_counter=0;
2574 +    memset(y, 0x0, sizeof(double)* (params.no_of_initiators+1));
2575 +
2576 +
2577 +
2578 +
2579 +    mpu_handler(OPEN);
2580 +
2581 +
2582 +    while(statCountIdx != (TRACE_SZ - 1))
2583 +    {
2584 +        usleep(INTERVAL_US);
2585 +        int group;
2586 +       for(group = 1; group<11; group++)
2587 +               statCollectorReadGroup(group);
2588 +
2589 +        mpu_handler(READ);
2590 +
2591 +       if(statCountIdx != 0 ) 
2592 +       for(i=0; i<params.no_of_initiators; i++) {
2593 +               y[i] += (double)(global_object[params.user_config_list[i].id].readings[statCountIdx])/ (8000000000);
2594 +       }
2595 +       second_counter++;
2596 +
2597 +       if(second_counter % 30 == 0)
2598 +       {
2599 +               
2600 +               for(i=0; i<TOTAL_Y_PARAMETERS; i++) {
2601 +                       bg_y[i] = 1.0;
2602 +               }
2603 +
2604 +               //HACK
2605 +               bg_y[9]=y[0]*2;
2606 +               bg_y[11]=y[1]*2;
2607 +               sprintf(bg_text_list[8], "%02.1f%s", y[0]*100, "%");
2608 +               sprintf(bg_text_list[10], "%02.1f%s", y[1]*100, "%");
2609 +
2610 +               struct sort sort_array[STATCOL_MAX];
2611 +               memset(sort_array, 0x0, sizeof(struct sort) * STATCOL_MAX);
2612 +               /* Sort here */
2613 +               for(i=2; i<params.no_of_initiators; i++) {
2614 +                       sort_array[i-2].value = y[i];
2615 +                       sort_array[i-2].pos = i;
2616 +               }
2617 +
2618 +               int j;
2619 +               double tempdouble;
2620 +               int tempint;
2621 +               for(i=0; i<params.no_of_initiators-2; i++) {
2622 +                       for(j=i+1; j<params.no_of_initiators-2; j++) { 
2623 +                               if(sort_array[i].value < sort_array[j].value) {
2624 +                                       tempdouble = sort_array[j].value;
2625 +                                       tempint = sort_array[j].pos;
2626
2627 +                                       sort_array[j].value  = sort_array[i].value;
2628 +                                       sort_array[j].pos    = sort_array[i].pos;
2629 +
2630 +                                       sort_array[i].value = tempdouble;
2631 +                                       sort_array[i].pos   = tempint;
2632 +                               }
2633 +                       }
2634 +               }
2635 +
2636 +               for(i=0; i<6; i++)
2637 +               {
2638 +                       //HACK
2639 +                       bg_y[14+i*2] = sort_array[i].value*2;
2640 +                       sprintf(bg_text_list[13+i*2], "%02.1f%s", sort_array[i].value*100, "%");
2641 +                       sprintf(bg_text_list[14+i*2], "%s", (params.user_config_list[sort_array[i].pos].name)+8);
2642 +               }
2643 +
2644 +                bar_graph_plot(ctx, bg_y, (const char **)bg_text_list);
2645 +
2646 +               y[params.no_of_initiators]=y[0]+y[1];
2647 +               time_graph_plot(ctx, y, (const char **)text_list);
2648 +               //printf("Plotting the time_graph\n");
2649 +               memset(y, 0x0, sizeof(double)* (params.no_of_initiators+1));
2650 +       }
2651 +       statCountIdx++;
2652 +
2653 +    }
2654 +    
2655 +    mpu_handler(CLOSE);
2656 +
2657 +    printf("------------------------------------------------\n\n");
2658 +    printf("SUCCESS: Stat collection completed... Writing into file now\n");
2659 +    FILE *outfile = fopen("statcollector.csv", "w+");
2660 +    if (!outfile) {
2661 +        printf("\n ERROR: Error opening file");
2662 +    }
2663 +
2664 +    /* Ignore the first index at 0 */
2665 +    for(index=1; index<statCountIdx; index++) {
2666 +           for(i=0; i<params.no_of_initiators; i++) {
2667 +                   fprintf(outfile,"%s = %d,", params.user_config_list[i].name, global_object[params.user_config_list[i].id].readings[index]);
2668 +           }
2669 +           fprintf(outfile,"\n"); 
2670 +    }
2671 +    fclose(outfile);
2672 +
2673 +       time_graph_destroy(ctx);
2674 +    gettimeofday(&tv2, NULL);
2675 +    //printf("End time = %d\n", time(NULL));
2676 +    //printf("Time seconds = %d, usecs = %d\n", tv.tv_sec, tv.tv_usec);
2677 +    printf("Total execution time = %d secs, %d usecs\n\n", (tv2.tv_sec - tv1.tv_sec), (tv2.tv_usec - tv2.tv_usec));
2678 +
2679 +    return 0;
2680 +}
2681 +
2682 +
2683 diff --git a/clients/statcoll.h b/clients/statcoll.h
2684 new file mode 100644
2685 index 0000000..fa92753
2686 --- /dev/null
2687 +++ b/clients/statcoll.h
2688 @@ -0,0 +1,152 @@
2689 +#ifndef __STATCOLL_H 
2690 +#define __STATCOLL_H
2691
2692 +
2693 +#define CM_L3INSTR_REGISTER_BASE           (0x4A008000)
2694 +
2695 +#define CM_L3INSTR_L3INSTR_CLKSTCTRL_OFFSET     (0xE00)
2696 +#define CM_L3INSTR_L3_MAIN_2_CLKCTRL_OFFSET     (0xE20)
2697 +
2698 +#define STATCOLL_SIZE 40960
2699 +#define STATCOLL_BASE (0x45001000)
2700 +
2701 +#define stat_coll0_base_address (0x45001000)
2702 +#define stat_coll1_base_address (0x45002000)
2703 +#define stat_coll2_base_address (0x45003000)
2704 +#define stat_coll3_base_address (0x45004000)
2705 +#define stat_coll4_base_address (0x45005000)
2706 +#define stat_coll5_base_address (0x45006000)
2707 +#define stat_coll6_base_address (0x45007000)
2708 +#define stat_coll7_base_address (0x45008000)
2709 +#define stat_coll8_base_address (0x45009000)
2710 +#define stat_coll9_base_address (0x4500a000)
2711 +
2712 +#define printd(fmt, ...) \
2713 +       do { if (debug) fprintf(stderr, fmt, __VA_ARGS__); } while (0)
2714 +
2715 +typedef unsigned int UInt32;
2716 +
2717 +
2718 +typedef enum
2719 +{
2720 +    STATCOL_EMIF1_SYS,
2721 +    STATCOL_EMIF2_SYS,
2722 +    STATCOL_MA_MPU_P1,
2723 +    STATCOL_MA_MPU_P2,
2724 +    STATCOL_MPU1,
2725 +    STATCOL_MMU1,
2726 +    STATCOL_TPTC_RD1,
2727 +    STATCOL_TPTC_WR1,
2728 +    STATCOL_TPTC_RD2,
2729 +    STATCOL_TPTC_WR2,
2730 +    STATCOL_VIP1_P1,
2731 +    STATCOL_VIP1_P2,
2732 +    STATCOL_VIP2_P1,
2733 +    STATCOL_VIP2_P2,
2734 +    STATCOL_VIP3_P1,
2735 +    STATCOL_VIP3_P2,
2736 +    STATCOL_VPE_P1,
2737 +    STATCOL_VPE_P2,
2738 +    STATCOL_EVE1_TC0,
2739 +    STATCOL_EVE1_TC1,
2740 +    STATCOL_EVE2_TC0,
2741 +    STATCOL_EVE2_TC1,
2742 +    STATCOL_EVE3_TC0,
2743 +    STATCOL_EVE3_TC1,
2744 +    STATCOL_EVE4_TC0,
2745 +    STATCOL_EVE4_TC1,
2746 +    STATCOL_DSP1_MDMA,
2747 +    STATCOL_DSP1_EDMA,
2748 +    STATCOL_DSP2_MDMA,
2749 +    STATCOL_DSP2_EDMA,
2750 +    STATCOL_IVA,
2751 +    STATCOL_GPU_P1,
2752 +    STATCOL_GPU_P2,
2753 +    STATCOL_BB2D_P1,
2754 +    STATCOL_DSS,
2755 +    STATCOL_CSI2_2,
2756 +    STATCOL_MMU2,
2757 +    STATCOL_IPU1,
2758 +    STATCOL_IPU2,
2759 +    STATCOL_DMA_SYSTEM_RD,
2760 +    STATCOL_DMA_SYSTEM_WR,
2761 +    STATCOL_CSI2_1,
2762 +    STATCOL_USB3_SS,
2763 +    STATCOL_USB2_SS,
2764 +    STATCOL_USB2_ULPI_SS1,
2765 +    STATCOL_USB2_ULPI_SS2,
2766 +    STATCOL_PCIE_SS1,
2767 +    STATCOL_PCIE_SS2,
2768 +    STATCOL_DSP1_CFG,
2769 +    STATCOL_DSP2_CFG,
2770 +    STATCOL_GMAC_SW,
2771 +    STATCOL_PRUSS1_P1,
2772 +    STATCOL_PRUSS1_P2,
2773 +    STATCOL_PRUSS2_P1,
2774 +    STATCOL_PRUSS2_P2,
2775 +    STATCOL_DMA_CRYPTO_RD,
2776 +    STATCOL_DMA_CRYPTO_WR,
2777 +    STATCOL_MPU2,
2778 +    STATCOL_MMC1,
2779 +    STATCOL_MMC2,
2780 +    STATCOL_SATA,
2781 +    STATCOL_MLBSS,
2782 +    STATCOL_BB2D_P2,
2783 +    STATCOL_IEEE1500,
2784 +    STATCOL_DBG,
2785 +    STATCOL_VCP1,
2786 +    STATCOL_OCMC_RAM1,
2787 +    STATCOL_OCMC_RAM2,
2788 +    STATCOL_OCMC_RAM3,
2789 +    STATCOL_GPMC,
2790 +    STATCOL_MCASP1,
2791 +    STATCOL_MCASP2,
2792 +    STATCOL_MCASP3,
2793 +    STATCOL_VCP2,
2794 +    STATCOL_MAX
2795 +} STATCOL_ID;
2796 +
2797 +
2798 +
2799 +typedef struct
2800 +{
2801 +    UInt32 stat0_filter_cnt;
2802 +    UInt32 stat1_filter_cnt;
2803 +    UInt32 stat2_filter_cnt;
2804 +    UInt32 stat3_filter_cnt;
2805 +    UInt32 stat4_filter_cnt;
2806 +    UInt32 stat5_filter_cnt;
2807 +    UInt32 stat6_filter_cnt;
2808 +    UInt32 stat7_filter_cnt;
2809 +    UInt32 stat8_filter_cnt;
2810 +    UInt32 stat9_filter_cnt;
2811 +} StatCollectorObj;
2812
2813 +struct list_of_initiators
2814 +{
2815 +   STATCOL_ID id;
2816 +   char name[50];    
2817 +};
2818 +
2819 +typedef struct 
2820 +{
2821 +    UInt32 INTERVAL_US;
2822 +    UInt32 TOTAL_TIME;
2823 +    UInt32 no_of_initiators;
2824 +    struct list_of_initiators user_config_list[STATCOL_MAX];
2825 +} statcoll_params;
2826 +
2827 +typedef struct
2828 +{
2829 +    UInt32 b_enabled;
2830 +    char name[100];
2831 +    UInt32 *readings;
2832 +    UInt32 *timestamp;
2833 +    UInt32 group_id;
2834 +    UInt32 counter_id;
2835 +    UInt32 base_address;
2836 +    UInt32 mux_req;
2837 +}statcoll_initiators_object;
2838 +
2839 +
2840 +#endif
2841 diff --git a/clients/statcoll_gui.h b/clients/statcoll_gui.h
2842 new file mode 100644
2843 index 0000000..7362bde
2844 --- /dev/null
2845 +++ b/clients/statcoll_gui.h
2846 @@ -0,0 +1,101 @@
2847 +
2848 +/*
2849 +
2850 + ---------------------------------------------
2851 + |                                            |
2852 + |  ---------------------------------------   |
2853 + |                                            |
2854 + |                                            |
2855 + |                                            |
2856 + |                                            |
2857 + |                                            |
2858 + |                                            |
2859 + |                                            |
2860 + |                                            |
2861 + |                                            |
2862 + |                                            |
2863 + |                                            |
2864 + |                                            |
2865 + |                                            |
2866 + |                                            |
2867 + |                                            |
2868 + ---------------------------------------------
2869 + |           |                                |
2870 + |           |                                |
2871 + |           |                                |
2872 + |           |                                |
2873 + |           |                                |
2874 + |           |                                |
2875 + ---------------------------------------------
2876 +
2877 +
2878 +
2879 +
2880 +*/
2881 +#define POSITION_X 2800
2882 +#define POSITION_Y 40
2883 +
2884 +#define MAX_WIDTH  900
2885 +//#define MAX_WIDTH  528
2886 +#define MAX_HEIGHT 900
2887 +
2888 +/* Derived parameters */
2889 +#define BAR_GAP    (MAX_WIDTH/25)
2890 +#define BAR_WIDTH  (MAX_WIDTH/16)
2891 +
2892 +#define BAR_HEIGHT ((MX_HEIGHT/40) * 6)
2893 +
2894 +#define BORDER     (MAX_WIDTH/15)
2895 +
2896 +#define HEIGHT_EMIF_AREA (MAX_HEIGHT/4)
2897 +
2898 +#define FONT_SIZE (MAX_WIDTH/40)
2899 +
2900 +#define WIDTH_EMIF_AREA (MAX_WIDTH / 4)
2901 +
2902 +#define TOTAL_Y_PARAMETERS (25)
2903 +
2904 +#define TIME_GRAPH_AREA_BL_X (BORDER)
2905 +#define TIME_GRAPH_AREA_BL_Y (MAX_HEIGHT - HEIGHT_EMIF_AREA - BORDER)
2906 +#define TIME_GRAPH_AREA_TR_X (MAX_WIDTH - BORDER)
2907 +#define TIME_GRAPH_AREA_TR_Y (BORDER)
2908 +
2909 +#define EMIF_AREA_BL_X (0)
2910 +#define EMIF_AREA_BL_Y (MAX_HEIGHT)
2911 +#define EMIF_AREA_TR_X (WIDTH_EMIF_AREA)
2912 +#define EMIF_AREA_TR_Y (MAX_HEIGHT - HEIGHT_EMIF_AREA)
2913 +
2914 +#define INITIATORS_AREA_BL_X (WIDTH_EMIF_AREA)
2915 +#define INITIATORS_AREA_BL_Y (MAX_HEIGHT)
2916 +#define INITIATORS_AREA_TR_X (MAX_WIDTH)
2917 +#define INITIATORS_AREA_TR_Y (MAX_HEIGHT - HEIGHT_EMIF_AREA)
2918 +
2919 +
2920 +const char *string_list[TOTAL_Y_PARAMETERS] = {
2921 +        "----DDR BANDWIDTH PLOT----",
2922 +        "8 GBPS",
2923 +        "6.4 ",
2924 +        "4.8",
2925 +        "3.2",
2926 +        "1.6",
2927 +        "0",
2928 +        "EMIF Plot",
2929 +        "test",
2930 +        "EMIF1",
2931 +        "test",
2932 +        "EMIF2",
2933 +        "TOP 6 INITIATORS",
2934 +        "test",
2935 +        "MPU",
2936 +        "test",
2937 +        "DSS",
2938 +        "test",
2939 +        "DSP",
2940 +        "test",
2941 +        "IVA",
2942 +        "test",
2943 +        "GPU",
2944 +        "test",
2945 +        "BB2D",
2946 +};
2947 +
2948 diff --git a/clients/time_bar_graph.c b/clients/time_bar_graph.c
2949 new file mode 100644
2950 index 0000000..9fa9c12
2951 --- /dev/null
2952 +++ b/clients/time_bar_graph.c
2953 @@ -0,0 +1,515 @@
2954 +/*
2955 + * Copyright Â© 2008 Kristian Høgsberg
2956 + *
2957 + * Permission to use, copy, modify, distribute, and sell this software and its
2958 + * documentation for any purpose is hereby granted without fee, provided that
2959 + * the above copyright notice appear in all copies and that both that copyright
2960 + * notice and this permission notice appear in supporting documentation, and
2961 + * that the name of the copyright holders not be used in advertising or
2962 + * publicity pertaining to distribution of the software without specific,
2963 + * written prior permission.  The copyright holders make no representations
2964 + * about the suitability of this software for any purpose.  It is provided "as
2965 + * is" without express or implied warranty.
2966 + *
2967 + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
2968 + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
2969 + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
2970 + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
2971 + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
2972 + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
2973 + * OF THIS SOFTWARE.
2974 + */
2975 +
2976 +#include <stdint.h>
2977 +#include <stdio.h>
2978 +#include <stdlib.h>
2979 +#include <string.h>
2980 +#include <stdint.h>
2981 +#include <signal.h>
2982 +#include <time.h>
2983 +#include <math.h>
2984 +#include <cairo.h>
2985 +#include <sys/time.h>
2986 +#include <pthread.h>
2987 +#include <errno.h>
2988 +#include <unistd.h>
2989 +#include <sys/eventfd.h>
2990 +#include <sys/epoll.h>
2991 +
2992 +#include <linux/input.h>
2993 +#include <wayland-client.h>
2994 +#include "window.h"
2995 +#include "../shared/cairo-util.h"
2996 +#include "time_bar_graph.h"
2997 +
2998 +//#define DEBUG 1
2999 +#ifdef DEBUG 
3000 +#define DBG(x...) printf(x)
3001 +#else
3002 +#define DBG(x...) // printf(x)
3003 +#endif
3004 +
3005 +#define MAX_ITEMS        180
3006 +#define MAX_TEXT_SIZE    128
3007 +
3008 +struct graph_dataset_point {
3009 +       int next_index;
3010 +       double y_values[MAX_ITEMS];
3011 +};
3012 +
3013 +struct graph_data {
3014 +       int dataset_size;
3015 +       int first_index, last_index, num_elems;
3016 +       uint64_t last_time;
3017 +       struct graph_dataset_point dataset[1];
3018 +};
3019 +
3020 +struct graph {
3021 +       struct display *display;
3022 +       struct window *window;
3023 +       struct widget *widget;
3024 +       int width, height;
3025 +       struct time_graph_create_params params;
3026 +       struct bar_graph_create_params bar_graph_params;
3027 +       struct _y_config y_config_array[MAX_ITEMS];
3028 +       struct _text_config text_config_array[MAX_ITEMS];
3029 +
3030 +       /* Bar graph parameters */
3031 +       struct _bar_graph_y_config bar_graph_y_config_array[MAX_ITEMS];
3032 +       struct _text_config bar_graph_text_config_array[MAX_ITEMS];
3033 +
3034 +       pthread_t thr;
3035 +       int eventfd;
3036 +       struct task task;
3037 +       double x_scaling_factor;
3038 +       pthread_mutex_t mtx;
3039 +       double time_graph_y_values[MAX_ITEMS];
3040 +       char text_values[MAX_ITEMS][MAX_TEXT_SIZE];
3041 +
3042 +       double bar_graph_y_values[MAX_ITEMS];
3043 +       char bar_graph_text_values[MAX_ITEMS][MAX_TEXT_SIZE];
3044 +
3045 +       uint64_t time_now;
3046 +       time_t start_time_tv_sec;
3047 +       struct graph_data *data;
3048 +};
3049 +
3050 +struct graph *global_graph=NULL;
3051 +static void
3052 +draw_stuff(struct graph *g, cairo_surface_t *surface)
3053 +{
3054 +       cairo_t *cr;
3055 +       int i, j, n_elems;
3056 +       double c_x, c_y, d_x, d_y;
3057 +
3058 +       cr = cairo_create(surface);
3059 +       cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
3060 +       cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.5);
3061 +       cairo_paint(cr);
3062 +       cairo_select_font_face(cr, "mono",
3063 +                       CAIRO_FONT_SLANT_NORMAL,
3064 +                       CAIRO_FONT_WEIGHT_BOLD);
3065 +       cairo_set_line_width (cr, 1.0);
3066 +       cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
3067 +       pthread_mutex_lock(&g->mtx);
3068 +       for (j=0; g->data->num_elems > 0 && j<g->params.num_of_y_items; j++) {
3069 +               n_elems = g->data->num_elems;
3070 +               DBG("first_index: %d, last_index: %d\n", g->data->first_index, g->data->last_index);
3071 +               if (g->y_config_array[j].fill_color.a != 0.0)
3072 +                       cairo_move_to(cr, (double)g->params.draw_area.bottom_left.x, (double)g->params.draw_area.bottom_left.y);
3073 +               c_x = (double)g->params.draw_area.bottom_left.x;
3074 +               c_y = (double)g->params.draw_area.bottom_left.y;
3075 +               d_x = 0;
3076 +               i = g->data->first_index;
3077 +               while (n_elems) {
3078 +                       DBG("index: %d, x: %f, y: %f, next_index: %d\n", i, c_x,
3079 +                               g->data->dataset[i].y_values[j], g->data->dataset[i].next_index);
3080 +                       d_y = g->data->dataset[i].y_values[j] - c_y;
3081 +                       c_y = g->data->dataset[i].y_values[j];
3082 +                       c_x = c_x + d_x;
3083 +                       if (g->y_config_array[j].fill_color.a == 0.0 && n_elems == g->data->num_elems) {
3084 +                               cairo_move_to(cr, c_x, c_y);
3085 +                       } else {
3086 +                               cairo_curve_to(cr, c_x - (d_x * 0.75), c_y - (d_y * 0.92), c_x - (d_x * 0.25), c_y - (d_y * 0.08), c_x, c_y);
3087 +                       }
3088 +                       if (g->data->dataset[i].next_index > i) {
3089 +                               d_x = (g->data->dataset[i].next_index - i);
3090 +                       } else {
3091 +                               d_x = (g->data->dataset_size + g->data->dataset[i].next_index - i);
3092 +                       }
3093 +                       i = g->data->dataset[i].next_index;
3094 +                       n_elems--;
3095 +               }
3096 +               if (g->y_config_array[j].fill_color.a != 0.0) {
3097 +                       cairo_line_to(cr, c_x, (double)g->params.draw_area.bottom_left.y);
3098 +                       cairo_line_to(cr, (double)g->params.draw_area.bottom_left.x, (double)g->params.draw_area.bottom_left.y);
3099 +                       cairo_close_path(cr);
3100 +                       cairo_set_source_rgba(cr, g->y_config_array[j].fill_color.r, g->y_config_array[j].fill_color.g, 
3101 +                                       g->y_config_array[j].fill_color.b, g->y_config_array[j].fill_color.a);
3102 +                       cairo_fill_preserve(cr);
3103 +               }
3104 +               cairo_set_source_rgba(cr, g->y_config_array[j].line_color.r, g->y_config_array[j].line_color.g, 
3105 +                       g->y_config_array[j].line_color.b, g->y_config_array[j].line_color.a);
3106 +               cairo_stroke(cr);
3107 +       }
3108 +
3109 +       for (j=0; j<g->params.num_of_text_items; j++) {
3110 +               cairo_move_to(cr, (double)g->text_config_array[j].at.x, (double)g->text_config_array[j].at.y);
3111 +               cairo_set_font_size(cr, g->text_config_array[j].fontsize);
3112 +               cairo_set_source_rgba(cr, g->text_config_array[j].color.r, g->text_config_array[j].color.g, 
3113 +                               g->text_config_array[j].color.b, g->text_config_array[j].color.a);
3114 +               cairo_show_text(cr, g->text_values[j]);
3115 +       }
3116 +
3117 +       
3118 +       for (j=0; j<g->bar_graph_params.num_of_y_items; j++) {
3119 +               cairo_move_to(cr, (double)g->bar_graph_params.y_config_array[j].region.bottom_left.x,
3120 +                       (double)g->bar_graph_params.y_config_array[j].region.bottom_left.y);
3121 +               c_y = (double)g->bar_graph_params.y_config_array[j].region.bottom_left.y -
3122 +                   (g->bar_graph_y_values[j] * (double)(g->bar_graph_params.y_config_array[j].region.bottom_left.y -
3123 +                       g->bar_graph_params.y_config_array[j].region.top_right.y));
3124 +               cairo_line_to(cr, (double)g->bar_graph_params.y_config_array[j].region.bottom_left.x, c_y);
3125 +               cairo_line_to(cr, (double)g->bar_graph_params.y_config_array[j].region.top_right.x, c_y);
3126 +               cairo_line_to(cr, (double)g->bar_graph_params.y_config_array[j].region.top_right.x,
3127 +                       (double)g->bar_graph_params.y_config_array[j].region.bottom_left.y);
3128 +               cairo_line_to(cr, (double)g->bar_graph_params.y_config_array[j].region.bottom_left.x,
3129 +                       (double)g->bar_graph_params.y_config_array[j].region.bottom_left.y);
3130 +               cairo_close_path(cr);
3131 +               cairo_set_source_rgba(cr, g->bar_graph_y_config_array[j].fill_color.r, g->bar_graph_y_config_array[j].fill_color.g, 
3132 +                               g->bar_graph_y_config_array[j].fill_color.b, g->bar_graph_y_config_array[j].fill_color.a);
3133 +               cairo_fill_preserve(cr);
3134 +               cairo_set_source_rgba(cr, g->bar_graph_y_config_array[j].line_color.r, g->bar_graph_y_config_array[j].line_color.g, 
3135 +                       g->bar_graph_y_config_array[j].line_color.b, g->bar_graph_y_config_array[j].line_color.a);
3136 +               cairo_stroke(cr);
3137 +       }
3138 +       for (j=0; j<g->bar_graph_params.num_of_text_items; j++) {
3139 +               cairo_move_to(cr, (double)g->bar_graph_text_config_array[j].at.x, (double)g->bar_graph_text_config_array[j].at.y);
3140 +               cairo_set_font_size(cr, g->bar_graph_text_config_array[j].fontsize);
3141 +               cairo_set_source_rgba(cr, g->bar_graph_text_config_array[j].color.r, g->bar_graph_text_config_array[j].color.g, 
3142 +                               g->bar_graph_text_config_array[j].color.b, g->bar_graph_text_config_array[j].color.a);
3143 +                cairo_save (cr);
3144 +               //cairo_rotate(cr, 2*3.14*21/24);
3145 +               cairo_show_text(cr, g->bar_graph_text_values[j]);
3146 +               cairo_restore(cr);
3147 +       }
3148 +       pthread_mutex_unlock(&g->mtx);
3149 +       cairo_destroy(cr);
3150 +}
3151 +
3152 +static void
3153 +resize_handler(struct widget *widget,
3154 +              int32_t width, int32_t height, void *data)
3155 +{
3156 +       struct graph *g = data;
3157 +
3158 +       /* Dont resize me */
3159 +       widget_set_size(g->widget, g->width, g->height);
3160 +}
3161 +
3162 +static void
3163 +redraw_handler(struct widget *widget, void *data)
3164 +{
3165 +       struct graph *g = data;
3166 +       cairo_surface_t *surface;
3167 +
3168 +       surface = window_get_surface(g->window);
3169 +       if (surface == NULL ||
3170 +           cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
3171 +               fprintf(stderr, "failed to create cairo egl surface\n");
3172 +               return;
3173 +       }
3174 +
3175 +       draw_stuff(g, surface);
3176 +       cairo_surface_destroy(surface);
3177 +}
3178 +
3179 +static void
3180 +button_handler(struct widget *widget,
3181 +              struct input *input, uint32_t time,
3182 +              uint32_t button, enum wl_pointer_button_state state, void *data)
3183 +{
3184 +       struct graph *g = data;
3185 +
3186 +       switch (button) {
3187 +       case BTN_LEFT:
3188 +               if (state == WL_POINTER_BUTTON_STATE_PRESSED)
3189 +                       window_move(g->window, input,
3190 +                                   display_get_serial(g->display));
3191 +               break;
3192 +       case BTN_MIDDLE:
3193 +               if (state == WL_POINTER_BUTTON_STATE_PRESSED)
3194 +                       widget_schedule_redraw(widget);
3195 +               break;
3196 +       case BTN_RIGHT:
3197 +               if (state == WL_POINTER_BUTTON_STATE_PRESSED)
3198 +                       window_show_frame_menu(g->window, input, time);
3199 +               break;
3200 +       }
3201 +}
3202 +
3203 +static void
3204 +touch_down_handler(struct widget *widget, struct input *input, 
3205 +                  uint32_t serial, uint32_t time, int32_t id, 
3206 +                  float x, float y, void *data)
3207 +{
3208 +       struct graph *g = data;
3209 +       window_move(g->window, input, display_get_serial(g->display));
3210 +}
3211 +
3212 +static void task_run(struct task *task, uint32_t events)
3213 +{
3214 +       eventfd_t e;
3215 +       struct graph *g = (struct graph *)(task->link.prev);
3216 +       uint64_t time_diff;
3217 +       int elems, tmp, incr, i;
3218 +       double y;
3219 +
3220 +       eventfd_read(g->eventfd, &e);
3221 +       if(e == 1) {
3222 +               pthread_mutex_lock(&g->mtx);
3223 +               /* Process new data */
3224 +               DBG("time_now: %llu, last_time: %llu\n", g->time_now, g->data->last_time);
3225 +               if (g->time_now > g->data->last_time) {
3226 +                       time_diff = g->time_now - g->data->last_time;
3227 +                       y = (double)time_diff * g->x_scaling_factor;
3228 +                       incr = (int)y;
3229 +                       DBG("incr: %d\n", incr);
3230 +
3231 +                       if (g->data->last_index >= g->data->first_index) elems = g->data->last_index - g->data->first_index + 1;
3232 +                       else elems = g->data->dataset_size - g->data->first_index + g->data->last_index + 1;
3233 +                       /* Move first index to make room for new element */
3234 +                       while (g->data->dataset_size > 0 && (elems + incr) > g->data->dataset_size) {
3235 +                               tmp = g->data->dataset[g->data->first_index].next_index - g->data->first_index;
3236 +                               if (tmp < 0) tmp = g->data->dataset_size + tmp;
3237 +                               g->data->first_index = g->data->dataset[g->data->first_index].next_index;
3238 +                               elems -= tmp;
3239 +                               g->data->num_elems--;
3240 +                       }
3241 +                       for (i=0; i<g->params.num_of_y_items; i++) {
3242 +                               /* Scale Y */
3243 +                               y = g->time_graph_y_values[i] * (double)(g->params.draw_area.bottom_left.y-g->params.draw_area.top_right.y);
3244 +                               y = (double)g->params.draw_area.bottom_left.y - y;
3245 +                               g->data->dataset[g->data->last_index].y_values[i] = y;
3246 +                       }
3247 +                       g->data->dataset[g->data->last_index].next_index = g->data->last_index + incr;
3248 +                       if (g->data->dataset[g->data->last_index].next_index >= g->data->dataset_size) 
3249 +                               g->data->dataset[g->data->last_index].next_index -= g->data->dataset_size;
3250 +                       g->data->num_elems++;
3251 +                       g->data->last_index = g->data->dataset[g->data->last_index].next_index;
3252 +                       g->data->last_time = g->time_now;
3253 +               }
3254 +               pthread_mutex_unlock(&g->mtx);
3255 +       }
3256 +       widget_schedule_redraw(g->widget);
3257 +       DBG("event task ran...\n");
3258 +}
3259 +
3260 +void *time_graph_create(int argc, char *argv[], struct time_graph_create_params *cp)
3261 +{
3262 +       struct graph *g;
3263 +       struct display *d;
3264 +       int dataset_size;
3265 +       struct timeval tv;
3266 +
3267 +       if (cp->num_of_y_items > MAX_ITEMS) return NULL;
3268 +       if (cp->num_of_text_items > MAX_ITEMS) return NULL;
3269 +
3270 +       g = (struct graph*)malloc(sizeof(struct graph));
3271 +       if (g == NULL) {
3272 +               fprintf(stderr, "failed to allocate memory\n");
3273 +               return NULL;
3274 +       }
3275 +       global_graph = g;
3276 +       g->params = *cp;
3277 +       if (cp->num_of_y_items)
3278 +               memcpy(&g->y_config_array[0], cp->y_config_array,
3279 +                       sizeof(struct _y_config) * cp->num_of_y_items);
3280 +       if (cp->num_of_text_items)
3281 +               memcpy(&g->text_config_array[0], cp->text_config_array,
3282 +                       sizeof(struct _text_config) * cp->num_of_text_items);
3283 +       d = display_create(&argc, argv);
3284 +       if (d == NULL) {
3285 +               fprintf(stderr, "failed to create display: %m\n");
3286 +               return NULL;
3287 +       }
3288 +       g->display = d;
3289 +       //g->bg_image = load_cairo_surface(cp->bg_image);
3290 +       g->width = cp->width; //cairo_image_surface_get_width(g->bg_image);
3291 +       g->height = cp->height; //cairo_image_surface_get_height(g->bg_image);
3292 +       dataset_size = cp->draw_area.top_right.x - cp->draw_area.bottom_left.x;
3293 +       g->data = (struct graph_data *)malloc(sizeof(struct graph_data) +
3294 +               (dataset_size * sizeof(struct graph_dataset_point)));
3295 +       if (!g->data) {
3296 +               fprintf(stderr, "failed to allocate memory\n");
3297 +               display_destroy(g->display);
3298 +               //cairo_surface_destroy(g->bg_image);
3299 +               free(g);
3300 +               return NULL;
3301 +       }
3302 +       g->data->first_index = 0;
3303 +       g->data->last_index = 0;
3304 +       g->data->num_elems = 0;
3305 +       g->data->dataset_size = dataset_size;
3306 +       g->x_scaling_factor = (double)dataset_size / (double)cp->time_span;
3307 +       g->window = window_create(d);
3308 +       g->widget = window_add_widget(g->window, g);
3309 +       window_set_title(g->window, cp->title);
3310 +       widget_set_resize_handler(g->widget, resize_handler);
3311 +       widget_set_redraw_handler(g->widget, redraw_handler);
3312 +       widget_set_button_handler(g->widget, button_handler);
3313 +       widget_set_default_cursor(g->widget, CURSOR_HAND1);
3314 +       widget_set_touch_down_handler(g->widget, touch_down_handler);
3315 +       window_schedule_resize(g->window, g->width, g->height);
3316 +       g->eventfd = eventfd(0, 0);
3317 +       g->task.run = task_run;
3318 +       g->task.link.prev = (struct wl_list*)g;
3319 +       g->task.link.next = NULL;
3320 +       display_watch_fd(d, g->eventfd, EPOLLIN, &g->task);
3321 +       pthread_mutex_init(&g->mtx, NULL);
3322 +
3323 +       if (0 != pthread_create(&g->thr, NULL, (void *(*)(void *))display_run, (void *)d)) {
3324 +               fprintf(stderr, "pthread_create failed: %m\n");
3325 +               widget_destroy(g->widget);
3326 +               window_destroy(g->window);
3327 +               display_destroy(g->display);
3328 +               //cairo_surface_destroy(g->bg_image);
3329 +               free(g->data);
3330 +               close(g->eventfd);
3331 +               free(g);
3332 +               return NULL;
3333 +       }
3334 +       gettimeofday(&tv, NULL);
3335 +       g->start_time_tv_sec = tv.tv_sec;
3336 +       g->data->last_time = 0;
3337 +       return (void*)g;
3338 +}
3339 +
3340 +void move_graph(void *ctx, struct time_graph_create_params *cp)
3341 +{
3342 +       struct graph *g = ctx;
3343 +       window_set_title(g->window, cp->title);
3344 +}
3345 +
3346 +void time_graph_plot(void *ctx, double *y_values, const char *text_values[])
3347 +{
3348 +       struct timeval tv;
3349 +       struct graph *g = ctx;
3350 +       int i;
3351 +       pthread_mutex_lock(&g->mtx);
3352 +       gettimeofday(&tv, NULL);
3353 +       g->time_now = ((tv.tv_sec - g->start_time_tv_sec) * 1000) + (tv.tv_usec / 1000);
3354 +       memcpy(g->time_graph_y_values, y_values, g->params.num_of_y_items * sizeof(double));
3355 +       for (i=0;i<g->params.num_of_text_items; i++) {
3356 +               strncpy(g->text_values[i], text_values[i], MAX_TEXT_SIZE);
3357 +               g->text_values[i][MAX_TEXT_SIZE-1] = '\0';
3358 +       }
3359 +       pthread_mutex_unlock(&g->mtx);
3360 +       eventfd_write(g->eventfd, (eventfd_t)1);
3361 +}
3362 +
3363 +void time_graph_destroy(void *ctx)
3364 +{
3365 +       struct graph *g = (struct graph *)ctx;
3366 +       display_exit(g->display);
3367 +       eventfd_write(g->eventfd, (eventfd_t)1);
3368 +       pthread_join(g->thr, NULL);
3369 +       widget_destroy(g->widget);
3370 +       window_destroy(g->window);
3371 +       display_destroy(g->display);
3372 +       free(g->data);
3373 +       close(g->eventfd);
3374 +       free(g);
3375 +       global_graph=NULL;
3376 +}
3377 +
3378 +void util_get_cpu_usage(double *cpu_usage)
3379 +{
3380 +       static FILE *fp = NULL;
3381 +       char buf[256];
3382 +       uint64_t tot;
3383 +       uint64_t u, n, s, i, w, x, y, z;
3384 +       static uint64_t last_i = 0, last_total = 0;
3385 +
3386 +
3387 +       if (!fp) {
3388 +               if (!(fp = fopen("/proc/stat", "r")))
3389 +                       fprintf(stderr, "Failed /proc/stat open: %s", strerror(errno));
3390 +       }
3391 +       if (fp) {
3392 +               while (1) {
3393 +                       rewind(fp);
3394 +                       fflush(fp);
3395 +                       if (!fgets(buf, sizeof(buf), fp)) {
3396 +                               fprintf(stderr, "failed /proc/stat read\n");
3397 +                       } else {
3398 +                               sscanf(buf, "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu",
3399 +                                               &u,
3400 +                                               &n,
3401 +                                               &s,
3402 +                                               &i,
3403 +                                               &w,
3404 +                                               &x,
3405 +                                               &y,
3406 +                                               &z
3407 +                                         );
3408 +                               if (last_total == 0) {
3409 +                                       last_total = u+n+s+i+w+x+y+z;
3410 +                                       last_i = i;
3411 +                                       usleep(100000);
3412 +                               } else {
3413 +                                       tot = u+n+s+i+w+x+y+z;
3414 +                                       *cpu_usage = (1.0 - ((double)(i-last_i)/(double)(tot-last_total)));
3415 +                                       last_i = i;
3416 +                                       last_total = tot;
3417 +                                       break;
3418 +                               }
3419 +                       }
3420 +               }
3421 +       }
3422 +}
3423 +
3424 +void *bar_graph_create(int argc, char *argv[], struct bar_graph_create_params *cp)
3425 +{
3426 +       struct graph *g;
3427 +       struct display *d;
3428 +       struct timeval tv;
3429 +
3430 +       if (cp->num_of_y_items > MAX_ITEMS) return NULL;
3431 +       if (cp->num_of_text_items > MAX_ITEMS) return NULL;
3432 +
3433 +       if (global_graph == NULL) {
3434 +               fprintf(stderr, "graph not initialized invoke time_graph_create first\n");
3435 +               return NULL;
3436 +       }
3437 +       g=global_graph;
3438 +       g->bar_graph_params = *cp;
3439 +       if (cp->num_of_y_items)
3440 +               memcpy(&g->bar_graph_y_config_array[0], cp->y_config_array,
3441 +                       sizeof(struct _bar_graph_y_config) * cp->num_of_y_items);
3442 +       if (cp->num_of_text_items)
3443 +               memcpy(&g->bar_graph_text_config_array[0], cp->text_config_array,
3444 +                       sizeof(struct _text_config) * cp->num_of_text_items);
3445 +
3446 +       return g;
3447 +}
3448 +
3449 +void bar_graph_plot(void *ctx, double *y_values, const char *text_values[])
3450 +{
3451 +       struct graph *g = ctx;
3452 +       int i;
3453 +       pthread_mutex_lock(&g->mtx);
3454 +       memcpy(g->bar_graph_y_values, y_values, g->bar_graph_params.num_of_y_items * sizeof(double));
3455 +       for (i=0;i<g->bar_graph_params.num_of_text_items; i++) {
3456 +               strncpy(g->bar_graph_text_values[i], text_values[i], MAX_TEXT_SIZE);
3457 +               g->bar_graph_text_values[i][MAX_TEXT_SIZE-1] = '\0';
3458 +       }
3459 +       pthread_mutex_unlock(&g->mtx);
3460 +       //eventfd_write(g->eventfd, (eventfd_t)2);
3461 +}
3462 +
3463 +void bar_graph_destroy(void *ctx)
3464 +{
3465 +       printf("Nothing to be done for this call\n");
3466 +       return;
3467 +}
3468 +
3469 diff --git a/clients/time_bar_graph.h b/clients/time_bar_graph.h
3470 new file mode 100644
3471 index 0000000..97ac05a
3472 --- /dev/null
3473 +++ b/clients/time_bar_graph.h
3474 @@ -0,0 +1,93 @@
3475 +
3476 +#ifndef _BAR_GRAPH_H_
3477 +#define _BAR_GRAPH_H_
3478 +
3479 +#include <stdint.h>
3480 +
3481 +struct _rgba {
3482 +       double r, g, b, a; // Values between 0 and 1
3483 +};
3484 +
3485 +struct _coordinate {
3486 +       uint32_t x, y; // Co-ordinates relative to top-left of the window
3487 +};
3488 +
3489 +struct _rect {
3490 +       struct _coordinate bottom_left, top_right;
3491 +};
3492 +
3493 +struct _y_config {
3494 +       struct _rgba line_color; // Line color
3495 +       struct _rgba fill_color; // Fill color, 0 alpha => no fill
3496 +};
3497 +
3498 +struct _text_config {
3499 +       struct _rgba color; // Color for drawing the text, RGBA
3500 +       struct _coordinate at; // where to draw the text
3501 +       int fontsize;         // Font size
3502 +};
3503 +
3504 +struct time_graph_create_params {
3505 +       char *title;
3506 +       //const char *bg_image;
3507 +       uint32_t width;
3508 +       uint32_t height;
3509 +       struct _rect draw_area;
3510 +       uint32_t time_span; // Amount of time the graph has to span in milliseconds
3511 +       uint32_t num_of_y_items;
3512 +       struct _y_config *y_config_array;
3513 +       uint32_t num_of_text_items;
3514 +       struct _text_config *text_config_array;
3515 +};
3516 +
3517 +
3518 +struct _bar_graph_y_config {
3519 +       struct _rect region;     // Region for the bar graph
3520 +       struct _rgba line_color; // Color for drawing the line, RGBA
3521 +       struct _rgba fill_color; // Fill under the line with color RGBA, 0 => no fill
3522 +};
3523 +
3524 +struct bar_graph_create_params {
3525 +       char *title;
3526 +       //const char *bg_image;
3527 +       uint32_t num_of_y_items;
3528 +       struct _bar_graph_y_config *y_config_array;
3529 +       uint32_t num_of_text_items;
3530 +       struct _text_config *text_config_array;
3531 +};
3532 +
3533 +/* Creates a time graph using create parameters */
3534 +void *bar_graph_create(int argc, char *argv[], struct bar_graph_create_params *cp);
3535 +
3536 +void move_graph(void *ctx, struct time_graph_create_params *cp);
3537 +
3538 +/* Plots a new set of y-values from the values in the array y_values. 
3539 +   The number of values must be equal to "num_of_y_items" from create params 
3540 +   y_values must be normalized between 0.0 to 1.0
3541 +*/
3542 +void bar_graph_plot(void *ctx, double *y_values, const char *text_values[]);
3543 +
3544 +/* Destroy the graph */
3545 +void bar_graph_destroy(void *ctx);
3546 +
3547 +
3548 +/* Creates a time graph using create parameters */
3549 +void *time_graph_create(int argc, char *argv[], struct time_graph_create_params *cp);
3550 +
3551 +/* 
3552 + * Plots a new set of points from the values in the array y_values. 
3553 + * The number of values in the array y_values must be equal to "num_of_y_items"
3554 + * from create params 
3555 + * y_values must be normalized between 0.0 to 1.0
3556 +
3557 + * The number of values in the array text_values must be equal to "num_of_text_items"
3558 + * from create params 
3559 +*/
3560 +void time_graph_plot(void *ctx, double *y_values, const char *text_values[]);
3561 +
3562 +/* Destroy the graph */
3563 +void time_graph_destroy(void *ctx);
3564 +
3565 +void util_get_cpu_usage(double *cpu_usage);
3566 +
3567 +#endif /* _BAR_GRAPH_H_ */
3568 -- 
3569 1.9.1
3570