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