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
6 Signed-off-by: Karthik Ramanan <a0393906@ti.com>
9 clients/Dra7xx_ddrstat_speed.c | 494 +++++++++++++
10 clients/soc_performance_monitor.c | 630 ++++++++++++++++
11 clients/soc_performance_monitor.h | 40 ++
12 clients/statcoll.c | 1433 +++++++++++++++++++++++++++++++++++++
13 clients/statcoll.h | 152 ++++
14 clients/statcoll_gui.h | 101 +++
15 clients/time_bar_graph.c | 515 +++++++++++++
16 clients/time_bar_graph.h | 93 +++
17 10 files changed, 4873 insertions(+), 1 deletion(-)
18 create mode 100644 clients/Dra7xx_ddrstat_speed.c
19 create mode 100644 clients/soc_performance_monitor.c
20 create mode 100644 clients/soc_performance_monitor.h
21 create mode 100644 clients/statcoll.c
22 create mode 100644 clients/statcoll.h
23 create mode 100644 clients/statcoll_gui.h
24 create mode 100644 clients/time_bar_graph.c
25 create mode 100644 clients/time_bar_graph.h
27 diff --git a/Makefile.am b/Makefile.am
28 index 62719c9..55aed6d 100644
31 @@ -432,7 +432,9 @@ demo_clients = \
37 + soc-performance-monitor \
38 + soc-ddr-bw-visualizer
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)
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)
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)
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)
59 weston_cliptest_SOURCES = \
61 src/vertex-clipping.c \
62 diff --git a/clients/Dra7xx_ddrstat_speed.c b/clients/Dra7xx_ddrstat_speed.c
64 index 0000000..af06733
66 +++ b/clients/Dra7xx_ddrstat_speed.c
69 + * Copyright (C) 2015 Texas Instruments
70 + * Author: Karthik Ramanan <karthik.ramanan@ti.com>
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.
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
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/>.
89 +#include <sys/mman.h>
90 +#include <sys/time.h>
93 +#include "statcoll.h"
95 +#define PAGE_SIZE 4096
97 +#define EMIF1_BASE 0x4c000000
98 +#define EMIF2_BASE 0x4d000000
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
106 +tv_diff(struct timeval *tv1, struct timeval *tv2)
108 + return (tv2->tv_sec - tv1->tv_sec) * 1000000 +
109 + (tv2->tv_usec - tv1->tv_usec);
118 +static const struct emif_perf emif_perf_tab[] = {
124 + { 5, "fifo_write" },
125 + { 6, "fifo_read" },
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;
139 +static int STATCOLL=0;
140 +static int TOTAL_TIME;
141 +static int INTERVAL_US;
143 +struct timeval t1, t2;
152 +static struct emif_stats emif1_start, emif1_end;
153 +static struct emif_stats emif2_start, emif2_end;
155 +static void *emif_init(int fd, unsigned base)
158 + mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, base);
159 + volatile uint32_t *emif = mem,temp;
161 + if (mem == MAP_FAILED){
165 + emif[EMIF_PERF_CNT_CFG>>2] = EMIF_PERF_CFG2 << 16 | EMIF_PERF_CFG1;
170 +static void emif_read(volatile uint32_t *emif, struct emif_stats *st)
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];
177 +static void emif_print(const char *tag, struct emif_stats *st1,
178 + struct emif_stats *st2)
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);
191 +static int perf_init(void)
193 + int fd = open("/dev/mem", O_RDWR);
197 + printf("error fd=open() \n");
200 + emif1 = emif_init(fd, EMIF1_BASE);
201 + emif2 = emif_init(fd, EMIF2_BASE);
203 + if (!emif1 || !emif2){
204 + printf("error if (!emif1 || !emif2) \n");
212 +static void perf_start(void)
215 + emif_read(emif1, &emif1_start);
216 + emif_read(emif2, &emif2_start);
220 +static void perf_stop(void)
223 + emif_read(emif1, &emif1_end);
224 + emif_read(emif2, &emif2_end);
228 +static void perf_print(void)
231 + emif_print("EMIF1", &emif1_start, &emif1_end);
233 + emif_print("EMIF2", &emif2_start, &emif2_end);
235 + fprintf(outfile, "\n");
241 +static void perf_close(void)
243 + if (emif1) munmap(emif1, PAGE_SIZE);
244 + if (emif2) munmap(emif2, PAGE_SIZE);
247 +static int get_cfg(const char *name, int def)
250 + int n = strtol(name, &end, 0);
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;
264 +unsigned int emif_freq()
266 + volatile unsigned *tim1;
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*/
276 + fd = open("/dev/mem", O_RDONLY);
278 + perror("/dev/mem");
283 + mem = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, fd, EMIF1_BASE);
284 + if (mem == MAP_FAILED) {
289 + tim1 = (unsigned *)((char*)mem + EMIF_PERF_CNT_TIM);
292 + gettimeofday(&t1, NULL);
295 + gettimeofday(&t2, NULL);
297 + munmap(mem, PAGE_SIZE);
300 + return (v2 - v1) / tv_diff(&t1, &t2);
305 +char config_file_path[100];
306 +char keylist[][50] = {
318 +char tokens[6][512];
320 +char *keyvalue, *pair;
327 +void print_valid_options(void)
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]);
336 +int validatekey(char *ptr)
339 + for(i=0; i<sizeof(keylist)/sizeof(keylist[0]); i++)
340 + if(strcmp(ptr, keylist[i]) == 0)
346 +void add_key_value(char *key, int value)
348 + printd("%s", "Inside add_key_value\n");
350 + if(strcmp(key, "BANDWIDTH") == 0) {
354 + if(strcmp(key, "STATCOLL") == 0) {
359 + printd("%s", "********** UNKNOWN**********");
361 + if(BANDWIDTH == 1) {
362 + if(strcmp(key, "DELAY") == 0)
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;
370 + printf("NOTE: BANDWIDTH is not enabled, ignoring %s\n", key);
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;
380 + printf("NOTE: STATCOLL is not enabled, ignoring %s\n", key);
383 +void bandwidth_usage() {
385 + printf("#########################################################\n##\n"
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"
394 + "## 4 -> fifo_cmd,\n"
395 + "## 5 -> fifo_write,\n"
396 + "## 6 -> fifo_read,\n"
397 + "## 7 -> fifo_ret,\n"
399 + "## 9 -> cmd_pend,\n"
400 + "## 10 -> data \n##\n"
402 + "## EMIF frq : %d MHz\n\n", emif_freq() );
406 +int main(int argc, char **argv)
411 + int xpos = 600, ypos = 40;
414 + /* Read config file */
415 + /* Initialize this to turn off verbosity of getopt */
418 +// while ((option = getopt (argc, argv, "df:")) != -1)
419 + while ((option = getopt (argc, argv, "dx:y:")) != -1)
425 + strcpy(config_file_path, optarg);
439 + printf("Invalid option.. Exiting\n");
444 + printf("xpos = %d, ypos = %d\n", xpos, ypos);
446 + strcpy(config_file_path,"config.ini");
447 + fp = fopen(config_file_path, "r");
449 + fprintf(stderr, "couldn't open the specified file\n");
453 + while (fgets(line, sizeof line, fp)) {
454 + printd("Line is = %s", line);
456 + if (line[0] == '#' || line[0] == '\n') {
460 + memset(tokens, 0, sizeof(tokens));
463 + pair = strtok (line," ,");
464 + while (pair != NULL)
466 + printd ("\tPair is = %s\n",pair);
467 + strcpy(tokens[i++], pair);
468 + pair = strtok (NULL, " ,.-");
471 + for(temp=0; temp< i; temp++)
473 + printd("Line %d: %s\n", temp, tokens[temp]);
475 + keyvalue = strtok (tokens[temp]," =");
476 + while (keyvalue != NULL)
480 + if(validatekey(keyvalue))
482 + print_valid_options();
485 + strcpy(key, keyvalue);
486 + printd ("\tKey is = %s\n",key);
491 + printd ("\tValue is = %s",keyvalue);
492 + printd (" (%d)\n", atoi(keyvalue));
493 + add_key_value(key, atoi(keyvalue));
496 + keyvalue = strtok (NULL, " =");
503 + printd("%s", "------------------- \n");
509 + printf("\n\nCOMPLETED: Parsing of the user specified parameters.. \n \
510 + \nConfiguring device now.. \n\n");
511 + if(BANDWIDTH == 1) {
517 + printf("perf_init return non zero \n");
521 + outfile = fopen("emif-performance.csv", "w+");
523 + printf("\n Error opening file");
537 + if(STATCOLL == 1) {
538 + printf("STATISTICS COLLECTOR option chosen\n");
539 + printf("------------------------------------------------\n\n");
540 + fp = fopen("initiators.cfg", "r");
542 + fprintf(stderr, "couldn't open the specified file initiators.cfg'\n");
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);
557 + statcoll_start(TOTAL_TIME, INTERVAL_US, list, xpos, ypos);
562 diff --git a/clients/soc_performance_monitor.c b/clients/soc_performance_monitor.c
564 index 0000000..5d1db32
566 +++ b/clients/soc_performance_monitor.c
569 + * Copyright (C) 2016 Texas Instruments
570 + * Author: Karthik Ramanan <karthik.ramanan@ti.com>
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.
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
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/>.
594 +#include <sys/time.h>
595 +#include <pthread.h>
599 +#include <sys/stat.h>
601 +#include "time_bar_graph.h"
603 +#include "soc_performance_monitor.h"
607 +static char readfifo[100];
608 +static int MAX_WIDTH=1920;
609 +static int MAX_HEIGHT=1080;
611 +static int y_pos=40;
614 +struct time_graph_create_params tg_p;
615 +struct bar_graph_create_params bg_p;
617 +static int cpu_load_offset = 0;
618 +static int total_cpu_load_items = 0;
619 +static int total_elements = 0;
621 +struct _bar_graph_y_config *y_cfg;
622 +struct _text_config *t_cfg;
627 +int command_handler(int command, double *y, char **text)
631 + int i, bytes, offset;
636 + fd = open(readfifo, O_RDONLY|O_NONBLOCK);
641 + /* open, read, and display the message from the FIFO */
642 + bytes=read(fd, buf, MAX_BUF);
648 + sscanf(buf, "%s %s", command, string);
649 + printd("Received %s\n", buf);
650 + if(strcmp(command, "TABLE:") == 0)
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);
661 + else if(strcmp(command, "CPULOAD:") == 0)
663 + char field[100], value[100];
665 + sscanf(buf, "%s %s %s", command, field, value);
667 + for(i=cpu_load_offset; i<cpu_load_offset+total_cpu_load_items; i++) {
668 + if(strcmp(text[i*2], field) == 0) {
669 + if(strlen(value) <= 2) {
670 + y[i*2+1] = atoi(value)/100.0;
671 + sprintf(text[i*2+1], " %02s%s", value,"%");
672 + printd("CPULOAD: Updating %s with %s\n", field, value);
675 + printf("Ignoring value: %s\n", value);
680 + else if(strcmp(command, "MOVE:") == 0)
683 + printd("Received MOVE command : %s\n", buf);
684 + sscanf(string, "%s", value);
685 + sprintf(tg_p.title, "CPU Usage[@position-req=%sx%d]", value, y_pos);
686 + move_graph(ctx, &tg_p);
690 + printf("ERROR: Received unexpected data from FIFO - \" %s \" \n", buf);
692 + memset(buf, 0x0, sizeof(buf));
704 +volatile sig_atomic_t sigtermed = 0;
706 +void my_signal_handler(int signum)
708 + if (signum == SIGTERM || signum == SIGINT) {
713 +int get_strings_in_section(char *string, char **output)
717 + int total_strings = 0;
719 + fd = fopen("soc_performance_monitor.cfg", "r");
721 + fprintf(stderr, "ERROR: Unable to open file soc_performance_monitor.cfg\n");
722 + fprintf(stderr, " Please copy the file from /etc/visualization_scripts into current directory\n");
726 + while(fgets(line, sizeof line, fd)) {
727 + if(strstr(line, string)) {
728 + printf("\n-------------------------------------------------\n");
729 + printf("CONFIG FILE PARSE: Found section %s in line : %s\n", string, line);
734 + while(fgets(line, sizeof line, fd)) {
735 + printd("Line is = %s", line);
737 + if (line[0] == '#' || line[0] == '\n' || line[0] == '[') {
741 + line[strlen(line) - 1] = '\0';
742 + strcpy(output[total_strings++], line);
747 + return total_strings;
751 +void fill_cpu_load_details(int start_offset, int end_offset, char **output, struct table_configuration *table_config)
755 + const int BL_START_X = table_config->BL_START_X;
756 + const int BL_START_Y = table_config->BL_START_Y;
757 + const int BAR_GAP = table_config->BAR_GAP;
758 + const int BAR_HEIGHT = table_config->BAR_HEIGHT;
759 + const int BAR_WIDTH = table_config->BAR_WIDTH;
760 + const int TR_START_X = table_config->TR_START_X;
761 + const int TR_START_Y = table_config->TR_START_Y;
762 + const int FONT_SIZE = table_config->FONT_SIZE;
763 + printf("Filling from %d to %d\n", start_offset, end_offset);
764 + cpu_load_offset = start_offset;
766 + for(i=start_offset; i< end_offset-1; i++) {
767 + y_cfg[i*2].region.bottom_left.x = BL_START_X + (i-start_offset) * (BAR_GAP + BAR_WIDTH);
768 + y_cfg[i*2].region.bottom_left.y = BL_START_Y;
769 + y_cfg[i*2].region.top_right.x = TR_START_X + (i-start_offset) * (BAR_GAP + BAR_WIDTH);
770 + y_cfg[i*2].region.top_right.y = TR_START_Y;
771 + y_cfg[i*2].line_color.r = 1.0;
772 + y_cfg[i*2].line_color.g = 1.0;
773 + y_cfg[i*2].line_color.b = 1.0;
774 + y_cfg[i*2].line_color.a = 1.0;
775 + y_cfg[i*2].fill_color.r = 0.0;
776 + y_cfg[i*2].fill_color.g = 0.0;
777 + y_cfg[i*2].fill_color.b = 1.0;
778 + y_cfg[i*2].fill_color.a = 0.7;
780 + y_cfg[i*2+1].region.bottom_left.x = BL_START_X +(i-start_offset) * (BAR_GAP + BAR_WIDTH);
781 + y_cfg[i*2+1].region.bottom_left.y = BL_START_Y;
782 + y_cfg[i*2+1].region.top_right.x = TR_START_X + (i-start_offset) * (BAR_GAP + BAR_WIDTH);
783 + y_cfg[i*2+1].region.top_right.y = TR_START_Y;
784 + y_cfg[i*2+1].line_color.r = 1.0;
785 + y_cfg[i*2+1].line_color.g = 1.0;
786 + y_cfg[i*2+1].line_color.b = 1.0;
787 + y_cfg[i*2+1].line_color.a = 1.0;
788 + y_cfg[i*2+1].fill_color.r = 1.0;
789 + y_cfg[i*2+1].fill_color.g = 0.0;
790 + y_cfg[i*2+1].fill_color.b = 0.0;
791 + y_cfg[i*2+1].fill_color.a = 1.0;
794 + t_cfg[i*2].color.r = 1.0;
795 + t_cfg[i*2].color.g = 1.0;
796 + t_cfg[i*2].color.b = 1.0;
797 + t_cfg[i*2].color.a = 1.0;
798 + t_cfg[i*2].at.x = BL_START_X + (i-start_offset) * (BAR_GAP + BAR_WIDTH);
799 + t_cfg[i*2].at.y = BL_START_Y + FONT_SIZE;
800 + t_cfg[i*2].fontsize = FONT_SIZE;
802 + t_cfg[i*2+1].color.r = 1.0;
803 + t_cfg[i*2+1].color.g = 1.0;
804 + t_cfg[i*2+1].color.b = 1.0;
805 + t_cfg[i*2+1].color.a = 1.0;
806 + t_cfg[i*2+1].at.x = BL_START_X + (i-start_offset) * (BAR_GAP + BAR_WIDTH);
807 + t_cfg[i*2+1].at.y = BL_START_Y - BAR_HEIGHT - FONT_SIZE;
808 + t_cfg[i*2+1].fontsize = FONT_SIZE;
810 + strcpy(bg_text[i*2], output[i - start_offset]);
811 + strcpy(bg_text[i*2+1], "0%");
814 + t_cfg[(end_offset-1)*2].color.r = 0.0;
815 + t_cfg[(end_offset-1)*2].color.g = 1.0;
816 + t_cfg[(end_offset-1)*2].color.b = 1.0;
817 + t_cfg[(end_offset-1)*2].color.a = 1.0;
818 + t_cfg[(end_offset-1)*2].at.x = BL_START_X + 80;
819 + t_cfg[(end_offset-1)*2].at.y = TR_START_Y - 40;
820 + t_cfg[(end_offset-1)*2].fontsize = FONT_SIZE + 3;
822 + printd("Copying title string %s\n", output[end_offset - start_offset -1]);
823 + strcpy(bg_text[(end_offset-1)*2], output[end_offset - start_offset-1]);
826 +void fill_table_details(int start_offset, int end_offset, char **output, struct table_configuration *table_config)
830 + const int BL_START_X = table_config->BL_START_X;
831 + const int BL_START_Y = table_config->BL_START_Y;
832 + const int BAR_GAP = table_config->BAR_GAP;
833 + const int BAR_HEIGHT = table_config->BAR_HEIGHT;
834 + const int BAR_WIDTH = table_config->BAR_WIDTH;
835 + const int TR_START_X = table_config->TR_START_X;
836 + const int TR_START_Y = table_config->TR_START_Y;
837 + const int FONT_SIZE = table_config->FONT_SIZE;
838 + printf("Filling from %d to %d\n", start_offset, end_offset);
841 + char tokenize[200];
842 + char tokens[10][100];
843 + char *pair, *key, *value;
845 + char title[100], unit[100];
847 + strcpy(tokenize, output[end_offset - start_offset - 1]);
848 + memset(tokens, 0, sizeof(tokens));
851 + pair = strtok (tokenize,",");
852 + while (pair != NULL) {
853 + strcpy(tokens[k++], pair);
854 + pair = strtok (NULL, ",");
858 + memset(title, 0, sizeof(title));
859 + memset(unit, 0, sizeof(unit));
861 + key=strtok(tokens[i], "=");
863 + if(strcmp(key,"TITLE") == 0) {
864 + value = strtok(NULL, "=");
865 + if(value != NULL) {
866 + strcpy(title, value);
869 + if(strcmp(key,"UNIT") == 0) {
870 + value = strtok(NULL, "=");
871 + if(value != NULL) {
872 + strcpy(unit, value);
879 + for(i=start_offset; i< end_offset-1; i++) {
880 + y_cfg[i*2].region.bottom_left.x = BL_START_X;
881 + y_cfg[i*2].region.bottom_left.y = BL_START_Y + (i - start_offset) * (BAR_GAP + BAR_HEIGHT);
882 + y_cfg[i*2].region.top_right.x = TR_START_X;
883 + y_cfg[i*2].region.top_right.y = TR_START_Y + (i - start_offset) * (BAR_GAP + BAR_HEIGHT);
884 + y_cfg[i*2].line_color.r = 1.0;
885 + y_cfg[i*2].line_color.g = 1.0;
886 + y_cfg[i*2].line_color.b = 1.0;
887 + y_cfg[i*2].line_color.a = 1.0;
888 + y_cfg[i*2].fill_color.r = 0.0;
889 + y_cfg[i*2].fill_color.g = 0.3;
890 + y_cfg[i*2].fill_color.b = 0.0;
891 + y_cfg[i*2].fill_color.a = 0.7;
893 + y_cfg[i*2+1].region.bottom_left.x = TR_START_X;
894 + y_cfg[i*2+1].region.bottom_left.y = BL_START_Y + (i - start_offset) * (BAR_GAP + BAR_HEIGHT);
895 + y_cfg[i*2+1].region.top_right.x = TR_START_X + (BAR_WIDTH); //+ 1 * BL_START_X;
896 + y_cfg[i*2+1].region.top_right.y = TR_START_Y + (i - start_offset) * (BAR_GAP + BAR_HEIGHT);;
897 + y_cfg[i*2+1].line_color.r = 1.0;
898 + y_cfg[i*2+1].line_color.g = 1.0;
899 + y_cfg[i*2+1].line_color.b = 1.0;
900 + y_cfg[i*2+1].line_color.a = 1.0;
901 + y_cfg[i*2+1].fill_color.r = 0.3;
902 + y_cfg[i*2+1].fill_color.g = 0.0;
903 + y_cfg[i*2+1].fill_color.b = 0.0;
904 + y_cfg[i*2+1].fill_color.a = 0.7;
907 + t_cfg[i*2].color.r = 1.0;
908 + t_cfg[i*2].color.g = 1.0;
909 + t_cfg[i*2].color.b = 1.0;
910 + t_cfg[i*2].color.a = 1.0;
911 + t_cfg[i*2].at.x = BL_START_X + 5;
912 + t_cfg[i*2].at.y = BL_START_Y + (i - start_offset) * (BAR_GAP+BAR_HEIGHT) -5;
913 + t_cfg[i*2].fontsize = FONT_SIZE;
915 + t_cfg[i*2+1].color.r = 1.0;
916 + t_cfg[i*2+1].color.g = 1.0;
917 + t_cfg[i*2+1].color.b = 1.0;
918 + t_cfg[i*2+1].color.a = 1.0;
919 + t_cfg[i*2+1].at.x = TR_START_X + 50;//BAR_WIDTH + TR_START_X;
920 + t_cfg[i*2+1].at.y = BL_START_Y + (i - start_offset) * (BAR_GAP + BAR_HEIGHT) -5;
921 + t_cfg[i*2+1].fontsize = FONT_SIZE;
923 + printd("Copying string %s at %d\n", output[i-start_offset], i);
924 + strcpy(bg_text[i*2], output[i-start_offset]);
925 + printd("Setting text 0 %s at %d\n", unit, i*2+1);
926 + sprintf(bg_text[i*2+1], "0 %s", unit);
928 + for(i=start_offset; i< end_offset*2; i++) {
929 + printd("%d - (%d, %d) to (%d, %d)\n", i, y_cfg[i].region.bottom_left.x, y_cfg[i].region.bottom_left.y, y_cfg[i].region.top_right.x, y_cfg[i].region.top_right.y);
932 + t_cfg[(end_offset-1)*2].color.r = 0.0;
933 + t_cfg[(end_offset-1)*2].color.g = 1.0;
934 + t_cfg[(end_offset-1)*2].color.b = 1.0;
935 + t_cfg[(end_offset-1)*2].color.a = 1.0;
936 + t_cfg[(end_offset-1)*2].at.x = BL_START_X + 80;
937 + t_cfg[(end_offset-1)*2].at.y = BL_START_Y - 40;
938 + t_cfg[(end_offset-1)*2].fontsize = FONT_SIZE + 3;
940 + printd("Copying title string %s\n", title);
941 + strcpy(bg_text[(end_offset-1)*2], title);
946 +int get_key_value_from_string(char *string, char *limiter, char *key, char *value)
948 + char *mykey, *myvalue;
950 + mykey=strtok(string, limiter);
951 + if(mykey != NULL) {
952 + myvalue = strtok(NULL, "=");
953 + strtok(myvalue, "\n");
954 + if(myvalue == NULL) {
961 + printd("Key is %s\n", mykey);
962 + printd("Value is %s\n", myvalue);
963 + strcpy(key, mykey);
964 + strcpy(value, myvalue);
969 +void populate_table_configuration(struct table_configuration *tbl_cfg, int cur_items, char **item_list)
971 + static int total_items = 0;
972 + static int total_tables = 0;
974 + tbl_cfg->BAR_HEIGHT = 25;
975 + tbl_cfg->BAR_WIDTH = 150;
976 + tbl_cfg->BL_START_X = 40;
977 + tbl_cfg->BL_START_Y = 80 + (total_items + total_tables) * tbl_cfg->BAR_HEIGHT;
978 + tbl_cfg->BAR_GAP = 0;
979 + tbl_cfg->TR_START_X = tbl_cfg->BL_START_X + tbl_cfg->BAR_WIDTH;
980 + tbl_cfg->TR_START_Y = tbl_cfg->BL_START_Y - tbl_cfg->BAR_HEIGHT;
981 + tbl_cfg->FONT_SIZE = 15;
983 + printf("Proceeding with filling out details...\n");
985 + fill_table_details(total_items, total_items+cur_items, item_list, tbl_cfg);
987 + total_items += cur_items;
991 + printf("total_items = %d, total_tables = %d\n", total_items, total_tables);
995 +int fill_list_from_section(char **section_list, char *section_name)
997 + int total_items, j;
999 + for(j=0; j<20; j++) {
1000 + section_list[j] = malloc(100);
1003 + total_items = get_strings_in_section(section_name, section_list);
1004 + printf("\tThe total values in the section %s are %d\n", section_name, total_items);
1005 + for(j=0; j<total_items; j++) {
1006 + printf("\t\tThe returned strings for BOOT_TIME are %s\n", section_list[j]);
1009 + total_elements += total_items;
1011 + return total_items;
1014 +int main(int argc, char *argv[])
1021 + if (SIG_ERR == signal(SIGPIPE,SIG_IGN))
1024 + if (SIG_ERR == signal(SIGINT,my_signal_handler))
1027 + if (SIG_ERR == signal(SIGTERM,my_signal_handler))
1031 + printf("Enabling debug\n");
1032 + debug = atoi(argv[1]);
1035 + printf("Debug is disabled\n");
1040 + int total = fill_list_from_section(output, "GLOBAL");
1041 + for(j=0; j<total; j++) {
1042 + char key[100], value[100];
1043 + int ret = get_key_value_from_string(output[j], "=", key, value);
1045 + if(strcmp(key, "FIFO") == 0) {
1046 + strcpy(readfifo, value);
1048 + if(strcmp(key, "REFRESH_RATE_USEC") == 0) {
1049 + refresh_rate = atoi(value);
1051 + if(strcmp(key, "MAX_WIDTH") == 0) {
1052 + MAX_WIDTH = atoi(value);
1054 + if(strcmp(key, "MAX_HEIGHT") == 0) {
1055 + MAX_HEIGHT = atoi(value);
1057 + if(strcmp(key, "X_POS") == 0) {
1058 + x_pos = atoi(value);
1060 + if(strcmp(key, "Y_POS") == 0) {
1061 + y_pos = atoi(value);
1067 + printf("\n-------------------------------------------------\n");
1068 + printf("Configured REFRESH_RATE is %d\n", refresh_rate);
1069 + printf("Configured FIFO is %s\n", readfifo);
1070 + printf("Configured MAX_WIDTH is %d\n", MAX_WIDTH);
1071 + printf("Configured MAX_HEIGHT is %d\n", MAX_HEIGHT);
1072 + printf("Configured starting location is (%d, %d)\n", x_pos, y_pos);
1073 + printf("\n-------------------------------------------------\n");
1075 + int fd = open(readfifo, O_RDONLY|O_NONBLOCK);
1077 + printf("SUCCESS: Configured FIFO exists\n");
1081 + printf("ERROR: %s not found\nPlease create the fifo by executing mkfifo %s before running the application\n", readfifo, readfifo);
1086 + bg_p.title = malloc(100);
1087 + sprintf(bg_p.title, "CPU Usage[@position-req=%dx%d]", x_pos, y_pos);
1089 + /* ------------------------------------------------------------------------*/
1090 + /* Section for populating all lists from cfg sections*/
1091 + /* ------------------------------------------------------------------------*/
1092 + char *boot_list[20];
1093 + int total_boot_items = fill_list_from_section(boot_list, "BOOT_TIME");
1095 + char *temperature_list[20];
1096 + int total_temperature_items = fill_list_from_section(temperature_list, "TEMPERATURE");
1098 + char *cpu_load_list[20];
1099 + total_cpu_load_items = fill_list_from_section(cpu_load_list, "CPU_LOAD");
1101 + char *voltage_list[20];
1102 + int total_voltage_items = fill_list_from_section(voltage_list, "VOLTAGE");
1104 + char *frequency_list[20];
1105 + int total_frequency_items = fill_list_from_section(frequency_list, "FREQUENCY");
1106 + /* ------------------------------------------------------------------------*/
1107 + /* total_elements will be updated inside the fill_list_from_section function */
1109 + t_cfg = malloc(sizeof(struct _text_config) * (total_elements*2 + 1));
1110 + y_cfg = malloc(sizeof(struct _bar_graph_y_config) * total_elements*2);
1111 + bg_p.num_of_y_items = total_elements*2;
1112 + bg_p.y_config_array = y_cfg;
1113 + bg_p.num_of_text_items = total_elements*2 + 1;
1114 + bg_p.text_config_array = t_cfg;
1116 + bg_y = malloc(sizeof(double) * total_elements * 2);
1117 + for(i=0; i< (total_elements*2+1); i++) {
1118 + bg_text[i] = malloc(150);
1122 + tg_y = malloc(sizeof(double) * total_elements * 2);
1123 + for(i=0; i< (total_elements*2+1); i++) {
1124 + tg_text[i] = malloc(150);
1125 + tg_y[i] = 0.1 * i;
1128 + struct table_configuration boot_table_config;
1129 + populate_table_configuration(&boot_table_config, total_boot_items, boot_list);
1131 + struct table_configuration temp_table_config;
1132 + populate_table_configuration(&temp_table_config, total_temperature_items, temperature_list);
1134 + struct table_configuration voltage_table_config;
1135 + populate_table_configuration(&voltage_table_config, total_voltage_items, voltage_list);
1137 + struct table_configuration frequency_table_config;
1138 + populate_table_configuration(&frequency_table_config, total_frequency_items, frequency_list);
1140 + struct table_configuration cpu_load_config;
1141 + cpu_load_config.BL_START_X = 40;
1142 + cpu_load_config.BL_START_Y = 80 + (total_boot_items + total_temperature_items + total_voltage_items + total_frequency_items+ 4) * boot_table_config.BAR_HEIGHT + 80 /*cpu_load_config.BAR_HEIGHT */;
1143 + cpu_load_config.BAR_GAP = 20;
1144 + cpu_load_config.BAR_HEIGHT = 80;
1145 + cpu_load_config.BAR_WIDTH = 40;
1146 + cpu_load_config.TR_START_X = cpu_load_config.BL_START_X + cpu_load_config.BAR_WIDTH;
1147 + cpu_load_config.TR_START_Y = cpu_load_config.BL_START_Y - cpu_load_config.BAR_HEIGHT;
1148 + cpu_load_config.FONT_SIZE = 15;
1149 + if(total_cpu_load_items > 0) {
1150 + fill_cpu_load_details(total_boot_items+total_temperature_items+total_voltage_items+total_frequency_items, total_boot_items+total_temperature_items+total_voltage_items+total_frequency_items+total_cpu_load_items, cpu_load_list, &cpu_load_config);
1153 + cpu_load_offset = total_boot_items + total_temperature_items + total_voltage_items + total_frequency_items;
1156 + tg_p.title=(char *)malloc(100);
1157 + sprintf(tg_p.title, "CPU Usage[@position-req=%dx%d]", x_pos, y_pos);
1158 + tg_p.height = MAX_HEIGHT;
1159 + tg_p.width = MAX_WIDTH;
1161 + struct _y_config *tg_y_cfg = malloc(tg_p.num_of_y_items * sizeof(struct _y_config));
1162 + tg_p.y_config_array = tg_y_cfg;
1163 + tg_p.text_config_array = t_cfg;
1165 + printf("Proceeding to create starting visualization...\n");
1166 + ctx = time_graph_create(argc, argv, &tg_p);
1168 + printf("Unable to create time_graph... \n");
1172 + ctx = bar_graph_create(argc, argv, &bg_p);
1174 + printf("Error creating context\n");
1178 + command_handler(OPEN, NULL, NULL);
1180 + /* Plot the graph first time */
1181 + time_graph_plot(ctx, tg_y, (const char **)tg_text);
1182 + bar_graph_plot(ctx, bg_y, (const char **)bg_text);
1184 + while (!sigtermed)
1186 + usleep(refresh_rate);
1187 + int bytes_read = command_handler(READ, bg_y, bg_text);
1188 + if(bytes_read > 0) {
1189 + time_graph_plot(ctx, tg_y, (const char **)tg_text);
1190 + bar_graph_plot(ctx, bg_y, (const char **)bg_text);
1194 + bar_graph_destroy(ctx);
1195 + command_handler(CLOSE, NULL, NULL);
1198 diff --git a/clients/soc_performance_monitor.h b/clients/soc_performance_monitor.h
1199 new file mode 100644
1200 index 0000000..861c8c7
1202 +++ b/clients/soc_performance_monitor.h
1204 +#define __SLEEP usleep(1000000)
1206 +#define MAX_BUF 1024
1211 +#define MAX_COLORS 12
1213 +#define printd(fmt, ...) \
1214 + do { if (debug) fprintf(stderr, fmt, __VA_ARGS__); } while (0)
1217 +struct _rgba pallette[MAX_COLORS] =
1219 + { 1.0, 0.0, 0.0, 1.0 },
1220 + { 0.0, 0.5, 0.0, 1.0 },
1221 + { 0.0, 0.0, 1.0, 1.0 },
1222 + { 0.0, 0.0, 0.0, 1.0 },
1223 + { 0.0, 0.5, 1.0, 1.0 },
1224 + { 1.0, 0.0, 1.0, 1.0 },
1225 + { 0.5, 0.5, 1.0, 1.0 },
1226 + { 1.0, 0.5, 0.0, 1.0 },
1227 + { 0.5, 0.5, 0.25, 1.0 },
1228 + { 0.5, 0.0, 0.0, 1.0 },
1229 + { 1.0, 0.5, 0.5, 1.0 },
1230 + { 0.0, 0.0, 0.20, 1.0 }
1233 +struct table_configuration {
1244 diff --git a/clients/statcoll.c b/clients/statcoll.c
1245 new file mode 100644
1246 index 0000000..5d5cae7
1248 +++ b/clients/statcoll.c
1251 + * Copyright (C) 2015 Texas Instruments
1252 + * created by prash@ti.com on 16 Jan 2013
1253 + * Adapted to Linux with changes in framework: Karthik R <karthik.ramanan@ti.com>
1255 + * This program is free software; you can redistribute it and/or modify it
1256 + * under the terms of the GNU General Public License version 2 as published by
1257 + * the Free Software Foundation.
1259 + * This program is distributed in the hope that it will be useful, but WITHOUT
1260 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1261 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
1264 + * You should have received a copy of the GNU General Public License along with
1265 + * this program. If not, see <http://www.gnu.org/licenses/>.
1269 +#include <stdlib.h>
1270 +#include <string.h>
1271 +#include <sys/mman.h>
1273 +#include <signal.h>
1274 +#include <unistd.h>
1275 +#include <sys/time.h>
1277 +#include "statcoll.h"
1278 +#include "statcoll_gui.h"
1279 +#include "time_bar_graph.h"
1281 +#define ENABLE_MODE 0x0
1282 +#define READ_STATUS_MODE 0x1
1292 +#define __SLEEP sleep(1)
1294 +#define __SLEEP usleep(100000)
1296 +//#define DUMMY_MODE
1298 +#define MAX_COLORS 12
1300 +struct _rgba pallette[MAX_COLORS] =
1302 + { 1.0, 0.0, 0.0, 1.0 },
1303 + { 0.0, 0.5, 0.0, 1.0 },
1304 + { 0.0, 0.0, 1.0, 1.0 },
1305 + { 0.0, 0.0, 0.0, 1.0 },
1306 + { 0.0, 0.5, 1.0, 1.0 },
1307 + { 1.0, 0.0, 1.0, 1.0 },
1308 + { 0.5, 0.5, 1.0, 1.0 },
1309 + { 1.0, 0.5, 0.0, 1.0 },
1310 + { 0.5, 0.5, 0.25, 1.0 },
1311 + { 0.5, 0.0, 0.0, 1.0 },
1312 + { 1.0, 0.5, 0.5, 1.0 },
1313 + { 0.0, 0.0, 0.20, 1.0 }
1316 +const struct list_of_initiators initiators[STATCOL_MAX] =
1318 + { STATCOL_EMIF1_SYS, "STATCOL_EMIF1_SYS" },
1319 + { STATCOL_EMIF2_SYS,"STATCOL_EMIF2_SYS" },
1320 + { STATCOL_MA_MPU_P1,"STATCOL_MPU_P1" },
1321 + { STATCOL_MA_MPU_P2,"STATCOL_MPU_P2" },
1322 + { STATCOL_MPU1,"STATCOL_MPU1" },
1323 + { STATCOL_MMU1,"STATCOL_MMU1" },
1324 + { STATCOL_TPTC_RD1,"STATCOL_TPTC_RD1" },
1325 + { STATCOL_TPTC_WR1,"STATCOL_TPTC_WR1" },
1326 + { STATCOL_TPTC_RD2,"STATCOL_TPTC_RD2" },
1327 + { STATCOL_TPTC_WR2,"STATCOL_TPTC_WR2" },
1328 + { STATCOL_VIP1_P1,"STATCOL_VIP1_P1" },
1329 + { STATCOL_VIP1_P2,"STATCOL_VIP1_P2" },
1330 + { STATCOL_VIP2_P1,"STATCOL_VIP2_P1" },
1331 + { STATCOL_VIP2_P2,"STATCOL_VIP2_P2" },
1332 + { STATCOL_VIP3_P1,"STATCOL_VIP3_P1" },
1333 + { STATCOL_VIP3_P2,"STATCOL_VIP3_P2" },
1334 + { STATCOL_VPE_P1,"STATCOL_VPE_P1" },
1335 + { STATCOL_VPE_P2,"STATCOL_VPE_P2" },
1336 + { STATCOL_EVE1_TC0,"STATCOL_EVE1_TC0" },
1337 + { STATCOL_EVE1_TC1,"STATCOL_EVE1_TC1" },
1338 + { STATCOL_EVE2_TC0,"STATCOL_EVE2_TC0" },
1339 + { STATCOL_EVE2_TC1,"STATCOL_EVE2_TC1" },
1340 + { STATCOL_EVE3_TC0,"STATCOL_EVE3_TC0" },
1341 + { STATCOL_EVE3_TC1,"STATCOL_EVE3_TC1" },
1342 + { STATCOL_EVE4_TC0,"STATCOL_EVE4_TC0" },
1343 + { STATCOL_EVE4_TC1,"STATCOL_EVE4_TC1" },
1344 + { STATCOL_DSP1_MDMA,"STATCOL_DSP1_MDMA" },
1345 + { STATCOL_DSP1_EDMA,"STATCOL_DSP1_EDMA" },
1346 + { STATCOL_DSP2_MDMA,"STATCOL_DSP2_MDMA" },
1347 + { STATCOL_DSP2_EDMA,"STATCOL_DSP2_EDMA" },
1348 + { STATCOL_IVA,"STATCOL_IVA" },
1349 + { STATCOL_GPU_P1,"STATCOL_GPU_P1" },
1350 + { STATCOL_GPU_P2,"STATCOL_GPU_P2" },
1351 + { STATCOL_BB2D_P1,"STATCOL_BB2D_P1" },
1352 + { STATCOL_DSS,"STATCOL_DSS" },
1353 + { STATCOL_CSI2_2,"STATCOL_CSI2_2" },
1354 + { STATCOL_MMU2,"STATCOL_MMU2" },
1355 + { STATCOL_IPU1,"STATCOL_IPU1" },
1356 + { STATCOL_IPU2,"STATCOL_IPU2" },
1357 + { STATCOL_DMA_SYSTEM_RD,"STATCOL_DMA_SYSTEM_RD" },
1358 + { STATCOL_DMA_SYSTEM_WR,"STATCOL_DMA_SYSTEM_WR" },
1359 + { STATCOL_CSI2_1,"STATCOL_CSI2_1" },
1360 + { STATCOL_USB3_SS,"STATCOL_USB3_SS" },
1361 + { STATCOL_USB2_SS,"STATCOL_USB2_SS" },
1362 + { STATCOL_USB2_ULPI_SS1,"STATCOL_USB2_ULPI_SS1" },
1363 + { STATCOL_USB2_ULPI_SS2,"STATCOL_USB2_ULPI_SS2" },
1364 + { STATCOL_PCIE_SS1,"STATCOL_PCIE_SS1" },
1365 + { STATCOL_PCIE_SS2,"STATCOL_PCIE_SS2" },
1366 + { STATCOL_DSP1_CFG,"STATCOL_DSP1_CFG" },
1367 + { STATCOL_DSP2_CFG,"STATCOL_DSP2_CFG" },
1368 + { STATCOL_GMAC_SW,"STATCOL_GMAC_SW" },
1369 + { STATCOL_PRUSS1_P1,"STATCOL_PRUSS1_P1" },
1370 + { STATCOL_PRUSS1_P2,"STATCOL_PRUSS1_P2" },
1371 + { STATCOL_PRUSS2_P1,"STATCOL_PRUSS2_P1" },
1372 + { STATCOL_PRUSS2_P2,"STATCOL_PRUSS2_P2" },
1373 + { STATCOL_DMA_CRYPTO_RD,"STATCOL_DMA_CRYPTO_RD" },
1374 + { STATCOL_DMA_CRYPTO_WR,"STATCOL_DMA_CRYPTO_WR" },
1375 + { STATCOL_MPU2,"STATCOL_MPU2" },
1376 + { STATCOL_MMC1,"STATCOL_MMC1" },
1377 + { STATCOL_MMC2,"STATCOL_MMC2" },
1378 + { STATCOL_SATA,"STATCOL_SATA" },
1379 + { STATCOL_MLBSS,"STATCOL_MLBSS" },
1380 + { STATCOL_BB2D_P2,"STATCOL_BB2D_P2" },
1381 + { STATCOL_IEEE1500,"STATCOL_IEEE1500" },
1382 + { STATCOL_DBG,"STATCOL_DBG" },
1383 + { STATCOL_VCP1,"STATCOL_VCP1" },
1384 + { STATCOL_OCMC_RAM1,"STATCOL_OCMC_RAM1" },
1385 + { STATCOL_OCMC_RAM2,"STATCOL_OCMC_RAM2" },
1386 + { STATCOL_OCMC_RAM3,"STATCOL_OCMC_RAM3" },
1387 + { STATCOL_GPMC,"STATCOL_GPMC" },
1388 + { STATCOL_MCASP1,"STATCOL_MCASP1" },
1389 + { STATCOL_MCASP2,"STATCOL_MCASP2" },
1390 + { STATCOL_MCASP3,"STATCOL_MCASP3" },
1391 + { STATCOL_VCP2, "STATCOL_VCP2" }
1394 +StatCollectorObj gStatColState;
1396 +static void *statcoll_base_mem;
1397 +static int *l3_3_clkctrl;
1399 +static UInt32 *statCountDSS = NULL;
1400 +static UInt32 *statCountIVA = NULL;
1401 +static UInt32 *statCountBB2DP1 = NULL;
1402 +static UInt32 *statCountBB2DP2 = NULL;
1403 +static UInt32 *statCountUSB4 = NULL;
1404 +static UInt32 *statCountSata = NULL;
1405 +static UInt32 *statCountEmif1 = NULL;
1406 +static UInt32 *statCountEmif2 = NULL;
1409 +static statcoll_initiators_object global_object[STATCOL_MAX];
1410 +UInt32 statCountIdx = 0;
1411 +UInt32 TRACE_SZ = 0;
1413 +void create_overall_box(struct _bar_graph_y_config *y_cfg, struct _text_config *t_cfg, char *text[])
1417 + memset(y_cfg, 0x0, sizeof(struct _y_config)*25);
1418 + memset(t_cfg, 0x0, sizeof(struct _text_config)*25);
1421 + for(i=0; i<TOTAL_Y_PARAMETERS; i++) {
1422 + (y_cfg+i)->line_color.r = 1.0;
1423 + (y_cfg+i)->line_color.g = 1.0;
1424 + (y_cfg+i)->line_color.b = 1.0;
1425 + (y_cfg+i)->line_color.a = 0.7;
1426 + (y_cfg+i)->fill_color.r = 0.0;
1427 + (y_cfg+i)->fill_color.g = 0.0;
1428 + (y_cfg+i)->fill_color.b = 0.0;
1429 + (y_cfg+i)->fill_color.a = 0.1;
1432 + (y_cfg+0)->region.bottom_left.x = 0;
1433 + (y_cfg+0)->region.bottom_left.y = MAX_HEIGHT - HEIGHT_EMIF_AREA;
1434 + (y_cfg+0)->region.top_right.x = MAX_WIDTH;
1435 + (y_cfg+0)->region.top_right.y = 0;
1437 + (t_cfg+0)->at.x = MAX_WIDTH/2 - 8*FONT_SIZE - 50;
1438 + (t_cfg+0)->at.y = BORDER - FONT_SIZE + 6;
1439 + strcpy(text[0], string_list[0]);
1441 + (y_cfg+1)->region.bottom_left.x = TIME_GRAPH_AREA_BL_X;
1442 + (y_cfg+1)->region.bottom_left.y = TIME_GRAPH_AREA_BL_Y;
1443 + (y_cfg+1)->region.top_right.x = TIME_GRAPH_AREA_TR_X;
1444 + (y_cfg+1)->region.top_right.y = TIME_GRAPH_AREA_TR_Y;
1446 + (t_cfg+1)->at.x = TIME_GRAPH_AREA_BL_X - 2*FONT_SIZE;
1447 + (t_cfg+1)->at.y = TIME_GRAPH_AREA_TR_Y;
1448 + strcpy(text[1],string_list[1]);
1450 + for(i=2; i<7; i++)
1452 + (y_cfg+i)->region.bottom_left.x = TIME_GRAPH_AREA_BL_X;
1453 + (y_cfg+i)->region.bottom_left.y = TIME_GRAPH_AREA_BL_Y;// - (i-2) * (30);
1454 + (y_cfg+i)->region.top_right.x = TIME_GRAPH_AREA_TR_X;
1455 + (y_cfg+i)->region.top_right.y = TIME_GRAPH_AREA_TR_Y + (i-1) * ((TIME_GRAPH_AREA_BL_Y - TIME_GRAPH_AREA_TR_Y)/5);
1456 + (t_cfg+i)->at.x = TIME_GRAPH_AREA_BL_X - 2*FONT_SIZE;
1457 + (t_cfg+i)->at.y = TIME_GRAPH_AREA_TR_Y + (i-1) * ((TIME_GRAPH_AREA_BL_Y - TIME_GRAPH_AREA_TR_Y)/5);//TIME_GRAPH_AREA_TR_Y;
1458 + strcpy(text[i],string_list[i]);
1462 + (y_cfg+7)->region.bottom_left.x = EMIF_AREA_BL_X;
1463 + (y_cfg+7)->region.bottom_left.y = EMIF_AREA_BL_Y;
1464 + (y_cfg+7)->region.top_right.x = EMIF_AREA_TR_X;
1465 + (y_cfg+7)->region.top_right.y = EMIF_AREA_TR_Y;
1467 + (t_cfg+7)->at.x = WIDTH_EMIF_AREA/2 - 2*FONT_SIZE;
1468 + (t_cfg+7)->at.y = EMIF_AREA_TR_Y + FONT_SIZE;
1469 + strcpy(text[7],string_list[7]);
1471 + for(i=8; i<12; i=i+2)
1473 + (y_cfg+i)->region.bottom_left.x = EMIF_AREA_BL_X + BORDER + (i-8)*(BAR_WIDTH+BAR_GAP)/2;
1474 + (y_cfg+i)->region.bottom_left.y = EMIF_AREA_BL_Y - BORDER/2;// - (i-2) * (30);
1475 + (y_cfg+i)->region.top_right.x = EMIF_AREA_BL_X + BORDER + BAR_WIDTH + (i-8) * (BAR_WIDTH + BAR_GAP)/2;
1476 + (y_cfg+i)->region.top_right.y = EMIF_AREA_TR_Y + BORDER * 1.2;
1478 + (y_cfg+i)->fill_color.r = 1.0;
1479 + (y_cfg+i)->fill_color.g = 0.0;
1480 + (y_cfg+i)->fill_color.b = 0.0;
1481 + (y_cfg+i)->fill_color.a = 0.1;
1483 + (y_cfg+i+1)->region.bottom_left.x = EMIF_AREA_BL_X + BORDER + (i-8) * (BAR_WIDTH + BAR_GAP)/2;
1484 + (y_cfg+i+1)->region.bottom_left.y = EMIF_AREA_BL_Y - BORDER/2;
1485 + (y_cfg+i+1)->region.top_right.x = EMIF_AREA_BL_X + BORDER + BAR_WIDTH + (i-8) * (BAR_WIDTH + BAR_GAP)/2;
1486 + (y_cfg+i+1)->region.top_right.y = EMIF_AREA_TR_Y + BORDER*1.2;
1488 + (y_cfg+i+1)->fill_color.r = 0.0;
1489 + (y_cfg+i+1)->fill_color.g = 1.0;
1490 + (y_cfg+i+1)->fill_color.b = 0.0;
1491 + (y_cfg+i+1)->fill_color.a = 1.0;
1493 + (t_cfg+i)->at.x = EMIF_AREA_BL_X + BAR_WIDTH + BORDER + (i-8) * (BAR_WIDTH + BAR_GAP)/2- 2.2*FONT_SIZE;
1494 + (t_cfg+i)->at.y = EMIF_AREA_TR_Y + BORDER*1.2 -5;
1496 + /* Fixed strings */
1497 + (t_cfg+i+1)->at.x = EMIF_AREA_BL_X + BORDER + (i-8) * (BAR_WIDTH + BAR_GAP)/2;
1498 + (t_cfg+i+1)->at.y = EMIF_AREA_BL_Y;// - BORDER + FONT_SIZE;
1500 + strcpy(text[i],string_list[i]);
1501 + strcpy(text[i+1],string_list[i+1]);
1504 + (y_cfg+12)->region.bottom_left.x = INITIATORS_AREA_BL_X;
1505 + (y_cfg+12)->region.bottom_left.y = INITIATORS_AREA_BL_Y;
1506 + (y_cfg+12)->region.top_right.x = INITIATORS_AREA_TR_X;
1507 + (y_cfg+12)->region.top_right.y = INITIATORS_AREA_TR_Y;
1509 + (t_cfg+12)->at.x = EMIF_AREA_TR_X + (INITIATORS_AREA_TR_X - INITIATORS_AREA_BL_X)/2 - 4 * FONT_SIZE;
1510 + (t_cfg+12)->at.y = INITIATORS_AREA_TR_Y + FONT_SIZE;
1511 + strcpy(text[12],string_list[12]);
1513 + for(i=13; i<25; i=i+2)
1515 + (y_cfg+i)->region.bottom_left.x = INITIATORS_AREA_BL_X + BORDER + (i-13)*(BAR_WIDTH+BAR_GAP)/2;
1516 + (y_cfg+i)->region.bottom_left.y = INITIATORS_AREA_BL_Y - BORDER/2;// - (i-2) * (30);
1517 + (y_cfg+i)->region.top_right.x = INITIATORS_AREA_BL_X + BORDER + BAR_WIDTH + (i-13) * (BAR_WIDTH + BAR_GAP)/2;
1518 + (y_cfg+i)->region.top_right.y = INITIATORS_AREA_TR_Y + BORDER*1.2;
1520 + (y_cfg+i)->fill_color.r = 1.0;
1521 + (y_cfg+i)->fill_color.g = 0.0;
1522 + (y_cfg+i)->fill_color.b = 0.0;
1523 + (y_cfg+i)->fill_color.a = 0.1;
1525 + (y_cfg+i+1)->region.bottom_left.x = INITIATORS_AREA_BL_X + BORDER + (i-13) * (BAR_WIDTH + BAR_GAP)/2;
1526 + (y_cfg+i+1)->region.bottom_left.y = INITIATORS_AREA_BL_Y - BORDER/2;// - (i-2) * (30);
1527 + (y_cfg+i+1)->region.top_right.x = INITIATORS_AREA_BL_X + BORDER + BAR_WIDTH + (i-13) * (BAR_WIDTH + BAR_GAP)/2;
1528 + (y_cfg+i+1)->region.top_right.y = INITIATORS_AREA_TR_Y + BORDER* 1.2;
1530 + (y_cfg+i+1)->fill_color.r = 0.0;
1531 + (y_cfg+i+1)->fill_color.g = 1.0;
1532 + (y_cfg+i+1)->fill_color.b = 0.0;
1533 + (y_cfg+i+1)->fill_color.a = 1.0;
1535 + (t_cfg+i)->at.x = INITIATORS_AREA_BL_X + BORDER + BAR_WIDTH + (i-13) * (BAR_WIDTH + BAR_GAP)/2 - 2.2* FONT_SIZE;
1536 + (t_cfg+i)->at.y = INITIATORS_AREA_TR_Y + BORDER*1.2 -5;
1538 + (t_cfg+i+1)->at.x = INITIATORS_AREA_BL_X + BORDER + (i-13)*(BAR_WIDTH+BAR_GAP)/2;
1539 + (t_cfg+i+1)->at.y = INITIATORS_AREA_BL_Y;
1541 + strcpy(text[i],string_list[i]);
1542 + strcpy(text[i+1],string_list[i+1]);
1547 + for(i=0; i<25; i++)
1548 + printf("(%d, %d) to (%d, %d)\n", (y_cfg +i)->region.bottom_left.x,(y_cfg +i)->region.bottom_left.y,(y_cfg +i)->region.top_right.x, (y_cfg +i)->region.top_right.y);
1553 + for(i=0; i<25; i++) {
1554 + (t_cfg+i)->color.r = 0.0;
1555 + (t_cfg+i)->color.g = 1.0;
1556 + (t_cfg+i)->color.b = 1.0;
1557 + (t_cfg+i)->color.a = 1.0;
1558 + (t_cfg+i)->fontsize = FONT_SIZE;
1560 + (t_cfg+0)->fontsize = 20;
1566 +void statCollectorInit()
1570 + gStatColState.stat0_filter_cnt = 0;
1571 + gStatColState.stat1_filter_cnt = 0;
1572 + gStatColState.stat2_filter_cnt = 0;
1573 + gStatColState.stat3_filter_cnt = 0;
1574 + gStatColState.stat4_filter_cnt = 0;
1575 + gStatColState.stat5_filter_cnt = 0;
1576 + gStatColState.stat6_filter_cnt = 0;
1577 + gStatColState.stat7_filter_cnt = 0;
1578 + gStatColState.stat8_filter_cnt = 0;
1579 + gStatColState.stat9_filter_cnt = 0;
1581 + for(index=STATCOL_EMIF1_SYS; index < STATCOL_MAX; index++)
1583 + global_object[index].b_enabled = 0;
1585 + strcpy(global_object[index].name, initiators[index].name);
1587 + global_object[index].readings = malloc(TRACE_SZ * sizeof(UInt32));
1588 + memset(global_object[index].readings, 0, TRACE_SZ * sizeof(UInt32));
1590 + global_object[index].timestamp = NULL;
1592 + global_object[index].group_id = 0xFF;
1593 + global_object[index].counter_id = 0;
1594 + global_object[index].base_address = 0;
1595 + global_object[index].mux_req = 0;
1600 +void wr_stat_reg(UInt32 address, UInt32 data)
1602 + UInt32 *mymem = statcoll_base_mem;
1603 + UInt32 delta = (address - STATCOLL_BASE) / 4;
1605 + mymem[delta] = data;
1607 + printf("WRITE: Address = 0x%x, Data = 0x%x\n", address, data);
1611 +UInt32 rd_stat_reg(UInt32 address)
1614 + UInt32 *mymem = statcoll_base_mem;
1616 + UInt32 delta = (address - STATCOLL_BASE) / 4;
1617 + data = mymem[delta];
1620 + printf("READ: Address = 0x%x\n", address);
1624 +UInt32 statCollectorControlInitialize(UInt32 instance_id)
1626 + UInt32 cur_base_address = 0;
1627 + UInt32 cur_event_mux_req;
1628 + UInt32 cur_event_mux_resp;
1629 + UInt32 cur_stat_filter_cnt;
1631 + switch (instance_id)
1633 + case STATCOL_EMIF1_SYS:
1634 + cur_base_address = stat_coll0_base_address;
1635 + cur_event_mux_req = 0;
1636 + cur_event_mux_resp = 1;
1637 + gStatColState.stat0_filter_cnt = gStatColState.stat0_filter_cnt + 1;
1638 + cur_stat_filter_cnt = gStatColState.stat0_filter_cnt;
1639 + global_object[instance_id].group_id = 0;
1641 + case STATCOL_EMIF2_SYS:
1642 + cur_base_address = stat_coll0_base_address;
1643 + cur_event_mux_req = 2;
1644 + cur_event_mux_resp = 3;
1645 + gStatColState.stat0_filter_cnt = gStatColState.stat0_filter_cnt + 1;
1646 + cur_stat_filter_cnt = gStatColState.stat0_filter_cnt;
1647 + global_object[instance_id].group_id = 0;
1649 + case STATCOL_MA_MPU_P1:
1650 + cur_base_address = stat_coll0_base_address;
1651 + cur_event_mux_req = 4;
1652 + cur_event_mux_resp = 5;
1653 + gStatColState.stat0_filter_cnt = gStatColState.stat0_filter_cnt + 1;
1654 + cur_stat_filter_cnt = gStatColState.stat0_filter_cnt;
1655 + global_object[instance_id].group_id = 0;
1657 + case STATCOL_MA_MPU_P2:
1658 + cur_base_address = stat_coll0_base_address;
1659 + cur_event_mux_req = 6;
1660 + cur_event_mux_resp = 7;
1661 + gStatColState.stat0_filter_cnt = gStatColState.stat0_filter_cnt + 1;
1662 + cur_stat_filter_cnt = gStatColState.stat0_filter_cnt;
1663 + global_object[instance_id].group_id = 0;
1665 + case STATCOL_MPU1:
1666 + cur_base_address = stat_coll1_base_address;
1667 + cur_event_mux_req = 0;
1668 + cur_event_mux_resp = 1;
1669 + gStatColState.stat1_filter_cnt = gStatColState.stat1_filter_cnt + 1;
1670 + cur_stat_filter_cnt = gStatColState.stat1_filter_cnt;
1671 + global_object[instance_id].group_id = 1;
1673 + case STATCOL_MMU1:
1674 + cur_base_address = stat_coll1_base_address;
1675 + cur_event_mux_req = 2;
1676 + cur_event_mux_resp = 3;
1677 + gStatColState.stat1_filter_cnt = gStatColState.stat1_filter_cnt + 1;
1678 + cur_stat_filter_cnt = gStatColState.stat1_filter_cnt;
1679 + global_object[instance_id].group_id = 1;
1681 + case STATCOL_TPTC_RD1:
1682 + cur_base_address = stat_coll1_base_address;
1683 + cur_event_mux_req = 4;
1684 + cur_event_mux_resp = 5;
1685 + gStatColState.stat1_filter_cnt = gStatColState.stat1_filter_cnt + 1;
1686 + cur_stat_filter_cnt = gStatColState.stat1_filter_cnt;
1687 + global_object[instance_id].group_id = 1;
1689 + case STATCOL_TPTC_WR1:
1690 + cur_base_address = stat_coll1_base_address;
1691 + cur_event_mux_req = 6;
1692 + cur_event_mux_resp = 7;
1693 + gStatColState.stat1_filter_cnt = gStatColState.stat1_filter_cnt + 1;
1694 + cur_stat_filter_cnt = gStatColState.stat1_filter_cnt;
1695 + global_object[instance_id].group_id = 1;
1697 + case STATCOL_TPTC_RD2:
1698 + cur_base_address = stat_coll1_base_address;
1699 + cur_event_mux_req = 8;
1700 + cur_event_mux_resp = 9;
1701 + gStatColState.stat1_filter_cnt = gStatColState.stat1_filter_cnt + 1;
1702 + cur_stat_filter_cnt = gStatColState.stat1_filter_cnt;
1703 + global_object[instance_id].group_id = 1;
1705 + case STATCOL_TPTC_WR2:
1706 + cur_base_address = stat_coll1_base_address;
1707 + cur_event_mux_req = 10;
1708 + cur_event_mux_resp = 11;
1709 + gStatColState.stat1_filter_cnt = gStatColState.stat1_filter_cnt + 1;
1710 + cur_stat_filter_cnt = gStatColState.stat1_filter_cnt;
1711 + global_object[instance_id].group_id = 1;
1713 + case STATCOL_VIP1_P1:
1714 + cur_base_address = stat_coll2_base_address;
1715 + cur_event_mux_req = 0;
1716 + cur_event_mux_resp = 1;
1717 + gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1718 + cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1719 + global_object[instance_id].group_id = 2;
1721 + case STATCOL_VIP1_P2:
1722 + cur_base_address = stat_coll2_base_address;
1723 + cur_event_mux_req = 2;
1724 + cur_event_mux_resp = 3;
1725 + gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1726 + cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1727 + global_object[instance_id].group_id = 2;
1729 + case STATCOL_VIP2_P1:
1730 + cur_base_address = stat_coll2_base_address;
1731 + cur_event_mux_req = 4;
1732 + cur_event_mux_resp = 5;
1733 + gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1734 + cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1735 + global_object[instance_id].group_id = 2;
1737 + case STATCOL_VIP2_P2:
1738 + cur_base_address = stat_coll2_base_address;
1739 + cur_event_mux_req = 6;
1740 + cur_event_mux_resp = 7;
1741 + gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1742 + cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1743 + global_object[instance_id].group_id = 2;
1745 + case STATCOL_VIP3_P1:
1746 + cur_base_address = stat_coll2_base_address;
1747 + cur_event_mux_req = 8;
1748 + cur_event_mux_resp = 9;
1749 + gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1750 + cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1751 + global_object[instance_id].group_id = 2;
1753 + case STATCOL_VIP3_P2:
1754 + cur_base_address = stat_coll2_base_address;
1755 + cur_event_mux_req = 10;
1756 + cur_event_mux_resp = 11;
1757 + gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1758 + cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1759 + global_object[instance_id].group_id = 2;
1761 + case STATCOL_VPE_P1:
1762 + cur_base_address = stat_coll2_base_address;
1763 + cur_event_mux_req = 12;
1764 + cur_event_mux_resp = 13;
1765 + gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1766 + cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1767 + global_object[instance_id].group_id = 2;
1769 + case STATCOL_VPE_P2:
1770 + cur_base_address = stat_coll2_base_address;
1771 + cur_event_mux_req = 14;
1772 + cur_event_mux_resp = 15;
1773 + gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1774 + cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1775 + global_object[instance_id].group_id = 2;
1777 + case STATCOL_EVE1_TC0:
1778 + cur_base_address = stat_coll3_base_address;
1779 + cur_event_mux_req = 0;
1780 + cur_event_mux_resp = 1;
1781 + gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1782 + cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1783 + global_object[instance_id].group_id = 3;
1785 + case STATCOL_EVE1_TC1:
1786 + cur_base_address = stat_coll3_base_address;
1787 + cur_event_mux_req = 2;
1788 + cur_event_mux_resp = 3;
1789 + gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1790 + cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1791 + global_object[instance_id].group_id = 3;
1793 + case STATCOL_EVE2_TC0:
1794 + cur_base_address = stat_coll3_base_address;
1795 + cur_event_mux_req = 4;
1796 + cur_event_mux_resp = 5;
1797 + gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1798 + cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1799 + global_object[instance_id].group_id = 3;
1801 + case STATCOL_EVE2_TC1:
1802 + cur_base_address = stat_coll3_base_address;
1803 + cur_event_mux_req = 6;
1804 + cur_event_mux_resp = 7;
1805 + gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1806 + cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1807 + global_object[instance_id].group_id = 3;
1809 + case STATCOL_EVE3_TC0:
1810 + cur_base_address = stat_coll3_base_address;
1811 + cur_event_mux_req = 8;
1812 + cur_event_mux_resp = 9;
1813 + gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1814 + cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1815 + global_object[instance_id].group_id = 3;
1817 + case STATCOL_EVE3_TC1:
1818 + cur_base_address = stat_coll3_base_address;
1819 + cur_event_mux_req = 10;
1820 + cur_event_mux_resp = 11;
1821 + gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1822 + cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1823 + global_object[instance_id].group_id = 3;
1825 + case STATCOL_EVE4_TC0:
1826 + cur_base_address = stat_coll3_base_address;
1827 + cur_event_mux_req = 12;
1828 + cur_event_mux_resp = 13;
1829 + gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1830 + cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1831 + global_object[instance_id].group_id = 3;
1833 + case STATCOL_EVE4_TC1:
1834 + cur_base_address = stat_coll3_base_address;
1835 + cur_event_mux_req = 14;
1836 + cur_event_mux_resp = 15;
1837 + gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1838 + cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1839 + global_object[instance_id].group_id = 3;
1841 + case STATCOL_DSP1_MDMA:
1842 + cur_base_address = stat_coll4_base_address;
1843 + cur_event_mux_req = 0;
1844 + cur_event_mux_resp = 1;
1845 + gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1846 + cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1847 + global_object[instance_id].group_id = 4;
1849 + case STATCOL_DSP1_EDMA:
1850 + cur_base_address = stat_coll4_base_address;
1851 + cur_event_mux_req = 2;
1852 + cur_event_mux_resp = 3;
1853 + gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1854 + cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1855 + global_object[instance_id].group_id = 4;
1857 + case STATCOL_DSP2_MDMA:
1858 + cur_base_address = stat_coll4_base_address;
1859 + cur_event_mux_req = 4;
1860 + cur_event_mux_resp = 5;
1861 + gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1862 + cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1863 + global_object[instance_id].group_id = 4;
1865 + case STATCOL_DSP2_EDMA:
1866 + cur_base_address = stat_coll4_base_address;
1867 + cur_event_mux_req = 6;
1868 + cur_event_mux_resp = 7;
1869 + gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1870 + cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1871 + global_object[instance_id].group_id = 4;
1874 + cur_base_address = stat_coll4_base_address;
1875 + cur_event_mux_req = 8;
1876 + cur_event_mux_resp = 9;
1877 + gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1878 + cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1879 + global_object[instance_id].group_id = 4;
1881 + case STATCOL_GPU_P1:
1882 + cur_base_address = stat_coll4_base_address;
1883 + cur_event_mux_req = 10;
1884 + cur_event_mux_resp = 11;
1885 + gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1886 + cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1887 + global_object[instance_id].group_id = 4;
1889 + case STATCOL_GPU_P2:
1890 + cur_base_address = stat_coll4_base_address;
1891 + cur_event_mux_req = 12;
1892 + cur_event_mux_resp = 13;
1893 + gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1894 + cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1895 + global_object[instance_id].group_id = 4;
1897 + case STATCOL_BB2D_P1:
1898 + cur_base_address = stat_coll4_base_address;
1899 + cur_event_mux_req = 14;
1900 + cur_event_mux_resp = 15;
1901 + gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1902 + cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1903 + global_object[instance_id].group_id = 4;
1906 + cur_base_address = stat_coll5_base_address;
1907 + cur_event_mux_req = 0;
1908 + cur_event_mux_resp = 1;
1909 + gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1910 + cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1911 + global_object[instance_id].group_id = 5;
1913 + case STATCOL_CSI2_2:
1914 + cur_base_address = stat_coll5_base_address;
1915 + cur_event_mux_req = 2;
1916 + cur_event_mux_resp = 3;
1917 + gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1918 + cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1919 + global_object[instance_id].group_id = 5;
1921 + case STATCOL_MMU2:
1922 + cur_base_address = stat_coll5_base_address;
1923 + cur_event_mux_req = 4;
1924 + cur_event_mux_resp = 5;
1925 + gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1926 + cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1927 + global_object[instance_id].group_id = 5;
1929 + case STATCOL_IPU1:
1930 + cur_base_address = stat_coll5_base_address;
1931 + cur_event_mux_req = 6;
1932 + cur_event_mux_resp = 7;
1933 + gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1934 + cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1935 + global_object[instance_id].group_id = 5;
1937 + case STATCOL_IPU2:
1938 + cur_base_address = stat_coll5_base_address;
1939 + cur_event_mux_req = 8;
1940 + cur_event_mux_resp = 9;
1941 + gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1942 + cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1943 + global_object[instance_id].group_id = 5;
1945 + case STATCOL_DMA_SYSTEM_RD:
1946 + cur_base_address = stat_coll5_base_address;
1947 + cur_event_mux_req = 10;
1948 + cur_event_mux_resp = 11;
1949 + gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1950 + cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1951 + global_object[instance_id].group_id = 5;
1953 + case STATCOL_DMA_SYSTEM_WR:
1954 + cur_base_address = stat_coll5_base_address;
1955 + cur_event_mux_req = 12;
1956 + cur_event_mux_resp = 13;
1957 + gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1958 + cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1959 + global_object[instance_id].group_id = 5;
1961 + case STATCOL_CSI2_1:
1962 + cur_base_address = stat_coll5_base_address;
1963 + cur_event_mux_req = 14;
1964 + cur_event_mux_resp = 15;
1965 + gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1966 + cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1967 + global_object[instance_id].group_id = 5;
1969 + case STATCOL_USB3_SS:
1970 + cur_base_address = stat_coll6_base_address;
1971 + cur_event_mux_req = 0;
1972 + cur_event_mux_resp = 1;
1973 + gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
1974 + cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
1975 + global_object[instance_id].group_id = 6;
1977 + case STATCOL_USB2_SS:
1978 + cur_base_address = stat_coll6_base_address;
1979 + cur_event_mux_req = 2;
1980 + cur_event_mux_resp = 3;
1981 + gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
1982 + cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
1983 + global_object[instance_id].group_id = 6;
1985 + case STATCOL_USB2_ULPI_SS1:
1986 + cur_base_address = stat_coll6_base_address;
1987 + cur_event_mux_req = 4;
1988 + cur_event_mux_resp = 5;
1989 + gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
1990 + cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
1991 + global_object[instance_id].group_id = 6;
1993 + case STATCOL_USB2_ULPI_SS2:
1994 + cur_base_address = stat_coll6_base_address;
1995 + cur_event_mux_req = 6;
1996 + cur_event_mux_resp = 7;
1997 + gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
1998 + cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
1999 + global_object[instance_id].group_id = 6;
2001 + case STATCOL_PCIE_SS1:
2002 + cur_base_address = stat_coll6_base_address;
2003 + cur_event_mux_req = 8;
2004 + cur_event_mux_resp = 9;
2005 + gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
2006 + cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
2007 + global_object[instance_id].group_id = 6;
2009 + case STATCOL_PCIE_SS2:
2010 + cur_base_address = stat_coll6_base_address;
2011 + cur_event_mux_req = 10;
2012 + cur_event_mux_resp = 11;
2013 + gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
2014 + cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
2015 + global_object[instance_id].group_id = 6;
2017 + case STATCOL_DSP1_CFG:
2018 + cur_base_address = stat_coll6_base_address;
2019 + cur_event_mux_req = 12;
2020 + cur_event_mux_resp = 13;
2021 + gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
2022 + cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
2023 + global_object[instance_id].group_id = 6;
2025 + case STATCOL_DSP2_CFG:
2026 + cur_base_address = stat_coll6_base_address;
2027 + cur_event_mux_req = 14;
2028 + cur_event_mux_resp = 15;
2029 + gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
2030 + cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
2031 + global_object[instance_id].group_id = 6;
2033 + case STATCOL_GMAC_SW:
2034 + cur_base_address = stat_coll7_base_address;
2035 + cur_event_mux_req = 0;
2036 + cur_event_mux_resp = 1;
2037 + gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2038 + cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2039 + global_object[instance_id].group_id = 7;
2041 + case STATCOL_PRUSS1_P1:
2042 + cur_base_address = stat_coll7_base_address;
2043 + cur_event_mux_req = 2;
2044 + cur_event_mux_resp = 3;
2045 + gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2046 + cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2047 + global_object[instance_id].group_id = 7;
2049 + case STATCOL_PRUSS1_P2:
2050 + cur_base_address = stat_coll7_base_address;
2051 + cur_event_mux_req = 4;
2052 + cur_event_mux_resp = 5;
2053 + gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2054 + cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2055 + global_object[instance_id].group_id = 7;
2057 + case STATCOL_PRUSS2_P1:
2058 + cur_base_address = stat_coll7_base_address;
2059 + cur_event_mux_req = 6;
2060 + cur_event_mux_resp = 7;
2061 + gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2062 + cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2063 + global_object[instance_id].group_id = 7;
2065 + case STATCOL_PRUSS2_P2:
2066 + cur_base_address = stat_coll7_base_address;
2067 + cur_event_mux_req = 8;
2068 + cur_event_mux_resp = 9;
2069 + gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2070 + cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2071 + global_object[instance_id].group_id = 7;
2073 + case STATCOL_DMA_CRYPTO_RD:
2074 + cur_base_address = stat_coll7_base_address;
2075 + cur_event_mux_req = 10;
2076 + cur_event_mux_resp = 11;
2077 + gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2078 + cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2079 + global_object[instance_id].group_id = 7;
2081 + case STATCOL_DMA_CRYPTO_WR:
2082 + cur_base_address = stat_coll7_base_address;
2083 + cur_event_mux_req = 12;
2084 + cur_event_mux_resp = 13;
2085 + gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2086 + cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2087 + global_object[instance_id].group_id = 7;
2089 + case STATCOL_MPU2:
2090 + cur_base_address = stat_coll7_base_address;
2091 + cur_event_mux_req = 14;
2092 + cur_event_mux_resp = 15;
2093 + gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2094 + cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2095 + global_object[instance_id].group_id = 7;
2097 + case STATCOL_MMC1:
2098 + cur_base_address = stat_coll8_base_address;
2099 + cur_event_mux_req = 0;
2100 + cur_event_mux_resp = 1;
2101 + gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2102 + cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2103 + global_object[instance_id].group_id = 8;
2105 + case STATCOL_MMC2:
2106 + cur_base_address = stat_coll8_base_address;
2107 + cur_event_mux_req = 2;
2108 + cur_event_mux_resp = 3;
2109 + gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2110 + cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2111 + global_object[instance_id].group_id = 8;
2113 + case STATCOL_SATA:
2114 + cur_base_address = stat_coll8_base_address;
2115 + cur_event_mux_req = 4;
2116 + cur_event_mux_resp = 5;
2117 + gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2118 + cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2119 + global_object[instance_id].group_id = 8;
2121 + case STATCOL_MLBSS:
2122 + cur_base_address = stat_coll8_base_address;
2123 + cur_event_mux_req = 6;
2124 + cur_event_mux_resp = 7;
2125 + gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2126 + cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2127 + global_object[instance_id].group_id = 8;
2129 + case STATCOL_BB2D_P2:
2130 + cur_base_address = stat_coll8_base_address;
2131 + cur_event_mux_req = 8;
2132 + cur_event_mux_resp = 9;
2133 + gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2134 + cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2135 + global_object[instance_id].group_id = 8;
2137 + case STATCOL_IEEE1500:
2138 + cur_base_address = stat_coll8_base_address;
2139 + cur_event_mux_req = 10;
2140 + cur_event_mux_resp = 11;
2141 + gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2142 + cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2143 + global_object[instance_id].group_id = 8;
2146 + cur_base_address = stat_coll8_base_address;
2147 + cur_event_mux_req = 12;
2148 + cur_event_mux_resp = 13;
2149 + gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2150 + cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2151 + global_object[instance_id].group_id = 8;
2153 + case STATCOL_VCP1:
2154 + cur_base_address = stat_coll8_base_address;
2155 + cur_event_mux_req = 14;
2156 + cur_event_mux_resp = 15;
2157 + gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2158 + cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2159 + global_object[instance_id].group_id = 8;
2161 + case STATCOL_OCMC_RAM1:
2162 + cur_base_address = stat_coll9_base_address;
2163 + cur_event_mux_req = 0;
2164 + cur_event_mux_resp = 1;
2165 + gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2166 + cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2167 + global_object[instance_id].group_id = 9;
2169 + case STATCOL_OCMC_RAM2:
2170 + cur_base_address = stat_coll9_base_address;
2171 + cur_event_mux_req = 2;
2172 + cur_event_mux_resp = 3;
2173 + gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2174 + cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2175 + global_object[instance_id].group_id = 9;
2177 + case STATCOL_OCMC_RAM3:
2178 + cur_base_address = stat_coll9_base_address;
2179 + cur_event_mux_req = 4;
2180 + cur_event_mux_resp = 5;
2181 + gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2182 + cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2183 + global_object[instance_id].group_id = 9;
2185 + case STATCOL_GPMC:
2186 + cur_base_address = stat_coll9_base_address;
2187 + cur_event_mux_req = 6;
2188 + cur_event_mux_resp = 7;
2189 + gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2190 + cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2191 + global_object[instance_id].group_id = 9;
2193 + case STATCOL_MCASP1:
2194 + cur_base_address = stat_coll9_base_address;
2195 + cur_event_mux_req = 8;
2196 + cur_event_mux_resp = 9;
2197 + gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2198 + cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2199 + global_object[instance_id].group_id = 9;
2201 + case STATCOL_MCASP2:
2202 + cur_base_address = stat_coll9_base_address;
2203 + cur_event_mux_req = 10;
2204 + cur_event_mux_resp = 11;
2205 + gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2206 + cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2207 + global_object[instance_id].group_id = 9;
2209 + case STATCOL_MCASP3:
2210 + cur_base_address = stat_coll9_base_address;
2211 + cur_event_mux_req = 12;
2212 + cur_event_mux_resp = 13;
2213 + gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2214 + cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2215 + global_object[instance_id].group_id = 9;
2217 + case STATCOL_VCP2:
2218 + cur_base_address = stat_coll9_base_address;
2219 + cur_event_mux_req = 14;
2220 + cur_event_mux_resp = 15;
2221 + gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2222 + cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2223 + global_object[instance_id].group_id = 9;
2226 + printf("ERROR: Unknown initiator %d\n", instance_id);
2231 + if ( cur_stat_filter_cnt > 4 )
2233 + printf("WARNING: We have exhausted filters/counters.....\n");
2236 + // Global Enable Stat Collector
2237 + wr_stat_reg(cur_base_address+0x8,0x1);
2239 + // Soft Enable Stat Collector
2240 + wr_stat_reg(cur_base_address+0xC,0x1);
2242 + wr_stat_reg(cur_base_address+0x18,0x5);
2243 + // Operation of Stat Collector / RespEvt => Packet
2244 + wr_stat_reg(cur_base_address+0x1C,0x5);
2248 + wr_stat_reg(cur_base_address+0x20+4*(cur_stat_filter_cnt-1),cur_event_mux_req);
2250 + // Op is EventInfo
2251 + wr_stat_reg(cur_base_address+0x1FC+(0x158*(cur_stat_filter_cnt-1)),2);
2253 + // Event Info Sel Op -> packet length
2254 + wr_stat_reg(cur_base_address+0x1F8+(0x158*(cur_stat_filter_cnt-1)),0);
2256 + // Filter Global Enable
2257 + wr_stat_reg(cur_base_address+0xAC+(0x158*(cur_stat_filter_cnt-1)),0x1);
2260 + wr_stat_reg(cur_base_address+0xBC+(0x158*(cur_stat_filter_cnt-1)),0x1);
2263 + wr_stat_reg(cur_base_address+0x54,0x1);
2264 + // use send register to reset counters
2268 + global_object[instance_id].mux_req = cur_event_mux_req;
2269 + global_object[instance_id].base_address = cur_base_address;
2270 + global_object[instance_id].counter_id = cur_stat_filter_cnt;
2271 + global_object[instance_id].b_enabled = 1;
2273 + return cur_stat_filter_cnt;
2278 +void statCollectorReadGroup(UInt32 group_id)
2281 + UInt32 cur_base_address = 0x45001000 + ((group_id - 1) * 0x1000);
2283 + wr_stat_reg(cur_base_address+0xC,0x0);
2285 + for(i=0; i < STATCOL_MAX; i++)
2287 + if(global_object[i].group_id == (group_id - 1) &&
2288 + global_object[i].b_enabled == 1)
2290 + UInt32 cur_stat_filter_cnt = global_object[i].counter_id;
2292 + global_object[i].readings[statCountIdx] = rd_stat_reg(cur_base_address+0x8C+((cur_stat_filter_cnt-1)*4));
2296 + wr_stat_reg(cur_base_address+0xC,0x1);
2300 +volatile sig_atomic_t sigtermed = 0;
2302 +void my_signal_handler(int signum)
2304 + if (signum == SIGTERM || signum == SIGINT) {
2317 +struct time_graph_create_params p;
2318 +char xpos_string[100], ypos_string[100];
2320 +void mpu_handler(int command)
2325 + char * tabledata= "/tmp/statcollfifo";
2328 + static int offset = 13;
2333 + fd = open(tabledata, O_RDONLY|O_NONBLOCK);
2338 + /* open, read, and display the message from the FIFO */
2339 + bytes=read(fd, buf, 1000);
2344 + sscanf(buf, "%s %s", str, value);
2345 + if(strcmp(str, "MOVE:") == 0)
2347 + printf("Received MOVE command : %s\n", buf);
2348 + sprintf(p.title, "CPU Usage[@position-req=%sx%s]", value, ypos_string);
2349 + move_graph(ctx, &p);
2353 + printf("ERROR: Received unexpected data from FIFO - \" %s \" \n", buf);
2355 + memset(buf, 0x0, sizeof(buf));
2369 +UInt32 statcoll_start(UInt32 TOTAL_TIME, UInt32 INTERVAL_US, char list[][50], UInt32 xpos, UInt32 ypos)
2372 + UInt32 counterIdDss, counterIdIva, counterIdBB2dP1, counterIdBB2dP2, counterIdUsb4, counterIdSata, counterIdEmif1, counterIdEmif2;
2374 + if (SIG_ERR == signal(SIGPIPE,SIG_IGN))
2377 + if (SIG_ERR == signal(SIGINT,my_signal_handler))
2380 + if (SIG_ERR == signal(SIGTERM,my_signal_handler))
2384 + struct timeval tv1, tv2;
2385 + gettimeofday(&tv1, NULL);
2386 + printf("------------------------------------------------\n");
2387 + printf("Compile time = %s %s\n",__DATE__, __TIME__);
2388 + printf("------------------------------------------------\n\n");
2389 + //printd("Start time = %d\n", time(NULL));
2390 + //printd("Time seconds = %d, usecs = %d\n", tv.tv_sec, tv.tv_usec);
2392 + statcoll_params params;
2393 + memset(¶ms, sizeof(params), 0);
2394 + params.INTERVAL_US = INTERVAL_US;
2395 + params.TOTAL_TIME = TOTAL_TIME;
2400 + while(list[i][0] != 0)
2402 + for(index=0; index< STATCOL_MAX; index++) {
2403 + if(strcmp(list[i], initiators[index].name) == 0)
2405 + strcpy(params.user_config_list[params.no_of_initiators].name, list[i]);
2406 + params.user_config_list[params.no_of_initiators++].id = initiators[index].id;
2411 + if(index == STATCOL_MAX) {
2412 + printf("ERROR: Unknown initiator.%d.. .%s. \n", i, list[i]);
2418 + struct bar_graph_create_params bg_p;
2419 + struct _y_config *y_cfg;
2420 + struct _text_config *t_cfg;
2423 + char *text_list[STATCOL_MAX];
2425 + struct _bar_graph_y_config *bg_y_cfg;
2426 + struct _text_config *bg_t_cfg;
2427 + char *bg_text_list[STATCOL_MAX];
2429 + sprintf(xpos_string, "%d", xpos);
2430 + sprintf(ypos_string, "%d", ypos);
2431 + p.title=(char *)malloc(100);
2432 + sprintf(p.title, "CPU Usage[@position-req=%sx%s]", xpos_string, ypos_string);
2433 + //p.height = MAX_HEIGHT - HEIGHT_EMIF_AREA;
2434 + p.height = MAX_HEIGHT;// - HEIGHT_EMIF_AREA;
2435 + p.width = MAX_WIDTH;
2436 + p.draw_area.bottom_left.x = TIME_GRAPH_AREA_BL_X;
2437 + p.draw_area.bottom_left.y = TIME_GRAPH_AREA_BL_Y;
2438 + p.draw_area.top_right.x = TIME_GRAPH_AREA_TR_X;
2439 + p.draw_area.top_right.y = TIME_GRAPH_AREA_TR_Y;
2440 + p.time_span = 120000; // 120 seconds
2441 + p.num_of_y_items = params.no_of_initiators+1;
2442 + p.num_of_text_items = 0;//params.no_of_initiators;
2445 + y_cfg = malloc((params.no_of_initiators+1) * sizeof(struct _y_config));
2446 + t_cfg = malloc(params.no_of_initiators * sizeof(struct _text_config));
2447 + y = malloc((params.no_of_initiators+1) * sizeof(double));
2448 + p.y_config_array = y_cfg;
2449 + p.text_config_array = t_cfg;
2451 + bg_y_cfg = malloc(TOTAL_Y_PARAMETERS * sizeof(struct _bar_graph_y_config));
2452 + bg_t_cfg = malloc(TOTAL_Y_PARAMETERS * sizeof(struct _text_config));
2453 + bg_y = malloc(TOTAL_Y_PARAMETERS * sizeof(double));
2455 + for(i=0; i<TOTAL_Y_PARAMETERS; i++)
2457 + bg_text_list[i] = malloc(100);
2458 + strcpy(bg_text_list[i],"test");
2461 + create_overall_box(bg_y_cfg, bg_t_cfg, bg_text_list);
2465 + while(i < params.no_of_initiators)
2467 + text_list[i] = malloc(100 * sizeof(char));
2468 + memset(text_list[i], 0x0, 100);
2470 + ((struct _y_config *)y_cfg+i)->line_color.r = pallette[i%MAX_COLORS].r;
2471 + ((struct _y_config *)y_cfg+i)->line_color.g = pallette[i%MAX_COLORS].g;
2472 + ((struct _y_config *)y_cfg+i)->line_color.b = pallette[i%MAX_COLORS].b;
2473 + ((struct _y_config *)y_cfg+i)->line_color.a = 0.0;//pallette[i%MAX_COLORS].a;
2475 + ((struct _y_config *)y_cfg+i)->fill_color.r = 0.0;
2476 + ((struct _y_config *)y_cfg+i)->fill_color.g = 1.0;
2477 + ((struct _y_config *)y_cfg+i)->fill_color.b = 0.0;
2478 + ((struct _y_config *)y_cfg+i)->fill_color.a = 0.5;
2483 + ((struct _y_config *)y_cfg+i)->line_color.r = 0.0;
2484 + ((struct _y_config *)y_cfg+i)->line_color.g = 0.0;
2485 + ((struct _y_config *)y_cfg+i)->line_color.b = 0.0;
2486 + ((struct _y_config *)y_cfg+i)->line_color.a = 0.5;
2487 + ((struct _y_config *)y_cfg+i)->fill_color.r = 0.1;
2488 + ((struct _y_config *)y_cfg+i)->fill_color.g = 0.9;
2489 + ((struct _y_config *)y_cfg+i)->fill_color.b = 0.5;
2490 + ((struct _y_config *)y_cfg+i)->fill_color.a = 1.0;
2492 + bg_p.title = "CPU Usage";
2494 + bg_p.num_of_y_items = TOTAL_Y_PARAMETERS;
2495 + bg_p.y_config_array = bg_y_cfg;
2496 + bg_p.num_of_text_items = TOTAL_Y_PARAMETERS;
2497 + bg_p.text_config_array = bg_t_cfg;
2502 + ctx = time_graph_create(argc, argv, &p);
2504 + printf("Error creating context\n");
2508 + printf("\n Context after time_graph_create = 0x%x\n", ctx);
2509 + ctx = bar_graph_create(argc, argv, &bg_p);
2511 + printf("Error creating context\n");
2515 + printf("\n Context after bar_graph_create= 0x%x\n", ctx);
2517 + printf("Total configured initiators = %d\n", params.no_of_initiators);
2520 + fd = open("/dev/mem", O_RDWR);
2522 + printf("error fd=open() \n");
2525 + statcoll_base_mem = mmap(NULL, STATCOLL_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, STATCOLL_BASE);
2527 + if (statcoll_base_mem == MAP_FAILED){
2528 + printf("ERROR: mmap failed \n");
2533 + fd = open("/dev/mem", O_RDWR);
2535 + printf("error fd=open() \n");
2538 + l3_3_clkctrl = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, CM_L3INSTR_REGISTER_BASE);
2539 + if (l3_3_clkctrl == MAP_FAILED){
2540 + printf("ERROR: mmap failed for CM_L3INSTR_REGISTER_BASE\n");
2545 + printf("SUCCESS: Mapped 0x%x to user space address 0x%x\n", STATCOLL_BASE, statcoll_base_mem);
2546 + printf("INTERVAL = %d usecs\n", INTERVAL_US);
2547 + printf("TOTAL TIME = %d seconds\n", TOTAL_TIME);
2548 + TRACE_SZ = (TOTAL_TIME * 1000000)/INTERVAL_US;
2549 + printf("TRACE SIZE = %d samples\n", TRACE_SZ);
2551 + printf("**************************************\n");
2552 + printf("Going to initialize the L3 clocks \n");
2553 + l3_3_clkctrl[CM_L3INSTR_L3INSTR_CLKSTCTRL_OFFSET >> 2] = 0x2;
2554 + l3_3_clkctrl[CM_L3INSTR_L3_MAIN_2_CLKCTRL_OFFSET >> 2] = 0x1;
2555 + printf("**************************************\n");
2557 + while( (l3_3_clkctrl[CM_L3INSTR_L3_MAIN_2_CLKCTRL_OFFSET >> 2] & 0x30000) != 0x0)
2559 + printf("Waiting on module to be functional\n");
2562 + statCollectorInit();
2564 + printf("SUCCESS: Initialized STAT COLLECTOR\n");
2565 + /* Initialize all enabled initiators */
2566 + for(index =0; index < params.no_of_initiators; index++) {
2567 + printf("\t\t Initialized %s\n", params.user_config_list[index].name);
2568 + statCollectorControlInitialize(params.user_config_list[index].id);
2571 + const char *bg_text = "CPU Utilization";
2573 + int second_counter=0;
2574 + memset(y, 0x0, sizeof(double)* (params.no_of_initiators+1));
2579 + mpu_handler(OPEN);
2582 + while(statCountIdx != (TRACE_SZ - 1))
2584 + usleep(INTERVAL_US);
2586 + for(group = 1; group<11; group++)
2587 + statCollectorReadGroup(group);
2589 + mpu_handler(READ);
2591 + if(statCountIdx != 0 )
2592 + for(i=0; i<params.no_of_initiators; i++) {
2593 + y[i] += (double)(global_object[params.user_config_list[i].id].readings[statCountIdx])/ (8000000000);
2597 + if(second_counter % 30 == 0)
2600 + for(i=0; i<TOTAL_Y_PARAMETERS; i++) {
2607 + sprintf(bg_text_list[8], "%02.1f%s", y[0]*100, "%");
2608 + sprintf(bg_text_list[10], "%02.1f%s", y[1]*100, "%");
2610 + struct sort sort_array[STATCOL_MAX];
2611 + memset(sort_array, 0x0, sizeof(struct sort) * STATCOL_MAX);
2613 + for(i=2; i<params.no_of_initiators; i++) {
2614 + sort_array[i-2].value = y[i];
2615 + sort_array[i-2].pos = i;
2619 + double tempdouble;
2621 + for(i=0; i<params.no_of_initiators-2; i++) {
2622 + for(j=i+1; j<params.no_of_initiators-2; j++) {
2623 + if(sort_array[i].value < sort_array[j].value) {
2624 + tempdouble = sort_array[j].value;
2625 + tempint = sort_array[j].pos;
2627 + sort_array[j].value = sort_array[i].value;
2628 + sort_array[j].pos = sort_array[i].pos;
2630 + sort_array[i].value = tempdouble;
2631 + sort_array[i].pos = tempint;
2636 + for(i=0; i<6; i++)
2639 + bg_y[14+i*2] = sort_array[i].value*2;
2640 + sprintf(bg_text_list[13+i*2], "%02.1f%s", sort_array[i].value*100, "%");
2641 + sprintf(bg_text_list[14+i*2], "%s", (params.user_config_list[sort_array[i].pos].name)+8);
2644 + bar_graph_plot(ctx, bg_y, (const char **)bg_text_list);
2646 + y[params.no_of_initiators]=y[0]+y[1];
2647 + time_graph_plot(ctx, y, (const char **)text_list);
2648 + //printf("Plotting the time_graph\n");
2649 + memset(y, 0x0, sizeof(double)* (params.no_of_initiators+1));
2655 + mpu_handler(CLOSE);
2657 + printf("------------------------------------------------\n\n");
2658 + printf("SUCCESS: Stat collection completed... Writing into file now\n");
2659 + FILE *outfile = fopen("statcollector.csv", "w+");
2661 + printf("\n ERROR: Error opening file");
2664 + /* Ignore the first index at 0 */
2665 + for(index=1; index<statCountIdx; index++) {
2666 + for(i=0; i<params.no_of_initiators; i++) {
2667 + fprintf(outfile,"%s = %d,", params.user_config_list[i].name, global_object[params.user_config_list[i].id].readings[index]);
2669 + fprintf(outfile,"\n");
2673 + time_graph_destroy(ctx);
2674 + gettimeofday(&tv2, NULL);
2675 + //printf("End time = %d\n", time(NULL));
2676 + //printf("Time seconds = %d, usecs = %d\n", tv.tv_sec, tv.tv_usec);
2677 + printf("Total execution time = %d secs, %d usecs\n\n", (tv2.tv_sec - tv1.tv_sec), (tv2.tv_usec - tv2.tv_usec));
2683 diff --git a/clients/statcoll.h b/clients/statcoll.h
2684 new file mode 100644
2685 index 0000000..fa92753
2687 +++ b/clients/statcoll.h
2689 +#ifndef __STATCOLL_H
2690 +#define __STATCOLL_H
2693 +#define CM_L3INSTR_REGISTER_BASE (0x4A008000)
2695 +#define CM_L3INSTR_L3INSTR_CLKSTCTRL_OFFSET (0xE00)
2696 +#define CM_L3INSTR_L3_MAIN_2_CLKCTRL_OFFSET (0xE20)
2698 +#define STATCOLL_SIZE 40960
2699 +#define STATCOLL_BASE (0x45001000)
2701 +#define stat_coll0_base_address (0x45001000)
2702 +#define stat_coll1_base_address (0x45002000)
2703 +#define stat_coll2_base_address (0x45003000)
2704 +#define stat_coll3_base_address (0x45004000)
2705 +#define stat_coll4_base_address (0x45005000)
2706 +#define stat_coll5_base_address (0x45006000)
2707 +#define stat_coll6_base_address (0x45007000)
2708 +#define stat_coll7_base_address (0x45008000)
2709 +#define stat_coll8_base_address (0x45009000)
2710 +#define stat_coll9_base_address (0x4500a000)
2712 +#define printd(fmt, ...) \
2713 + do { if (debug) fprintf(stderr, fmt, __VA_ARGS__); } while (0)
2715 +typedef unsigned int UInt32;
2720 + STATCOL_EMIF1_SYS,
2721 + STATCOL_EMIF2_SYS,
2722 + STATCOL_MA_MPU_P1,
2723 + STATCOL_MA_MPU_P2,
2746 + STATCOL_DSP1_MDMA,
2747 + STATCOL_DSP1_EDMA,
2748 + STATCOL_DSP2_MDMA,
2749 + STATCOL_DSP2_EDMA,
2759 + STATCOL_DMA_SYSTEM_RD,
2760 + STATCOL_DMA_SYSTEM_WR,
2764 + STATCOL_USB2_ULPI_SS1,
2765 + STATCOL_USB2_ULPI_SS2,
2771 + STATCOL_PRUSS1_P1,
2772 + STATCOL_PRUSS1_P2,
2773 + STATCOL_PRUSS2_P1,
2774 + STATCOL_PRUSS2_P2,
2775 + STATCOL_DMA_CRYPTO_RD,
2776 + STATCOL_DMA_CRYPTO_WR,
2786 + STATCOL_OCMC_RAM1,
2787 + STATCOL_OCMC_RAM2,
2788 + STATCOL_OCMC_RAM3,
2801 + UInt32 stat0_filter_cnt;
2802 + UInt32 stat1_filter_cnt;
2803 + UInt32 stat2_filter_cnt;
2804 + UInt32 stat3_filter_cnt;
2805 + UInt32 stat4_filter_cnt;
2806 + UInt32 stat5_filter_cnt;
2807 + UInt32 stat6_filter_cnt;
2808 + UInt32 stat7_filter_cnt;
2809 + UInt32 stat8_filter_cnt;
2810 + UInt32 stat9_filter_cnt;
2811 +} StatCollectorObj;
2813 +struct list_of_initiators
2821 + UInt32 INTERVAL_US;
2822 + UInt32 TOTAL_TIME;
2823 + UInt32 no_of_initiators;
2824 + struct list_of_initiators user_config_list[STATCOL_MAX];
2832 + UInt32 *timestamp;
2834 + UInt32 counter_id;
2835 + UInt32 base_address;
2837 +}statcoll_initiators_object;
2841 diff --git a/clients/statcoll_gui.h b/clients/statcoll_gui.h
2842 new file mode 100644
2843 index 0000000..7362bde
2845 +++ b/clients/statcoll_gui.h
2850 + ---------------------------------------------
2852 + | --------------------------------------- |
2868 + ---------------------------------------------
2875 + ---------------------------------------------
2881 +#define POSITION_X 2800
2882 +#define POSITION_Y 40
2884 +#define MAX_WIDTH 900
2885 +//#define MAX_WIDTH 528
2886 +#define MAX_HEIGHT 900
2888 +/* Derived parameters */
2889 +#define BAR_GAP (MAX_WIDTH/25)
2890 +#define BAR_WIDTH (MAX_WIDTH/16)
2892 +#define BAR_HEIGHT ((MX_HEIGHT/40) * 6)
2894 +#define BORDER (MAX_WIDTH/15)
2896 +#define HEIGHT_EMIF_AREA (MAX_HEIGHT/4)
2898 +#define FONT_SIZE (MAX_WIDTH/40)
2900 +#define WIDTH_EMIF_AREA (MAX_WIDTH / 4)
2902 +#define TOTAL_Y_PARAMETERS (25)
2904 +#define TIME_GRAPH_AREA_BL_X (BORDER)
2905 +#define TIME_GRAPH_AREA_BL_Y (MAX_HEIGHT - HEIGHT_EMIF_AREA - BORDER)
2906 +#define TIME_GRAPH_AREA_TR_X (MAX_WIDTH - BORDER)
2907 +#define TIME_GRAPH_AREA_TR_Y (BORDER)
2909 +#define EMIF_AREA_BL_X (0)
2910 +#define EMIF_AREA_BL_Y (MAX_HEIGHT)
2911 +#define EMIF_AREA_TR_X (WIDTH_EMIF_AREA)
2912 +#define EMIF_AREA_TR_Y (MAX_HEIGHT - HEIGHT_EMIF_AREA)
2914 +#define INITIATORS_AREA_BL_X (WIDTH_EMIF_AREA)
2915 +#define INITIATORS_AREA_BL_Y (MAX_HEIGHT)
2916 +#define INITIATORS_AREA_TR_X (MAX_WIDTH)
2917 +#define INITIATORS_AREA_TR_Y (MAX_HEIGHT - HEIGHT_EMIF_AREA)
2920 +const char *string_list[TOTAL_Y_PARAMETERS] = {
2921 + "----DDR BANDWIDTH PLOT----",
2933 + "TOP 6 INITIATORS",
2948 diff --git a/clients/time_bar_graph.c b/clients/time_bar_graph.c
2949 new file mode 100644
2950 index 0000000..9fa9c12
2952 +++ b/clients/time_bar_graph.c
2955 + * Copyright © 2008 Kristian Høgsberg
2957 + * Permission to use, copy, modify, distribute, and sell this software and its
2958 + * documentation for any purpose is hereby granted without fee, provided that
2959 + * the above copyright notice appear in all copies and that both that copyright
2960 + * notice and this permission notice appear in supporting documentation, and
2961 + * that the name of the copyright holders not be used in advertising or
2962 + * publicity pertaining to distribution of the software without specific,
2963 + * written prior permission. The copyright holders make no representations
2964 + * about the suitability of this software for any purpose. It is provided "as
2965 + * is" without express or implied warranty.
2967 + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
2968 + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
2969 + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
2970 + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
2971 + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
2972 + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
2973 + * OF THIS SOFTWARE.
2976 +#include <stdint.h>
2978 +#include <stdlib.h>
2979 +#include <string.h>
2980 +#include <stdint.h>
2981 +#include <signal.h>
2985 +#include <sys/time.h>
2986 +#include <pthread.h>
2988 +#include <unistd.h>
2989 +#include <sys/eventfd.h>
2990 +#include <sys/epoll.h>
2992 +#include <linux/input.h>
2993 +#include <wayland-client.h>
2994 +#include "window.h"
2995 +#include "../shared/cairo-util.h"
2996 +#include "time_bar_graph.h"
3000 +#define DBG(x...) printf(x)
3002 +#define DBG(x...) // printf(x)
3005 +#define MAX_ITEMS 180
3006 +#define MAX_TEXT_SIZE 128
3008 +struct graph_dataset_point {
3010 + double y_values[MAX_ITEMS];
3013 +struct graph_data {
3015 + int first_index, last_index, num_elems;
3016 + uint64_t last_time;
3017 + struct graph_dataset_point dataset[1];
3021 + struct display *display;
3022 + struct window *window;
3023 + struct widget *widget;
3024 + int width, height;
3025 + struct time_graph_create_params params;
3026 + struct bar_graph_create_params bar_graph_params;
3027 + struct _y_config y_config_array[MAX_ITEMS];
3028 + struct _text_config text_config_array[MAX_ITEMS];
3030 + /* Bar graph parameters */
3031 + struct _bar_graph_y_config bar_graph_y_config_array[MAX_ITEMS];
3032 + struct _text_config bar_graph_text_config_array[MAX_ITEMS];
3037 + double x_scaling_factor;
3038 + pthread_mutex_t mtx;
3039 + double time_graph_y_values[MAX_ITEMS];
3040 + char text_values[MAX_ITEMS][MAX_TEXT_SIZE];
3042 + double bar_graph_y_values[MAX_ITEMS];
3043 + char bar_graph_text_values[MAX_ITEMS][MAX_TEXT_SIZE];
3045 + uint64_t time_now;
3046 + time_t start_time_tv_sec;
3047 + struct graph_data *data;
3050 +struct graph *global_graph=NULL;
3052 +draw_stuff(struct graph *g, cairo_surface_t *surface)
3055 + int i, j, n_elems;
3056 + double c_x, c_y, d_x, d_y;
3058 + cr = cairo_create(surface);
3059 + cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
3060 + cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.5);
3062 + cairo_select_font_face(cr, "mono",
3063 + CAIRO_FONT_SLANT_NORMAL,
3064 + CAIRO_FONT_WEIGHT_BOLD);
3065 + cairo_set_line_width (cr, 1.0);
3066 + cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
3067 + pthread_mutex_lock(&g->mtx);
3068 + for (j=0; g->data->num_elems > 0 && j<g->params.num_of_y_items; j++) {
3069 + n_elems = g->data->num_elems;
3070 + DBG("first_index: %d, last_index: %d\n", g->data->first_index, g->data->last_index);
3071 + if (g->y_config_array[j].fill_color.a != 0.0)
3072 + cairo_move_to(cr, (double)g->params.draw_area.bottom_left.x, (double)g->params.draw_area.bottom_left.y);
3073 + c_x = (double)g->params.draw_area.bottom_left.x;
3074 + c_y = (double)g->params.draw_area.bottom_left.y;
3076 + i = g->data->first_index;
3078 + DBG("index: %d, x: %f, y: %f, next_index: %d\n", i, c_x,
3079 + g->data->dataset[i].y_values[j], g->data->dataset[i].next_index);
3080 + d_y = g->data->dataset[i].y_values[j] - c_y;
3081 + c_y = g->data->dataset[i].y_values[j];
3083 + if (g->y_config_array[j].fill_color.a == 0.0 && n_elems == g->data->num_elems) {
3084 + cairo_move_to(cr, c_x, c_y);
3086 + cairo_curve_to(cr, c_x - (d_x * 0.75), c_y - (d_y * 0.92), c_x - (d_x * 0.25), c_y - (d_y * 0.08), c_x, c_y);
3088 + if (g->data->dataset[i].next_index > i) {
3089 + d_x = (g->data->dataset[i].next_index - i);
3091 + d_x = (g->data->dataset_size + g->data->dataset[i].next_index - i);
3093 + i = g->data->dataset[i].next_index;
3096 + if (g->y_config_array[j].fill_color.a != 0.0) {
3097 + cairo_line_to(cr, c_x, (double)g->params.draw_area.bottom_left.y);
3098 + cairo_line_to(cr, (double)g->params.draw_area.bottom_left.x, (double)g->params.draw_area.bottom_left.y);
3099 + cairo_close_path(cr);
3100 + cairo_set_source_rgba(cr, g->y_config_array[j].fill_color.r, g->y_config_array[j].fill_color.g,
3101 + g->y_config_array[j].fill_color.b, g->y_config_array[j].fill_color.a);
3102 + cairo_fill_preserve(cr);
3104 + cairo_set_source_rgba(cr, g->y_config_array[j].line_color.r, g->y_config_array[j].line_color.g,
3105 + g->y_config_array[j].line_color.b, g->y_config_array[j].line_color.a);
3109 + for (j=0; j<g->params.num_of_text_items; j++) {
3110 + cairo_move_to(cr, (double)g->text_config_array[j].at.x, (double)g->text_config_array[j].at.y);
3111 + cairo_set_font_size(cr, g->text_config_array[j].fontsize);
3112 + cairo_set_source_rgba(cr, g->text_config_array[j].color.r, g->text_config_array[j].color.g,
3113 + g->text_config_array[j].color.b, g->text_config_array[j].color.a);
3114 + cairo_show_text(cr, g->text_values[j]);
3118 + for (j=0; j<g->bar_graph_params.num_of_y_items; j++) {
3119 + cairo_move_to(cr, (double)g->bar_graph_params.y_config_array[j].region.bottom_left.x,
3120 + (double)g->bar_graph_params.y_config_array[j].region.bottom_left.y);
3121 + c_y = (double)g->bar_graph_params.y_config_array[j].region.bottom_left.y -
3122 + (g->bar_graph_y_values[j] * (double)(g->bar_graph_params.y_config_array[j].region.bottom_left.y -
3123 + g->bar_graph_params.y_config_array[j].region.top_right.y));
3124 + cairo_line_to(cr, (double)g->bar_graph_params.y_config_array[j].region.bottom_left.x, c_y);
3125 + cairo_line_to(cr, (double)g->bar_graph_params.y_config_array[j].region.top_right.x, c_y);
3126 + cairo_line_to(cr, (double)g->bar_graph_params.y_config_array[j].region.top_right.x,
3127 + (double)g->bar_graph_params.y_config_array[j].region.bottom_left.y);
3128 + cairo_line_to(cr, (double)g->bar_graph_params.y_config_array[j].region.bottom_left.x,
3129 + (double)g->bar_graph_params.y_config_array[j].region.bottom_left.y);
3130 + cairo_close_path(cr);
3131 + cairo_set_source_rgba(cr, g->bar_graph_y_config_array[j].fill_color.r, g->bar_graph_y_config_array[j].fill_color.g,
3132 + g->bar_graph_y_config_array[j].fill_color.b, g->bar_graph_y_config_array[j].fill_color.a);
3133 + cairo_fill_preserve(cr);
3134 + cairo_set_source_rgba(cr, g->bar_graph_y_config_array[j].line_color.r, g->bar_graph_y_config_array[j].line_color.g,
3135 + g->bar_graph_y_config_array[j].line_color.b, g->bar_graph_y_config_array[j].line_color.a);
3138 + for (j=0; j<g->bar_graph_params.num_of_text_items; j++) {
3139 + cairo_move_to(cr, (double)g->bar_graph_text_config_array[j].at.x, (double)g->bar_graph_text_config_array[j].at.y);
3140 + cairo_set_font_size(cr, g->bar_graph_text_config_array[j].fontsize);
3141 + cairo_set_source_rgba(cr, g->bar_graph_text_config_array[j].color.r, g->bar_graph_text_config_array[j].color.g,
3142 + g->bar_graph_text_config_array[j].color.b, g->bar_graph_text_config_array[j].color.a);
3144 + //cairo_rotate(cr, 2*3.14*21/24);
3145 + cairo_show_text(cr, g->bar_graph_text_values[j]);
3146 + cairo_restore(cr);
3148 + pthread_mutex_unlock(&g->mtx);
3149 + cairo_destroy(cr);
3153 +resize_handler(struct widget *widget,
3154 + int32_t width, int32_t height, void *data)
3156 + struct graph *g = data;
3158 + /* Dont resize me */
3159 + widget_set_size(g->widget, g->width, g->height);
3163 +redraw_handler(struct widget *widget, void *data)
3165 + struct graph *g = data;
3166 + cairo_surface_t *surface;
3168 + surface = window_get_surface(g->window);
3169 + if (surface == NULL ||
3170 + cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
3171 + fprintf(stderr, "failed to create cairo egl surface\n");
3175 + draw_stuff(g, surface);
3176 + cairo_surface_destroy(surface);
3180 +button_handler(struct widget *widget,
3181 + struct input *input, uint32_t time,
3182 + uint32_t button, enum wl_pointer_button_state state, void *data)
3184 + struct graph *g = data;
3188 + if (state == WL_POINTER_BUTTON_STATE_PRESSED)
3189 + window_move(g->window, input,
3190 + display_get_serial(g->display));
3193 + if (state == WL_POINTER_BUTTON_STATE_PRESSED)
3194 + widget_schedule_redraw(widget);
3197 + if (state == WL_POINTER_BUTTON_STATE_PRESSED)
3198 + window_show_frame_menu(g->window, input, time);
3204 +touch_down_handler(struct widget *widget, struct input *input,
3205 + uint32_t serial, uint32_t time, int32_t id,
3206 + float x, float y, void *data)
3208 + struct graph *g = data;
3209 + window_move(g->window, input, display_get_serial(g->display));
3212 +static void task_run(struct task *task, uint32_t events)
3215 + struct graph *g = (struct graph *)(task->link.prev);
3216 + uint64_t time_diff;
3217 + int elems, tmp, incr, i;
3220 + eventfd_read(g->eventfd, &e);
3222 + pthread_mutex_lock(&g->mtx);
3223 + /* Process new data */
3224 + DBG("time_now: %llu, last_time: %llu\n", g->time_now, g->data->last_time);
3225 + if (g->time_now > g->data->last_time) {
3226 + time_diff = g->time_now - g->data->last_time;
3227 + y = (double)time_diff * g->x_scaling_factor;
3229 + DBG("incr: %d\n", incr);
3231 + if (g->data->last_index >= g->data->first_index) elems = g->data->last_index - g->data->first_index + 1;
3232 + else elems = g->data->dataset_size - g->data->first_index + g->data->last_index + 1;
3233 + /* Move first index to make room for new element */
3234 + while (g->data->dataset_size > 0 && (elems + incr) > g->data->dataset_size) {
3235 + tmp = g->data->dataset[g->data->first_index].next_index - g->data->first_index;
3236 + if (tmp < 0) tmp = g->data->dataset_size + tmp;
3237 + g->data->first_index = g->data->dataset[g->data->first_index].next_index;
3239 + g->data->num_elems--;
3241 + for (i=0; i<g->params.num_of_y_items; i++) {
3243 + y = g->time_graph_y_values[i] * (double)(g->params.draw_area.bottom_left.y-g->params.draw_area.top_right.y);
3244 + y = (double)g->params.draw_area.bottom_left.y - y;
3245 + g->data->dataset[g->data->last_index].y_values[i] = y;
3247 + g->data->dataset[g->data->last_index].next_index = g->data->last_index + incr;
3248 + if (g->data->dataset[g->data->last_index].next_index >= g->data->dataset_size)
3249 + g->data->dataset[g->data->last_index].next_index -= g->data->dataset_size;
3250 + g->data->num_elems++;
3251 + g->data->last_index = g->data->dataset[g->data->last_index].next_index;
3252 + g->data->last_time = g->time_now;
3254 + pthread_mutex_unlock(&g->mtx);
3256 + widget_schedule_redraw(g->widget);
3257 + DBG("event task ran...\n");
3260 +void *time_graph_create(int argc, char *argv[], struct time_graph_create_params *cp)
3263 + struct display *d;
3265 + struct timeval tv;
3267 + if (cp->num_of_y_items > MAX_ITEMS) return NULL;
3268 + if (cp->num_of_text_items > MAX_ITEMS) return NULL;
3270 + g = (struct graph*)malloc(sizeof(struct graph));
3272 + fprintf(stderr, "failed to allocate memory\n");
3277 + if (cp->num_of_y_items)
3278 + memcpy(&g->y_config_array[0], cp->y_config_array,
3279 + sizeof(struct _y_config) * cp->num_of_y_items);
3280 + if (cp->num_of_text_items)
3281 + memcpy(&g->text_config_array[0], cp->text_config_array,
3282 + sizeof(struct _text_config) * cp->num_of_text_items);
3283 + d = display_create(&argc, argv);
3285 + fprintf(stderr, "failed to create display: %m\n");
3289 + //g->bg_image = load_cairo_surface(cp->bg_image);
3290 + g->width = cp->width; //cairo_image_surface_get_width(g->bg_image);
3291 + g->height = cp->height; //cairo_image_surface_get_height(g->bg_image);
3292 + dataset_size = cp->draw_area.top_right.x - cp->draw_area.bottom_left.x;
3293 + g->data = (struct graph_data *)malloc(sizeof(struct graph_data) +
3294 + (dataset_size * sizeof(struct graph_dataset_point)));
3296 + fprintf(stderr, "failed to allocate memory\n");
3297 + display_destroy(g->display);
3298 + //cairo_surface_destroy(g->bg_image);
3302 + g->data->first_index = 0;
3303 + g->data->last_index = 0;
3304 + g->data->num_elems = 0;
3305 + g->data->dataset_size = dataset_size;
3306 + g->x_scaling_factor = (double)dataset_size / (double)cp->time_span;
3307 + g->window = window_create(d);
3308 + g->widget = window_add_widget(g->window, g);
3309 + window_set_title(g->window, cp->title);
3310 + widget_set_resize_handler(g->widget, resize_handler);
3311 + widget_set_redraw_handler(g->widget, redraw_handler);
3312 + widget_set_button_handler(g->widget, button_handler);
3313 + widget_set_default_cursor(g->widget, CURSOR_HAND1);
3314 + widget_set_touch_down_handler(g->widget, touch_down_handler);
3315 + window_schedule_resize(g->window, g->width, g->height);
3316 + g->eventfd = eventfd(0, 0);
3317 + g->task.run = task_run;
3318 + g->task.link.prev = (struct wl_list*)g;
3319 + g->task.link.next = NULL;
3320 + display_watch_fd(d, g->eventfd, EPOLLIN, &g->task);
3321 + pthread_mutex_init(&g->mtx, NULL);
3323 + if (0 != pthread_create(&g->thr, NULL, (void *(*)(void *))display_run, (void *)d)) {
3324 + fprintf(stderr, "pthread_create failed: %m\n");
3325 + widget_destroy(g->widget);
3326 + window_destroy(g->window);
3327 + display_destroy(g->display);
3328 + //cairo_surface_destroy(g->bg_image);
3330 + close(g->eventfd);
3334 + gettimeofday(&tv, NULL);
3335 + g->start_time_tv_sec = tv.tv_sec;
3336 + g->data->last_time = 0;
3340 +void move_graph(void *ctx, struct time_graph_create_params *cp)
3342 + struct graph *g = ctx;
3343 + window_set_title(g->window, cp->title);
3346 +void time_graph_plot(void *ctx, double *y_values, const char *text_values[])
3348 + struct timeval tv;
3349 + struct graph *g = ctx;
3351 + pthread_mutex_lock(&g->mtx);
3352 + gettimeofday(&tv, NULL);
3353 + g->time_now = ((tv.tv_sec - g->start_time_tv_sec) * 1000) + (tv.tv_usec / 1000);
3354 + memcpy(g->time_graph_y_values, y_values, g->params.num_of_y_items * sizeof(double));
3355 + for (i=0;i<g->params.num_of_text_items; i++) {
3356 + strncpy(g->text_values[i], text_values[i], MAX_TEXT_SIZE);
3357 + g->text_values[i][MAX_TEXT_SIZE-1] = '\0';
3359 + pthread_mutex_unlock(&g->mtx);
3360 + eventfd_write(g->eventfd, (eventfd_t)1);
3363 +void time_graph_destroy(void *ctx)
3365 + struct graph *g = (struct graph *)ctx;
3366 + display_exit(g->display);
3367 + eventfd_write(g->eventfd, (eventfd_t)1);
3368 + pthread_join(g->thr, NULL);
3369 + widget_destroy(g->widget);
3370 + window_destroy(g->window);
3371 + display_destroy(g->display);
3373 + close(g->eventfd);
3375 + global_graph=NULL;
3378 +void util_get_cpu_usage(double *cpu_usage)
3380 + static FILE *fp = NULL;
3383 + uint64_t u, n, s, i, w, x, y, z;
3384 + static uint64_t last_i = 0, last_total = 0;
3388 + if (!(fp = fopen("/proc/stat", "r")))
3389 + fprintf(stderr, "Failed /proc/stat open: %s", strerror(errno));
3395 + if (!fgets(buf, sizeof(buf), fp)) {
3396 + fprintf(stderr, "failed /proc/stat read\n");
3398 + sscanf(buf, "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu",
3408 + if (last_total == 0) {
3409 + last_total = u+n+s+i+w+x+y+z;
3413 + tot = u+n+s+i+w+x+y+z;
3414 + *cpu_usage = (1.0 - ((double)(i-last_i)/(double)(tot-last_total)));
3424 +void *bar_graph_create(int argc, char *argv[], struct bar_graph_create_params *cp)
3427 + struct display *d;
3428 + struct timeval tv;
3430 + if (cp->num_of_y_items > MAX_ITEMS) return NULL;
3431 + if (cp->num_of_text_items > MAX_ITEMS) return NULL;
3433 + if (global_graph == NULL) {
3434 + fprintf(stderr, "graph not initialized invoke time_graph_create first\n");
3438 + g->bar_graph_params = *cp;
3439 + if (cp->num_of_y_items)
3440 + memcpy(&g->bar_graph_y_config_array[0], cp->y_config_array,
3441 + sizeof(struct _bar_graph_y_config) * cp->num_of_y_items);
3442 + if (cp->num_of_text_items)
3443 + memcpy(&g->bar_graph_text_config_array[0], cp->text_config_array,
3444 + sizeof(struct _text_config) * cp->num_of_text_items);
3449 +void bar_graph_plot(void *ctx, double *y_values, const char *text_values[])
3451 + struct graph *g = ctx;
3453 + pthread_mutex_lock(&g->mtx);
3454 + memcpy(g->bar_graph_y_values, y_values, g->bar_graph_params.num_of_y_items * sizeof(double));
3455 + for (i=0;i<g->bar_graph_params.num_of_text_items; i++) {
3456 + strncpy(g->bar_graph_text_values[i], text_values[i], MAX_TEXT_SIZE);
3457 + g->bar_graph_text_values[i][MAX_TEXT_SIZE-1] = '\0';
3459 + pthread_mutex_unlock(&g->mtx);
3460 + //eventfd_write(g->eventfd, (eventfd_t)2);
3463 +void bar_graph_destroy(void *ctx)
3465 + printf("Nothing to be done for this call\n");
3469 diff --git a/clients/time_bar_graph.h b/clients/time_bar_graph.h
3470 new file mode 100644
3471 index 0000000..97ac05a
3473 +++ b/clients/time_bar_graph.h
3476 +#ifndef _BAR_GRAPH_H_
3477 +#define _BAR_GRAPH_H_
3479 +#include <stdint.h>
3482 + double r, g, b, a; // Values between 0 and 1
3485 +struct _coordinate {
3486 + uint32_t x, y; // Co-ordinates relative to top-left of the window
3490 + struct _coordinate bottom_left, top_right;
3494 + struct _rgba line_color; // Line color
3495 + struct _rgba fill_color; // Fill color, 0 alpha => no fill
3498 +struct _text_config {
3499 + struct _rgba color; // Color for drawing the text, RGBA
3500 + struct _coordinate at; // where to draw the text
3501 + int fontsize; // Font size
3504 +struct time_graph_create_params {
3506 + //const char *bg_image;
3509 + struct _rect draw_area;
3510 + uint32_t time_span; // Amount of time the graph has to span in milliseconds
3511 + uint32_t num_of_y_items;
3512 + struct _y_config *y_config_array;
3513 + uint32_t num_of_text_items;
3514 + struct _text_config *text_config_array;
3518 +struct _bar_graph_y_config {
3519 + struct _rect region; // Region for the bar graph
3520 + struct _rgba line_color; // Color for drawing the line, RGBA
3521 + struct _rgba fill_color; // Fill under the line with color RGBA, 0 => no fill
3524 +struct bar_graph_create_params {
3526 + //const char *bg_image;
3527 + uint32_t num_of_y_items;
3528 + struct _bar_graph_y_config *y_config_array;
3529 + uint32_t num_of_text_items;
3530 + struct _text_config *text_config_array;
3533 +/* Creates a time graph using create parameters */
3534 +void *bar_graph_create(int argc, char *argv[], struct bar_graph_create_params *cp);
3536 +void move_graph(void *ctx, struct time_graph_create_params *cp);
3538 +/* Plots a new set of y-values from the values in the array y_values.
3539 + The number of values must be equal to "num_of_y_items" from create params
3540 + y_values must be normalized between 0.0 to 1.0
3542 +void bar_graph_plot(void *ctx, double *y_values, const char *text_values[]);
3544 +/* Destroy the graph */
3545 +void bar_graph_destroy(void *ctx);
3548 +/* Creates a time graph using create parameters */
3549 +void *time_graph_create(int argc, char *argv[], struct time_graph_create_params *cp);
3552 + * Plots a new set of points from the values in the array y_values.
3553 + * The number of values in the array y_values must be equal to "num_of_y_items"
3554 + * from create params
3555 + * y_values must be normalized between 0.0 to 1.0
3557 + * The number of values in the array text_values must be equal to "num_of_text_items"
3558 + * from create params
3560 +void time_graph_plot(void *ctx, double *y_values, const char *text_values[]);
3562 +/* Destroy the graph */
3563 +void time_graph_destroy(void *ctx);
3565 +void util_get_cpu_usage(double *cpu_usage);
3567 +#endif /* _BAR_GRAPH_H_ */