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 | 625 ++++++++++++++++
11 clients/soc_performance_monitor.h | 40 ++
12 clients/statcoll.c | 1433 +++++++++++++++++++++++++++++++++++++
13 clients/statcoll.h | 152 ++++
14 clients/statcoll_gui.h | 101 +++
15 clients/time_bar_graph.c | 515 +++++++++++++
16 clients/time_bar_graph.h | 93 +++
17 10 files changed, 4873 insertions(+), 1 deletion(-)
18 create mode 100644 clients/Dra7xx_ddrstat_speed.c
19 create mode 100644 clients/soc_performance_monitor.c
20 create mode 100644 clients/soc_performance_monitor.h
21 create mode 100644 clients/statcoll.c
22 create mode 100644 clients/statcoll.h
23 create mode 100644 clients/statcoll_gui.h
24 create mode 100644 clients/time_bar_graph.c
25 create mode 100644 clients/time_bar_graph.h
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 + y[i*2+1] = atoi(value)/100.0;
670 + sprintf(text[i*2+1], " %02s%s", value,"%");
671 + printd("CPULOAD: Updating %s with %s\n", field, value);
675 + else if(strcmp(command, "MOVE:") == 0)
678 + printd("Received MOVE command : %s\n", buf);
679 + sscanf(string, "%s", value);
680 + sprintf(tg_p.title, "CPU Usage[@position-req=%sx%d]", value, y_pos);
681 + move_graph(ctx, &tg_p);
685 + printf("ERROR: Received unexpected data from FIFO - \" %s \" \n", buf);
687 + memset(buf, 0x0, sizeof(buf));
699 +volatile sig_atomic_t sigtermed = 0;
701 +void my_signal_handler(int signum)
703 + if (signum == SIGTERM || signum == SIGINT) {
708 +int get_strings_in_section(char *string, char **output)
712 + int total_strings = 0;
714 + fd = fopen("soc_performance_monitor.cfg", "r");
716 + fprintf(stderr, "ERROR: Unable to open file soc_performance_monitor.cfg\n");
717 + fprintf(stderr, " Please copy the file from /etc/visualization_scripts into current directory\n");
721 + while(fgets(line, sizeof line, fd)) {
722 + if(strstr(line, string)) {
723 + printf("\n-------------------------------------------------\n");
724 + printf("CONFIG FILE PARSE: Found section %s in line : %s\n", string, line);
729 + while(fgets(line, sizeof line, fd)) {
730 + printd("Line is = %s", line);
732 + if (line[0] == '#' || line[0] == '\n' || line[0] == '[') {
736 + line[strlen(line) - 1] = '\0';
737 + strcpy(output[total_strings++], line);
742 + return total_strings;
746 +void fill_cpu_load_details(int start_offset, int end_offset, char **output, struct table_configuration *table_config)
750 + const int BL_START_X = table_config->BL_START_X;
751 + const int BL_START_Y = table_config->BL_START_Y;
752 + const int BAR_GAP = table_config->BAR_GAP;
753 + const int BAR_HEIGHT = table_config->BAR_HEIGHT;
754 + const int BAR_WIDTH = table_config->BAR_WIDTH;
755 + const int TR_START_X = table_config->TR_START_X;
756 + const int TR_START_Y = table_config->TR_START_Y;
757 + const int FONT_SIZE = table_config->FONT_SIZE;
758 + printf("Filling from %d to %d\n", start_offset, end_offset);
759 + cpu_load_offset = start_offset;
761 + for(i=start_offset; i< end_offset-1; i++) {
762 + y_cfg[i*2].region.bottom_left.x = BL_START_X + (i-start_offset) * (BAR_GAP + BAR_WIDTH);
763 + y_cfg[i*2].region.bottom_left.y = BL_START_Y;
764 + y_cfg[i*2].region.top_right.x = TR_START_X + (i-start_offset) * (BAR_GAP + BAR_WIDTH);
765 + y_cfg[i*2].region.top_right.y = TR_START_Y;
766 + y_cfg[i*2].line_color.r = 1.0;
767 + y_cfg[i*2].line_color.g = 1.0;
768 + y_cfg[i*2].line_color.b = 1.0;
769 + y_cfg[i*2].line_color.a = 1.0;
770 + y_cfg[i*2].fill_color.r = 0.0;
771 + y_cfg[i*2].fill_color.g = 0.0;
772 + y_cfg[i*2].fill_color.b = 1.0;
773 + y_cfg[i*2].fill_color.a = 0.7;
775 + y_cfg[i*2+1].region.bottom_left.x = BL_START_X +(i-start_offset) * (BAR_GAP + BAR_WIDTH);
776 + y_cfg[i*2+1].region.bottom_left.y = BL_START_Y;
777 + y_cfg[i*2+1].region.top_right.x = TR_START_X + (i-start_offset) * (BAR_GAP + BAR_WIDTH);
778 + y_cfg[i*2+1].region.top_right.y = TR_START_Y;
779 + y_cfg[i*2+1].line_color.r = 1.0;
780 + y_cfg[i*2+1].line_color.g = 1.0;
781 + y_cfg[i*2+1].line_color.b = 1.0;
782 + y_cfg[i*2+1].line_color.a = 1.0;
783 + y_cfg[i*2+1].fill_color.r = 1.0;
784 + y_cfg[i*2+1].fill_color.g = 0.0;
785 + y_cfg[i*2+1].fill_color.b = 0.0;
786 + y_cfg[i*2+1].fill_color.a = 1.0;
789 + t_cfg[i*2].color.r = 1.0;
790 + t_cfg[i*2].color.g = 1.0;
791 + t_cfg[i*2].color.b = 1.0;
792 + t_cfg[i*2].color.a = 1.0;
793 + t_cfg[i*2].at.x = BL_START_X + (i-start_offset) * (BAR_GAP + BAR_WIDTH);
794 + t_cfg[i*2].at.y = BL_START_Y + FONT_SIZE;
795 + t_cfg[i*2].fontsize = FONT_SIZE;
797 + t_cfg[i*2+1].color.r = 1.0;
798 + t_cfg[i*2+1].color.g = 1.0;
799 + t_cfg[i*2+1].color.b = 1.0;
800 + t_cfg[i*2+1].color.a = 1.0;
801 + t_cfg[i*2+1].at.x = BL_START_X + (i-start_offset) * (BAR_GAP + BAR_WIDTH);
802 + t_cfg[i*2+1].at.y = BL_START_Y - BAR_HEIGHT - FONT_SIZE;
803 + t_cfg[i*2+1].fontsize = FONT_SIZE;
805 + strcpy(bg_text[i*2], output[i - start_offset]);
806 + strcpy(bg_text[i*2+1], "0%");
809 + t_cfg[(end_offset-1)*2].color.r = 0.0;
810 + t_cfg[(end_offset-1)*2].color.g = 1.0;
811 + t_cfg[(end_offset-1)*2].color.b = 1.0;
812 + t_cfg[(end_offset-1)*2].color.a = 1.0;
813 + t_cfg[(end_offset-1)*2].at.x = BL_START_X + 80;
814 + t_cfg[(end_offset-1)*2].at.y = TR_START_Y - 40;
815 + t_cfg[(end_offset-1)*2].fontsize = FONT_SIZE + 3;
817 + printd("Copying title string %s\n", output[end_offset - start_offset -1]);
818 + strcpy(bg_text[(end_offset-1)*2], output[end_offset - start_offset-1]);
821 +void fill_table_details(int start_offset, int end_offset, char **output, struct table_configuration *table_config)
825 + const int BL_START_X = table_config->BL_START_X;
826 + const int BL_START_Y = table_config->BL_START_Y;
827 + const int BAR_GAP = table_config->BAR_GAP;
828 + const int BAR_HEIGHT = table_config->BAR_HEIGHT;
829 + const int BAR_WIDTH = table_config->BAR_WIDTH;
830 + const int TR_START_X = table_config->TR_START_X;
831 + const int TR_START_Y = table_config->TR_START_Y;
832 + const int FONT_SIZE = table_config->FONT_SIZE;
833 + printf("Filling from %d to %d\n", start_offset, end_offset);
836 + char tokenize[200];
837 + char tokens[10][100];
838 + char *pair, *key, *value;
840 + char title[100], unit[100];
842 + strcpy(tokenize, output[end_offset - start_offset - 1]);
843 + memset(tokens, 0, sizeof(tokens));
846 + pair = strtok (tokenize,",");
847 + while (pair != NULL) {
848 + strcpy(tokens[k++], pair);
849 + pair = strtok (NULL, ",");
853 + memset(title, 0, sizeof(title));
854 + memset(unit, 0, sizeof(unit));
856 + key=strtok(tokens[i], "=");
858 + if(strcmp(key,"TITLE") == 0) {
859 + value = strtok(NULL, "=");
860 + if(value != NULL) {
861 + strcpy(title, value);
864 + if(strcmp(key,"UNIT") == 0) {
865 + value = strtok(NULL, "=");
866 + if(value != NULL) {
867 + strcpy(unit, value);
874 + for(i=start_offset; i< end_offset-1; i++) {
875 + y_cfg[i*2].region.bottom_left.x = BL_START_X;
876 + y_cfg[i*2].region.bottom_left.y = BL_START_Y + (i - start_offset) * (BAR_GAP + BAR_HEIGHT);
877 + y_cfg[i*2].region.top_right.x = TR_START_X;
878 + y_cfg[i*2].region.top_right.y = TR_START_Y + (i - start_offset) * (BAR_GAP + BAR_HEIGHT);
879 + y_cfg[i*2].line_color.r = 1.0;
880 + y_cfg[i*2].line_color.g = 1.0;
881 + y_cfg[i*2].line_color.b = 1.0;
882 + y_cfg[i*2].line_color.a = 1.0;
883 + y_cfg[i*2].fill_color.r = 0.0;
884 + y_cfg[i*2].fill_color.g = 0.3;
885 + y_cfg[i*2].fill_color.b = 0.0;
886 + y_cfg[i*2].fill_color.a = 0.7;
888 + y_cfg[i*2+1].region.bottom_left.x = TR_START_X;
889 + y_cfg[i*2+1].region.bottom_left.y = BL_START_Y + (i - start_offset) * (BAR_GAP + BAR_HEIGHT);
890 + y_cfg[i*2+1].region.top_right.x = TR_START_X + (BAR_WIDTH); //+ 1 * BL_START_X;
891 + y_cfg[i*2+1].region.top_right.y = TR_START_Y + (i - start_offset) * (BAR_GAP + BAR_HEIGHT);;
892 + y_cfg[i*2+1].line_color.r = 1.0;
893 + y_cfg[i*2+1].line_color.g = 1.0;
894 + y_cfg[i*2+1].line_color.b = 1.0;
895 + y_cfg[i*2+1].line_color.a = 1.0;
896 + y_cfg[i*2+1].fill_color.r = 0.3;
897 + y_cfg[i*2+1].fill_color.g = 0.0;
898 + y_cfg[i*2+1].fill_color.b = 0.0;
899 + y_cfg[i*2+1].fill_color.a = 0.7;
902 + t_cfg[i*2].color.r = 1.0;
903 + t_cfg[i*2].color.g = 1.0;
904 + t_cfg[i*2].color.b = 1.0;
905 + t_cfg[i*2].color.a = 1.0;
906 + t_cfg[i*2].at.x = BL_START_X + 5;
907 + t_cfg[i*2].at.y = BL_START_Y + (i - start_offset) * (BAR_GAP+BAR_HEIGHT) -5;
908 + t_cfg[i*2].fontsize = FONT_SIZE;
910 + t_cfg[i*2+1].color.r = 1.0;
911 + t_cfg[i*2+1].color.g = 1.0;
912 + t_cfg[i*2+1].color.b = 1.0;
913 + t_cfg[i*2+1].color.a = 1.0;
914 + t_cfg[i*2+1].at.x = TR_START_X + 50;//BAR_WIDTH + TR_START_X;
915 + t_cfg[i*2+1].at.y = BL_START_Y + (i - start_offset) * (BAR_GAP + BAR_HEIGHT) -5;
916 + t_cfg[i*2+1].fontsize = FONT_SIZE;
918 + printd("Copying string %s at %d\n", output[i-start_offset], i);
919 + strcpy(bg_text[i*2], output[i-start_offset]);
920 + printd("Setting text 0 %s at %d\n", unit, i*2+1);
921 + sprintf(bg_text[i*2+1], "0 %s", unit);
923 + for(i=start_offset; i< end_offset*2; i++) {
924 + printd("%d - (%d, %d) to (%d, %d)\n", i, y_cfg[i].region.bottom_left.x, y_cfg[i].region.bottom_left.y, y_cfg[i].region.top_right.x, y_cfg[i].region.top_right.y);
927 + t_cfg[(end_offset-1)*2].color.r = 0.0;
928 + t_cfg[(end_offset-1)*2].color.g = 1.0;
929 + t_cfg[(end_offset-1)*2].color.b = 1.0;
930 + t_cfg[(end_offset-1)*2].color.a = 1.0;
931 + t_cfg[(end_offset-1)*2].at.x = BL_START_X + 80;
932 + t_cfg[(end_offset-1)*2].at.y = BL_START_Y - 40;
933 + t_cfg[(end_offset-1)*2].fontsize = FONT_SIZE + 3;
935 + printd("Copying title string %s\n", title);
936 + strcpy(bg_text[(end_offset-1)*2], title);
941 +int get_key_value_from_string(char *string, char *limiter, char *key, char *value)
943 + char *mykey, *myvalue;
945 + mykey=strtok(string, limiter);
946 + if(mykey != NULL) {
947 + myvalue = strtok(NULL, "=");
948 + strtok(myvalue, "\n");
949 + if(myvalue == NULL) {
956 + printd("Key is %s\n", mykey);
957 + printd("Value is %s\n", myvalue);
958 + strcpy(key, mykey);
959 + strcpy(value, myvalue);
964 +void populate_table_configuration(struct table_configuration *tbl_cfg, int cur_items, char **item_list)
966 + static int total_items = 0;
967 + static int total_tables = 0;
969 + tbl_cfg->BAR_HEIGHT = 25;
970 + tbl_cfg->BAR_WIDTH = 150;
971 + tbl_cfg->BL_START_X = 40;
972 + tbl_cfg->BL_START_Y = 80 + (total_items + total_tables) * tbl_cfg->BAR_HEIGHT;
973 + tbl_cfg->BAR_GAP = 0;
974 + tbl_cfg->TR_START_X = tbl_cfg->BL_START_X + tbl_cfg->BAR_WIDTH;
975 + tbl_cfg->TR_START_Y = tbl_cfg->BL_START_Y - tbl_cfg->BAR_HEIGHT;
976 + tbl_cfg->FONT_SIZE = 15;
978 + printf("Proceeding with filling out details...\n");
980 + fill_table_details(total_items, total_items+cur_items, item_list, tbl_cfg);
982 + total_items += cur_items;
986 + printf("total_items = %d, total_tables = %d\n", total_items, total_tables);
990 +int fill_list_from_section(char **section_list, char *section_name)
992 + int total_items, j;
994 + for(j=0; j<20; j++) {
995 + section_list[j] = malloc(100);
998 + total_items = get_strings_in_section(section_name, section_list);
999 + printf("\tThe total values in the section %s are %d\n", section_name, total_items);
1000 + for(j=0; j<total_items; j++) {
1001 + printf("\t\tThe returned strings for BOOT_TIME are %s\n", section_list[j]);
1004 + total_elements += total_items;
1006 + return total_items;
1009 +int main(int argc, char *argv[])
1016 + if (SIG_ERR == signal(SIGPIPE,SIG_IGN))
1019 + if (SIG_ERR == signal(SIGINT,my_signal_handler))
1022 + if (SIG_ERR == signal(SIGTERM,my_signal_handler))
1026 + printf("Enabling debug\n");
1027 + debug = atoi(argv[1]);
1030 + printf("Debug is disabled\n");
1035 + int total = fill_list_from_section(output, "GLOBAL");
1036 + for(j=0; j<total; j++) {
1037 + char key[100], value[100];
1038 + int ret = get_key_value_from_string(output[j], "=", key, value);
1040 + if(strcmp(key, "FIFO") == 0) {
1041 + strcpy(readfifo, value);
1043 + if(strcmp(key, "REFRESH_RATE_USEC") == 0) {
1044 + refresh_rate = atoi(value);
1046 + if(strcmp(key, "MAX_WIDTH") == 0) {
1047 + MAX_WIDTH = atoi(value);
1049 + if(strcmp(key, "MAX_HEIGHT") == 0) {
1050 + MAX_HEIGHT = atoi(value);
1052 + if(strcmp(key, "X_POS") == 0) {
1053 + x_pos = atoi(value);
1055 + if(strcmp(key, "Y_POS") == 0) {
1056 + y_pos = atoi(value);
1062 + printf("\n-------------------------------------------------\n");
1063 + printf("Configured REFRESH_RATE is %d\n", refresh_rate);
1064 + printf("Configured FIFO is %s\n", readfifo);
1065 + printf("Configured MAX_WIDTH is %d\n", MAX_WIDTH);
1066 + printf("Configured MAX_HEIGHT is %d\n", MAX_HEIGHT);
1067 + printf("Configured starting location is (%d, %d)\n", x_pos, y_pos);
1068 + printf("\n-------------------------------------------------\n");
1070 + int fd = open(readfifo, O_RDONLY|O_NONBLOCK);
1072 + printf("SUCCESS: Configured FIFO exists\n");
1076 + printf("ERROR: %s not found\nPlease create the fifo by executing mkfifo %s before running the application\n", readfifo, readfifo);
1081 + bg_p.title = malloc(100);
1082 + sprintf(bg_p.title, "CPU Usage[@position-req=%dx%d]", x_pos, y_pos);
1084 + /* ------------------------------------------------------------------------*/
1085 + /* Section for populating all lists from cfg sections*/
1086 + /* ------------------------------------------------------------------------*/
1087 + char *boot_list[20];
1088 + int total_boot_items = fill_list_from_section(boot_list, "BOOT_TIME");
1090 + char *temperature_list[20];
1091 + int total_temperature_items = fill_list_from_section(temperature_list, "TEMPERATURE");
1093 + char *cpu_load_list[20];
1094 + total_cpu_load_items = fill_list_from_section(cpu_load_list, "CPU_LOAD");
1096 + char *voltage_list[20];
1097 + int total_voltage_items = fill_list_from_section(voltage_list, "VOLTAGE");
1099 + char *frequency_list[20];
1100 + int total_frequency_items = fill_list_from_section(frequency_list, "FREQUENCY");
1101 + /* ------------------------------------------------------------------------*/
1102 + /* total_elements will be updated inside the fill_list_from_section function */
1104 + t_cfg = malloc(sizeof(struct _text_config) * (total_elements*2 + 1));
1105 + y_cfg = malloc(sizeof(struct _bar_graph_y_config) * total_elements*2);
1106 + bg_p.num_of_y_items = total_elements*2;
1107 + bg_p.y_config_array = y_cfg;
1108 + bg_p.num_of_text_items = total_elements*2 + 1;
1109 + bg_p.text_config_array = t_cfg;
1111 + bg_y = malloc(sizeof(double) * total_elements * 2);
1112 + for(i=0; i< (total_elements*2+1); i++) {
1113 + bg_text[i] = malloc(150);
1117 + tg_y = malloc(sizeof(double) * total_elements * 2);
1118 + for(i=0; i< (total_elements*2+1); i++) {
1119 + tg_text[i] = malloc(150);
1120 + tg_y[i] = 0.1 * i;
1123 + struct table_configuration boot_table_config;
1124 + populate_table_configuration(&boot_table_config, total_boot_items, boot_list);
1126 + struct table_configuration temp_table_config;
1127 + populate_table_configuration(&temp_table_config, total_temperature_items, temperature_list);
1129 + struct table_configuration voltage_table_config;
1130 + populate_table_configuration(&voltage_table_config, total_voltage_items, voltage_list);
1132 + struct table_configuration frequency_table_config;
1133 + populate_table_configuration(&frequency_table_config, total_frequency_items, frequency_list);
1135 + struct table_configuration cpu_load_config;
1136 + cpu_load_config.BL_START_X = 40;
1137 + cpu_load_config.BL_START_Y = 80 + (total_boot_items + total_temperature_items + total_voltage_items + total_frequency_items+ 4) * boot_table_config.BAR_HEIGHT + 80 /*cpu_load_config.BAR_HEIGHT */;
1138 + cpu_load_config.BAR_GAP = 20;
1139 + cpu_load_config.BAR_HEIGHT = 80;
1140 + cpu_load_config.BAR_WIDTH = 40;
1141 + cpu_load_config.TR_START_X = cpu_load_config.BL_START_X + cpu_load_config.BAR_WIDTH;
1142 + cpu_load_config.TR_START_Y = cpu_load_config.BL_START_Y - cpu_load_config.BAR_HEIGHT;
1143 + cpu_load_config.FONT_SIZE = 15;
1144 + if(total_cpu_load_items > 0) {
1145 + fill_cpu_load_details(total_boot_items+total_temperature_items+total_voltage_items+total_frequency_items, total_boot_items+total_temperature_items+total_voltage_items+total_frequency_items+total_cpu_load_items, cpu_load_list, &cpu_load_config);
1148 + cpu_load_offset = total_boot_items + total_temperature_items + total_voltage_items + total_frequency_items;
1151 + tg_p.title=(char *)malloc(100);
1152 + sprintf(tg_p.title, "CPU Usage[@position-req=%dx%d]", x_pos, y_pos);
1153 + tg_p.height = MAX_HEIGHT;
1154 + tg_p.width = MAX_WIDTH;
1156 + struct _y_config *tg_y_cfg = malloc(tg_p.num_of_y_items * sizeof(struct _y_config));
1157 + tg_p.y_config_array = tg_y_cfg;
1158 + tg_p.text_config_array = t_cfg;
1160 + printf("Proceeding to create starting visualization...\n");
1161 + ctx = time_graph_create(argc, argv, &tg_p);
1163 + printf("Unable to create time_graph... \n");
1167 + ctx = bar_graph_create(argc, argv, &bg_p);
1169 + printf("Error creating context\n");
1173 + command_handler(OPEN, NULL, NULL);
1175 + /* Plot the graph first time */
1176 + time_graph_plot(ctx, tg_y, (const char **)tg_text);
1177 + bar_graph_plot(ctx, bg_y, (const char **)bg_text);
1179 + while (!sigtermed)
1181 + usleep(refresh_rate);
1182 + int bytes_read = command_handler(READ, bg_y, bg_text);
1183 + if(bytes_read > 0) {
1184 + time_graph_plot(ctx, tg_y, (const char **)tg_text);
1185 + bar_graph_plot(ctx, bg_y, (const char **)bg_text);
1189 + bar_graph_destroy(ctx);
1190 + command_handler(CLOSE, NULL, NULL);
1193 diff --git a/clients/soc_performance_monitor.h b/clients/soc_performance_monitor.h
1194 new file mode 100644
1195 index 0000000..861c8c7
1197 +++ b/clients/soc_performance_monitor.h
1199 +#define __SLEEP usleep(1000000)
1201 +#define MAX_BUF 1024
1206 +#define MAX_COLORS 12
1208 +#define printd(fmt, ...) \
1209 + do { if (debug) fprintf(stderr, fmt, __VA_ARGS__); } while (0)
1212 +struct _rgba pallette[MAX_COLORS] =
1214 + { 1.0, 0.0, 0.0, 1.0 },
1215 + { 0.0, 0.5, 0.0, 1.0 },
1216 + { 0.0, 0.0, 1.0, 1.0 },
1217 + { 0.0, 0.0, 0.0, 1.0 },
1218 + { 0.0, 0.5, 1.0, 1.0 },
1219 + { 1.0, 0.0, 1.0, 1.0 },
1220 + { 0.5, 0.5, 1.0, 1.0 },
1221 + { 1.0, 0.5, 0.0, 1.0 },
1222 + { 0.5, 0.5, 0.25, 1.0 },
1223 + { 0.5, 0.0, 0.0, 1.0 },
1224 + { 1.0, 0.5, 0.5, 1.0 },
1225 + { 0.0, 0.0, 0.20, 1.0 }
1228 +struct table_configuration {
1239 diff --git a/clients/statcoll.c b/clients/statcoll.c
1240 new file mode 100644
1241 index 0000000..5d5cae7
1243 +++ b/clients/statcoll.c
1246 + * Copyright (C) 2015 Texas Instruments
1247 + * created by prash@ti.com on 16 Jan 2013
1248 + * Adapted to Linux with changes in framework: Karthik R <karthik.ramanan@ti.com>
1250 + * This program is free software; you can redistribute it and/or modify it
1251 + * under the terms of the GNU General Public License version 2 as published by
1252 + * the Free Software Foundation.
1254 + * This program is distributed in the hope that it will be useful, but WITHOUT
1255 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1256 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
1259 + * You should have received a copy of the GNU General Public License along with
1260 + * this program. If not, see <http://www.gnu.org/licenses/>.
1264 +#include <stdlib.h>
1265 +#include <string.h>
1266 +#include <sys/mman.h>
1268 +#include <signal.h>
1269 +#include <unistd.h>
1270 +#include <sys/time.h>
1272 +#include "statcoll.h"
1273 +#include "statcoll_gui.h"
1274 +#include "time_bar_graph.h"
1276 +#define ENABLE_MODE 0x0
1277 +#define READ_STATUS_MODE 0x1
1287 +#define __SLEEP sleep(1)
1289 +#define __SLEEP usleep(100000)
1291 +//#define DUMMY_MODE
1293 +#define MAX_COLORS 12
1295 +struct _rgba pallette[MAX_COLORS] =
1297 + { 1.0, 0.0, 0.0, 1.0 },
1298 + { 0.0, 0.5, 0.0, 1.0 },
1299 + { 0.0, 0.0, 1.0, 1.0 },
1300 + { 0.0, 0.0, 0.0, 1.0 },
1301 + { 0.0, 0.5, 1.0, 1.0 },
1302 + { 1.0, 0.0, 1.0, 1.0 },
1303 + { 0.5, 0.5, 1.0, 1.0 },
1304 + { 1.0, 0.5, 0.0, 1.0 },
1305 + { 0.5, 0.5, 0.25, 1.0 },
1306 + { 0.5, 0.0, 0.0, 1.0 },
1307 + { 1.0, 0.5, 0.5, 1.0 },
1308 + { 0.0, 0.0, 0.20, 1.0 }
1311 +const struct list_of_initiators initiators[STATCOL_MAX] =
1313 + { STATCOL_EMIF1_SYS, "STATCOL_EMIF1_SYS" },
1314 + { STATCOL_EMIF2_SYS,"STATCOL_EMIF2_SYS" },
1315 + { STATCOL_MA_MPU_P1,"STATCOL_MPU_P1" },
1316 + { STATCOL_MA_MPU_P2,"STATCOL_MPU_P2" },
1317 + { STATCOL_MPU1,"STATCOL_MPU1" },
1318 + { STATCOL_MMU1,"STATCOL_MMU1" },
1319 + { STATCOL_TPTC_RD1,"STATCOL_TPTC_RD1" },
1320 + { STATCOL_TPTC_WR1,"STATCOL_TPTC_WR1" },
1321 + { STATCOL_TPTC_RD2,"STATCOL_TPTC_RD2" },
1322 + { STATCOL_TPTC_WR2,"STATCOL_TPTC_WR2" },
1323 + { STATCOL_VIP1_P1,"STATCOL_VIP1_P1" },
1324 + { STATCOL_VIP1_P2,"STATCOL_VIP1_P2" },
1325 + { STATCOL_VIP2_P1,"STATCOL_VIP2_P1" },
1326 + { STATCOL_VIP2_P2,"STATCOL_VIP2_P2" },
1327 + { STATCOL_VIP3_P1,"STATCOL_VIP3_P1" },
1328 + { STATCOL_VIP3_P2,"STATCOL_VIP3_P2" },
1329 + { STATCOL_VPE_P1,"STATCOL_VPE_P1" },
1330 + { STATCOL_VPE_P2,"STATCOL_VPE_P2" },
1331 + { STATCOL_EVE1_TC0,"STATCOL_EVE1_TC0" },
1332 + { STATCOL_EVE1_TC1,"STATCOL_EVE1_TC1" },
1333 + { STATCOL_EVE2_TC0,"STATCOL_EVE2_TC0" },
1334 + { STATCOL_EVE2_TC1,"STATCOL_EVE2_TC1" },
1335 + { STATCOL_EVE3_TC0,"STATCOL_EVE3_TC0" },
1336 + { STATCOL_EVE3_TC1,"STATCOL_EVE3_TC1" },
1337 + { STATCOL_EVE4_TC0,"STATCOL_EVE4_TC0" },
1338 + { STATCOL_EVE4_TC1,"STATCOL_EVE4_TC1" },
1339 + { STATCOL_DSP1_MDMA,"STATCOL_DSP1_MDMA" },
1340 + { STATCOL_DSP1_EDMA,"STATCOL_DSP1_EDMA" },
1341 + { STATCOL_DSP2_MDMA,"STATCOL_DSP2_MDMA" },
1342 + { STATCOL_DSP2_EDMA,"STATCOL_DSP2_EDMA" },
1343 + { STATCOL_IVA,"STATCOL_IVA" },
1344 + { STATCOL_GPU_P1,"STATCOL_GPU_P1" },
1345 + { STATCOL_GPU_P2,"STATCOL_GPU_P2" },
1346 + { STATCOL_BB2D_P1,"STATCOL_BB2D_P1" },
1347 + { STATCOL_DSS,"STATCOL_DSS" },
1348 + { STATCOL_CSI2_2,"STATCOL_CSI2_2" },
1349 + { STATCOL_MMU2,"STATCOL_MMU2" },
1350 + { STATCOL_IPU1,"STATCOL_IPU1" },
1351 + { STATCOL_IPU2,"STATCOL_IPU2" },
1352 + { STATCOL_DMA_SYSTEM_RD,"STATCOL_DMA_SYSTEM_RD" },
1353 + { STATCOL_DMA_SYSTEM_WR,"STATCOL_DMA_SYSTEM_WR" },
1354 + { STATCOL_CSI2_1,"STATCOL_CSI2_1" },
1355 + { STATCOL_USB3_SS,"STATCOL_USB3_SS" },
1356 + { STATCOL_USB2_SS,"STATCOL_USB2_SS" },
1357 + { STATCOL_USB2_ULPI_SS1,"STATCOL_USB2_ULPI_SS1" },
1358 + { STATCOL_USB2_ULPI_SS2,"STATCOL_USB2_ULPI_SS2" },
1359 + { STATCOL_PCIE_SS1,"STATCOL_PCIE_SS1" },
1360 + { STATCOL_PCIE_SS2,"STATCOL_PCIE_SS2" },
1361 + { STATCOL_DSP1_CFG,"STATCOL_DSP1_CFG" },
1362 + { STATCOL_DSP2_CFG,"STATCOL_DSP2_CFG" },
1363 + { STATCOL_GMAC_SW,"STATCOL_GMAC_SW" },
1364 + { STATCOL_PRUSS1_P1,"STATCOL_PRUSS1_P1" },
1365 + { STATCOL_PRUSS1_P2,"STATCOL_PRUSS1_P2" },
1366 + { STATCOL_PRUSS2_P1,"STATCOL_PRUSS2_P1" },
1367 + { STATCOL_PRUSS2_P2,"STATCOL_PRUSS2_P2" },
1368 + { STATCOL_DMA_CRYPTO_RD,"STATCOL_DMA_CRYPTO_RD" },
1369 + { STATCOL_DMA_CRYPTO_WR,"STATCOL_DMA_CRYPTO_WR" },
1370 + { STATCOL_MPU2,"STATCOL_MPU2" },
1371 + { STATCOL_MMC1,"STATCOL_MMC1" },
1372 + { STATCOL_MMC2,"STATCOL_MMC2" },
1373 + { STATCOL_SATA,"STATCOL_SATA" },
1374 + { STATCOL_MLBSS,"STATCOL_MLBSS" },
1375 + { STATCOL_BB2D_P2,"STATCOL_BB2D_P2" },
1376 + { STATCOL_IEEE1500,"STATCOL_IEEE1500" },
1377 + { STATCOL_DBG,"STATCOL_DBG" },
1378 + { STATCOL_VCP1,"STATCOL_VCP1" },
1379 + { STATCOL_OCMC_RAM1,"STATCOL_OCMC_RAM1" },
1380 + { STATCOL_OCMC_RAM2,"STATCOL_OCMC_RAM2" },
1381 + { STATCOL_OCMC_RAM3,"STATCOL_OCMC_RAM3" },
1382 + { STATCOL_GPMC,"STATCOL_GPMC" },
1383 + { STATCOL_MCASP1,"STATCOL_MCASP1" },
1384 + { STATCOL_MCASP2,"STATCOL_MCASP2" },
1385 + { STATCOL_MCASP3,"STATCOL_MCASP3" },
1386 + { STATCOL_VCP2, "STATCOL_VCP2" }
1389 +StatCollectorObj gStatColState;
1391 +static void *statcoll_base_mem;
1392 +static int *l3_3_clkctrl;
1394 +static UInt32 *statCountDSS = NULL;
1395 +static UInt32 *statCountIVA = NULL;
1396 +static UInt32 *statCountBB2DP1 = NULL;
1397 +static UInt32 *statCountBB2DP2 = NULL;
1398 +static UInt32 *statCountUSB4 = NULL;
1399 +static UInt32 *statCountSata = NULL;
1400 +static UInt32 *statCountEmif1 = NULL;
1401 +static UInt32 *statCountEmif2 = NULL;
1404 +static statcoll_initiators_object global_object[STATCOL_MAX];
1405 +UInt32 statCountIdx = 0;
1406 +UInt32 TRACE_SZ = 0;
1408 +void create_overall_box(struct _bar_graph_y_config *y_cfg, struct _text_config *t_cfg, char *text[])
1412 + memset(y_cfg, 0x0, sizeof(struct _y_config)*25);
1413 + memset(t_cfg, 0x0, sizeof(struct _text_config)*25);
1416 + for(i=0; i<TOTAL_Y_PARAMETERS; i++) {
1417 + (y_cfg+i)->line_color.r = 1.0;
1418 + (y_cfg+i)->line_color.g = 1.0;
1419 + (y_cfg+i)->line_color.b = 1.0;
1420 + (y_cfg+i)->line_color.a = 0.7;
1421 + (y_cfg+i)->fill_color.r = 0.0;
1422 + (y_cfg+i)->fill_color.g = 0.0;
1423 + (y_cfg+i)->fill_color.b = 0.0;
1424 + (y_cfg+i)->fill_color.a = 0.1;
1427 + (y_cfg+0)->region.bottom_left.x = 0;
1428 + (y_cfg+0)->region.bottom_left.y = MAX_HEIGHT - HEIGHT_EMIF_AREA;
1429 + (y_cfg+0)->region.top_right.x = MAX_WIDTH;
1430 + (y_cfg+0)->region.top_right.y = 0;
1432 + (t_cfg+0)->at.x = MAX_WIDTH/2 - 8*FONT_SIZE - 50;
1433 + (t_cfg+0)->at.y = BORDER - FONT_SIZE + 6;
1434 + strcpy(text[0], string_list[0]);
1436 + (y_cfg+1)->region.bottom_left.x = TIME_GRAPH_AREA_BL_X;
1437 + (y_cfg+1)->region.bottom_left.y = TIME_GRAPH_AREA_BL_Y;
1438 + (y_cfg+1)->region.top_right.x = TIME_GRAPH_AREA_TR_X;
1439 + (y_cfg+1)->region.top_right.y = TIME_GRAPH_AREA_TR_Y;
1441 + (t_cfg+1)->at.x = TIME_GRAPH_AREA_BL_X - 2*FONT_SIZE;
1442 + (t_cfg+1)->at.y = TIME_GRAPH_AREA_TR_Y;
1443 + strcpy(text[1],string_list[1]);
1445 + for(i=2; i<7; i++)
1447 + (y_cfg+i)->region.bottom_left.x = TIME_GRAPH_AREA_BL_X;
1448 + (y_cfg+i)->region.bottom_left.y = TIME_GRAPH_AREA_BL_Y;// - (i-2) * (30);
1449 + (y_cfg+i)->region.top_right.x = TIME_GRAPH_AREA_TR_X;
1450 + (y_cfg+i)->region.top_right.y = TIME_GRAPH_AREA_TR_Y + (i-1) * ((TIME_GRAPH_AREA_BL_Y - TIME_GRAPH_AREA_TR_Y)/5);
1451 + (t_cfg+i)->at.x = TIME_GRAPH_AREA_BL_X - 2*FONT_SIZE;
1452 + (t_cfg+i)->at.y = TIME_GRAPH_AREA_TR_Y + (i-1) * ((TIME_GRAPH_AREA_BL_Y - TIME_GRAPH_AREA_TR_Y)/5);//TIME_GRAPH_AREA_TR_Y;
1453 + strcpy(text[i],string_list[i]);
1457 + (y_cfg+7)->region.bottom_left.x = EMIF_AREA_BL_X;
1458 + (y_cfg+7)->region.bottom_left.y = EMIF_AREA_BL_Y;
1459 + (y_cfg+7)->region.top_right.x = EMIF_AREA_TR_X;
1460 + (y_cfg+7)->region.top_right.y = EMIF_AREA_TR_Y;
1462 + (t_cfg+7)->at.x = WIDTH_EMIF_AREA/2 - 2*FONT_SIZE;
1463 + (t_cfg+7)->at.y = EMIF_AREA_TR_Y + FONT_SIZE;
1464 + strcpy(text[7],string_list[7]);
1466 + for(i=8; i<12; i=i+2)
1468 + (y_cfg+i)->region.bottom_left.x = EMIF_AREA_BL_X + BORDER + (i-8)*(BAR_WIDTH+BAR_GAP)/2;
1469 + (y_cfg+i)->region.bottom_left.y = EMIF_AREA_BL_Y - BORDER/2;// - (i-2) * (30);
1470 + (y_cfg+i)->region.top_right.x = EMIF_AREA_BL_X + BORDER + BAR_WIDTH + (i-8) * (BAR_WIDTH + BAR_GAP)/2;
1471 + (y_cfg+i)->region.top_right.y = EMIF_AREA_TR_Y + BORDER * 1.2;
1473 + (y_cfg+i)->fill_color.r = 1.0;
1474 + (y_cfg+i)->fill_color.g = 0.0;
1475 + (y_cfg+i)->fill_color.b = 0.0;
1476 + (y_cfg+i)->fill_color.a = 0.1;
1478 + (y_cfg+i+1)->region.bottom_left.x = EMIF_AREA_BL_X + BORDER + (i-8) * (BAR_WIDTH + BAR_GAP)/2;
1479 + (y_cfg+i+1)->region.bottom_left.y = EMIF_AREA_BL_Y - BORDER/2;
1480 + (y_cfg+i+1)->region.top_right.x = EMIF_AREA_BL_X + BORDER + BAR_WIDTH + (i-8) * (BAR_WIDTH + BAR_GAP)/2;
1481 + (y_cfg+i+1)->region.top_right.y = EMIF_AREA_TR_Y + BORDER*1.2;
1483 + (y_cfg+i+1)->fill_color.r = 0.0;
1484 + (y_cfg+i+1)->fill_color.g = 1.0;
1485 + (y_cfg+i+1)->fill_color.b = 0.0;
1486 + (y_cfg+i+1)->fill_color.a = 1.0;
1488 + (t_cfg+i)->at.x = EMIF_AREA_BL_X + BAR_WIDTH + BORDER + (i-8) * (BAR_WIDTH + BAR_GAP)/2- 2.2*FONT_SIZE;
1489 + (t_cfg+i)->at.y = EMIF_AREA_TR_Y + BORDER*1.2 -5;
1491 + /* Fixed strings */
1492 + (t_cfg+i+1)->at.x = EMIF_AREA_BL_X + BORDER + (i-8) * (BAR_WIDTH + BAR_GAP)/2;
1493 + (t_cfg+i+1)->at.y = EMIF_AREA_BL_Y;// - BORDER + FONT_SIZE;
1495 + strcpy(text[i],string_list[i]);
1496 + strcpy(text[i+1],string_list[i+1]);
1499 + (y_cfg+12)->region.bottom_left.x = INITIATORS_AREA_BL_X;
1500 + (y_cfg+12)->region.bottom_left.y = INITIATORS_AREA_BL_Y;
1501 + (y_cfg+12)->region.top_right.x = INITIATORS_AREA_TR_X;
1502 + (y_cfg+12)->region.top_right.y = INITIATORS_AREA_TR_Y;
1504 + (t_cfg+12)->at.x = EMIF_AREA_TR_X + (INITIATORS_AREA_TR_X - INITIATORS_AREA_BL_X)/2 - 4 * FONT_SIZE;
1505 + (t_cfg+12)->at.y = INITIATORS_AREA_TR_Y + FONT_SIZE;
1506 + strcpy(text[12],string_list[12]);
1508 + for(i=13; i<25; i=i+2)
1510 + (y_cfg+i)->region.bottom_left.x = INITIATORS_AREA_BL_X + BORDER + (i-13)*(BAR_WIDTH+BAR_GAP)/2;
1511 + (y_cfg+i)->region.bottom_left.y = INITIATORS_AREA_BL_Y - BORDER/2;// - (i-2) * (30);
1512 + (y_cfg+i)->region.top_right.x = INITIATORS_AREA_BL_X + BORDER + BAR_WIDTH + (i-13) * (BAR_WIDTH + BAR_GAP)/2;
1513 + (y_cfg+i)->region.top_right.y = INITIATORS_AREA_TR_Y + BORDER*1.2;
1515 + (y_cfg+i)->fill_color.r = 1.0;
1516 + (y_cfg+i)->fill_color.g = 0.0;
1517 + (y_cfg+i)->fill_color.b = 0.0;
1518 + (y_cfg+i)->fill_color.a = 0.1;
1520 + (y_cfg+i+1)->region.bottom_left.x = INITIATORS_AREA_BL_X + BORDER + (i-13) * (BAR_WIDTH + BAR_GAP)/2;
1521 + (y_cfg+i+1)->region.bottom_left.y = INITIATORS_AREA_BL_Y - BORDER/2;// - (i-2) * (30);
1522 + (y_cfg+i+1)->region.top_right.x = INITIATORS_AREA_BL_X + BORDER + BAR_WIDTH + (i-13) * (BAR_WIDTH + BAR_GAP)/2;
1523 + (y_cfg+i+1)->region.top_right.y = INITIATORS_AREA_TR_Y + BORDER* 1.2;
1525 + (y_cfg+i+1)->fill_color.r = 0.0;
1526 + (y_cfg+i+1)->fill_color.g = 1.0;
1527 + (y_cfg+i+1)->fill_color.b = 0.0;
1528 + (y_cfg+i+1)->fill_color.a = 1.0;
1530 + (t_cfg+i)->at.x = INITIATORS_AREA_BL_X + BORDER + BAR_WIDTH + (i-13) * (BAR_WIDTH + BAR_GAP)/2 - 2.2* FONT_SIZE;
1531 + (t_cfg+i)->at.y = INITIATORS_AREA_TR_Y + BORDER*1.2 -5;
1533 + (t_cfg+i+1)->at.x = INITIATORS_AREA_BL_X + BORDER + (i-13)*(BAR_WIDTH+BAR_GAP)/2;
1534 + (t_cfg+i+1)->at.y = INITIATORS_AREA_BL_Y;
1536 + strcpy(text[i],string_list[i]);
1537 + strcpy(text[i+1],string_list[i+1]);
1542 + for(i=0; i<25; i++)
1543 + printf("(%d, %d) to (%d, %d)\n", (y_cfg +i)->region.bottom_left.x,(y_cfg +i)->region.bottom_left.y,(y_cfg +i)->region.top_right.x, (y_cfg +i)->region.top_right.y);
1548 + for(i=0; i<25; i++) {
1549 + (t_cfg+i)->color.r = 0.0;
1550 + (t_cfg+i)->color.g = 1.0;
1551 + (t_cfg+i)->color.b = 1.0;
1552 + (t_cfg+i)->color.a = 1.0;
1553 + (t_cfg+i)->fontsize = FONT_SIZE;
1555 + (t_cfg+0)->fontsize = 20;
1561 +void statCollectorInit()
1565 + gStatColState.stat0_filter_cnt = 0;
1566 + gStatColState.stat1_filter_cnt = 0;
1567 + gStatColState.stat2_filter_cnt = 0;
1568 + gStatColState.stat3_filter_cnt = 0;
1569 + gStatColState.stat4_filter_cnt = 0;
1570 + gStatColState.stat5_filter_cnt = 0;
1571 + gStatColState.stat6_filter_cnt = 0;
1572 + gStatColState.stat7_filter_cnt = 0;
1573 + gStatColState.stat8_filter_cnt = 0;
1574 + gStatColState.stat9_filter_cnt = 0;
1576 + for(index=STATCOL_EMIF1_SYS; index < STATCOL_MAX; index++)
1578 + global_object[index].b_enabled = 0;
1580 + strcpy(global_object[index].name, initiators[index].name);
1582 + global_object[index].readings = malloc(TRACE_SZ * sizeof(UInt32));
1583 + memset(global_object[index].readings, 0, TRACE_SZ * sizeof(UInt32));
1585 + global_object[index].timestamp = NULL;
1587 + global_object[index].group_id = 0xFF;
1588 + global_object[index].counter_id = 0;
1589 + global_object[index].base_address = 0;
1590 + global_object[index].mux_req = 0;
1595 +void wr_stat_reg(UInt32 address, UInt32 data)
1597 + UInt32 *mymem = statcoll_base_mem;
1598 + UInt32 delta = (address - STATCOLL_BASE) / 4;
1600 + mymem[delta] = data;
1602 + printf("WRITE: Address = 0x%x, Data = 0x%x\n", address, data);
1606 +UInt32 rd_stat_reg(UInt32 address)
1609 + UInt32 *mymem = statcoll_base_mem;
1611 + UInt32 delta = (address - STATCOLL_BASE) / 4;
1612 + data = mymem[delta];
1615 + printf("READ: Address = 0x%x\n", address);
1619 +UInt32 statCollectorControlInitialize(UInt32 instance_id)
1621 + UInt32 cur_base_address = 0;
1622 + UInt32 cur_event_mux_req;
1623 + UInt32 cur_event_mux_resp;
1624 + UInt32 cur_stat_filter_cnt;
1626 + switch (instance_id)
1628 + case STATCOL_EMIF1_SYS:
1629 + cur_base_address = stat_coll0_base_address;
1630 + cur_event_mux_req = 0;
1631 + cur_event_mux_resp = 1;
1632 + gStatColState.stat0_filter_cnt = gStatColState.stat0_filter_cnt + 1;
1633 + cur_stat_filter_cnt = gStatColState.stat0_filter_cnt;
1634 + global_object[instance_id].group_id = 0;
1636 + case STATCOL_EMIF2_SYS:
1637 + cur_base_address = stat_coll0_base_address;
1638 + cur_event_mux_req = 2;
1639 + cur_event_mux_resp = 3;
1640 + gStatColState.stat0_filter_cnt = gStatColState.stat0_filter_cnt + 1;
1641 + cur_stat_filter_cnt = gStatColState.stat0_filter_cnt;
1642 + global_object[instance_id].group_id = 0;
1644 + case STATCOL_MA_MPU_P1:
1645 + cur_base_address = stat_coll0_base_address;
1646 + cur_event_mux_req = 4;
1647 + cur_event_mux_resp = 5;
1648 + gStatColState.stat0_filter_cnt = gStatColState.stat0_filter_cnt + 1;
1649 + cur_stat_filter_cnt = gStatColState.stat0_filter_cnt;
1650 + global_object[instance_id].group_id = 0;
1652 + case STATCOL_MA_MPU_P2:
1653 + cur_base_address = stat_coll0_base_address;
1654 + cur_event_mux_req = 6;
1655 + cur_event_mux_resp = 7;
1656 + gStatColState.stat0_filter_cnt = gStatColState.stat0_filter_cnt + 1;
1657 + cur_stat_filter_cnt = gStatColState.stat0_filter_cnt;
1658 + global_object[instance_id].group_id = 0;
1660 + case STATCOL_MPU1:
1661 + cur_base_address = stat_coll1_base_address;
1662 + cur_event_mux_req = 0;
1663 + cur_event_mux_resp = 1;
1664 + gStatColState.stat1_filter_cnt = gStatColState.stat1_filter_cnt + 1;
1665 + cur_stat_filter_cnt = gStatColState.stat1_filter_cnt;
1666 + global_object[instance_id].group_id = 1;
1668 + case STATCOL_MMU1:
1669 + cur_base_address = stat_coll1_base_address;
1670 + cur_event_mux_req = 2;
1671 + cur_event_mux_resp = 3;
1672 + gStatColState.stat1_filter_cnt = gStatColState.stat1_filter_cnt + 1;
1673 + cur_stat_filter_cnt = gStatColState.stat1_filter_cnt;
1674 + global_object[instance_id].group_id = 1;
1676 + case STATCOL_TPTC_RD1:
1677 + cur_base_address = stat_coll1_base_address;
1678 + cur_event_mux_req = 4;
1679 + cur_event_mux_resp = 5;
1680 + gStatColState.stat1_filter_cnt = gStatColState.stat1_filter_cnt + 1;
1681 + cur_stat_filter_cnt = gStatColState.stat1_filter_cnt;
1682 + global_object[instance_id].group_id = 1;
1684 + case STATCOL_TPTC_WR1:
1685 + cur_base_address = stat_coll1_base_address;
1686 + cur_event_mux_req = 6;
1687 + cur_event_mux_resp = 7;
1688 + gStatColState.stat1_filter_cnt = gStatColState.stat1_filter_cnt + 1;
1689 + cur_stat_filter_cnt = gStatColState.stat1_filter_cnt;
1690 + global_object[instance_id].group_id = 1;
1692 + case STATCOL_TPTC_RD2:
1693 + cur_base_address = stat_coll1_base_address;
1694 + cur_event_mux_req = 8;
1695 + cur_event_mux_resp = 9;
1696 + gStatColState.stat1_filter_cnt = gStatColState.stat1_filter_cnt + 1;
1697 + cur_stat_filter_cnt = gStatColState.stat1_filter_cnt;
1698 + global_object[instance_id].group_id = 1;
1700 + case STATCOL_TPTC_WR2:
1701 + cur_base_address = stat_coll1_base_address;
1702 + cur_event_mux_req = 10;
1703 + cur_event_mux_resp = 11;
1704 + gStatColState.stat1_filter_cnt = gStatColState.stat1_filter_cnt + 1;
1705 + cur_stat_filter_cnt = gStatColState.stat1_filter_cnt;
1706 + global_object[instance_id].group_id = 1;
1708 + case STATCOL_VIP1_P1:
1709 + cur_base_address = stat_coll2_base_address;
1710 + cur_event_mux_req = 0;
1711 + cur_event_mux_resp = 1;
1712 + gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1713 + cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1714 + global_object[instance_id].group_id = 2;
1716 + case STATCOL_VIP1_P2:
1717 + cur_base_address = stat_coll2_base_address;
1718 + cur_event_mux_req = 2;
1719 + cur_event_mux_resp = 3;
1720 + gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1721 + cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1722 + global_object[instance_id].group_id = 2;
1724 + case STATCOL_VIP2_P1:
1725 + cur_base_address = stat_coll2_base_address;
1726 + cur_event_mux_req = 4;
1727 + cur_event_mux_resp = 5;
1728 + gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1729 + cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1730 + global_object[instance_id].group_id = 2;
1732 + case STATCOL_VIP2_P2:
1733 + cur_base_address = stat_coll2_base_address;
1734 + cur_event_mux_req = 6;
1735 + cur_event_mux_resp = 7;
1736 + gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1737 + cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1738 + global_object[instance_id].group_id = 2;
1740 + case STATCOL_VIP3_P1:
1741 + cur_base_address = stat_coll2_base_address;
1742 + cur_event_mux_req = 8;
1743 + cur_event_mux_resp = 9;
1744 + gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1745 + cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1746 + global_object[instance_id].group_id = 2;
1748 + case STATCOL_VIP3_P2:
1749 + cur_base_address = stat_coll2_base_address;
1750 + cur_event_mux_req = 10;
1751 + cur_event_mux_resp = 11;
1752 + gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1753 + cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1754 + global_object[instance_id].group_id = 2;
1756 + case STATCOL_VPE_P1:
1757 + cur_base_address = stat_coll2_base_address;
1758 + cur_event_mux_req = 12;
1759 + cur_event_mux_resp = 13;
1760 + gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1761 + cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1762 + global_object[instance_id].group_id = 2;
1764 + case STATCOL_VPE_P2:
1765 + cur_base_address = stat_coll2_base_address;
1766 + cur_event_mux_req = 14;
1767 + cur_event_mux_resp = 15;
1768 + gStatColState.stat2_filter_cnt = gStatColState.stat2_filter_cnt + 1;
1769 + cur_stat_filter_cnt = gStatColState.stat2_filter_cnt;
1770 + global_object[instance_id].group_id = 2;
1772 + case STATCOL_EVE1_TC0:
1773 + cur_base_address = stat_coll3_base_address;
1774 + cur_event_mux_req = 0;
1775 + cur_event_mux_resp = 1;
1776 + gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1777 + cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1778 + global_object[instance_id].group_id = 3;
1780 + case STATCOL_EVE1_TC1:
1781 + cur_base_address = stat_coll3_base_address;
1782 + cur_event_mux_req = 2;
1783 + cur_event_mux_resp = 3;
1784 + gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1785 + cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1786 + global_object[instance_id].group_id = 3;
1788 + case STATCOL_EVE2_TC0:
1789 + cur_base_address = stat_coll3_base_address;
1790 + cur_event_mux_req = 4;
1791 + cur_event_mux_resp = 5;
1792 + gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1793 + cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1794 + global_object[instance_id].group_id = 3;
1796 + case STATCOL_EVE2_TC1:
1797 + cur_base_address = stat_coll3_base_address;
1798 + cur_event_mux_req = 6;
1799 + cur_event_mux_resp = 7;
1800 + gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1801 + cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1802 + global_object[instance_id].group_id = 3;
1804 + case STATCOL_EVE3_TC0:
1805 + cur_base_address = stat_coll3_base_address;
1806 + cur_event_mux_req = 8;
1807 + cur_event_mux_resp = 9;
1808 + gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1809 + cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1810 + global_object[instance_id].group_id = 3;
1812 + case STATCOL_EVE3_TC1:
1813 + cur_base_address = stat_coll3_base_address;
1814 + cur_event_mux_req = 10;
1815 + cur_event_mux_resp = 11;
1816 + gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1817 + cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1818 + global_object[instance_id].group_id = 3;
1820 + case STATCOL_EVE4_TC0:
1821 + cur_base_address = stat_coll3_base_address;
1822 + cur_event_mux_req = 12;
1823 + cur_event_mux_resp = 13;
1824 + gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1825 + cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1826 + global_object[instance_id].group_id = 3;
1828 + case STATCOL_EVE4_TC1:
1829 + cur_base_address = stat_coll3_base_address;
1830 + cur_event_mux_req = 14;
1831 + cur_event_mux_resp = 15;
1832 + gStatColState.stat3_filter_cnt = gStatColState.stat3_filter_cnt + 1;
1833 + cur_stat_filter_cnt = gStatColState.stat3_filter_cnt;
1834 + global_object[instance_id].group_id = 3;
1836 + case STATCOL_DSP1_MDMA:
1837 + cur_base_address = stat_coll4_base_address;
1838 + cur_event_mux_req = 0;
1839 + cur_event_mux_resp = 1;
1840 + gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1841 + cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1842 + global_object[instance_id].group_id = 4;
1844 + case STATCOL_DSP1_EDMA:
1845 + cur_base_address = stat_coll4_base_address;
1846 + cur_event_mux_req = 2;
1847 + cur_event_mux_resp = 3;
1848 + gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1849 + cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1850 + global_object[instance_id].group_id = 4;
1852 + case STATCOL_DSP2_MDMA:
1853 + cur_base_address = stat_coll4_base_address;
1854 + cur_event_mux_req = 4;
1855 + cur_event_mux_resp = 5;
1856 + gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1857 + cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1858 + global_object[instance_id].group_id = 4;
1860 + case STATCOL_DSP2_EDMA:
1861 + cur_base_address = stat_coll4_base_address;
1862 + cur_event_mux_req = 6;
1863 + cur_event_mux_resp = 7;
1864 + gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1865 + cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1866 + global_object[instance_id].group_id = 4;
1869 + cur_base_address = stat_coll4_base_address;
1870 + cur_event_mux_req = 8;
1871 + cur_event_mux_resp = 9;
1872 + gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1873 + cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1874 + global_object[instance_id].group_id = 4;
1876 + case STATCOL_GPU_P1:
1877 + cur_base_address = stat_coll4_base_address;
1878 + cur_event_mux_req = 10;
1879 + cur_event_mux_resp = 11;
1880 + gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1881 + cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1882 + global_object[instance_id].group_id = 4;
1884 + case STATCOL_GPU_P2:
1885 + cur_base_address = stat_coll4_base_address;
1886 + cur_event_mux_req = 12;
1887 + cur_event_mux_resp = 13;
1888 + gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1889 + cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1890 + global_object[instance_id].group_id = 4;
1892 + case STATCOL_BB2D_P1:
1893 + cur_base_address = stat_coll4_base_address;
1894 + cur_event_mux_req = 14;
1895 + cur_event_mux_resp = 15;
1896 + gStatColState.stat4_filter_cnt = gStatColState.stat4_filter_cnt + 1;
1897 + cur_stat_filter_cnt = gStatColState.stat4_filter_cnt;
1898 + global_object[instance_id].group_id = 4;
1901 + cur_base_address = stat_coll5_base_address;
1902 + cur_event_mux_req = 0;
1903 + cur_event_mux_resp = 1;
1904 + gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1905 + cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1906 + global_object[instance_id].group_id = 5;
1908 + case STATCOL_CSI2_2:
1909 + cur_base_address = stat_coll5_base_address;
1910 + cur_event_mux_req = 2;
1911 + cur_event_mux_resp = 3;
1912 + gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1913 + cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1914 + global_object[instance_id].group_id = 5;
1916 + case STATCOL_MMU2:
1917 + cur_base_address = stat_coll5_base_address;
1918 + cur_event_mux_req = 4;
1919 + cur_event_mux_resp = 5;
1920 + gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1921 + cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1922 + global_object[instance_id].group_id = 5;
1924 + case STATCOL_IPU1:
1925 + cur_base_address = stat_coll5_base_address;
1926 + cur_event_mux_req = 6;
1927 + cur_event_mux_resp = 7;
1928 + gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1929 + cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1930 + global_object[instance_id].group_id = 5;
1932 + case STATCOL_IPU2:
1933 + cur_base_address = stat_coll5_base_address;
1934 + cur_event_mux_req = 8;
1935 + cur_event_mux_resp = 9;
1936 + gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1937 + cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1938 + global_object[instance_id].group_id = 5;
1940 + case STATCOL_DMA_SYSTEM_RD:
1941 + cur_base_address = stat_coll5_base_address;
1942 + cur_event_mux_req = 10;
1943 + cur_event_mux_resp = 11;
1944 + gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1945 + cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1946 + global_object[instance_id].group_id = 5;
1948 + case STATCOL_DMA_SYSTEM_WR:
1949 + cur_base_address = stat_coll5_base_address;
1950 + cur_event_mux_req = 12;
1951 + cur_event_mux_resp = 13;
1952 + gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1953 + cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1954 + global_object[instance_id].group_id = 5;
1956 + case STATCOL_CSI2_1:
1957 + cur_base_address = stat_coll5_base_address;
1958 + cur_event_mux_req = 14;
1959 + cur_event_mux_resp = 15;
1960 + gStatColState.stat5_filter_cnt = gStatColState.stat5_filter_cnt + 1;
1961 + cur_stat_filter_cnt = gStatColState.stat5_filter_cnt;
1962 + global_object[instance_id].group_id = 5;
1964 + case STATCOL_USB3_SS:
1965 + cur_base_address = stat_coll6_base_address;
1966 + cur_event_mux_req = 0;
1967 + cur_event_mux_resp = 1;
1968 + gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
1969 + cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
1970 + global_object[instance_id].group_id = 6;
1972 + case STATCOL_USB2_SS:
1973 + cur_base_address = stat_coll6_base_address;
1974 + cur_event_mux_req = 2;
1975 + cur_event_mux_resp = 3;
1976 + gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
1977 + cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
1978 + global_object[instance_id].group_id = 6;
1980 + case STATCOL_USB2_ULPI_SS1:
1981 + cur_base_address = stat_coll6_base_address;
1982 + cur_event_mux_req = 4;
1983 + cur_event_mux_resp = 5;
1984 + gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
1985 + cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
1986 + global_object[instance_id].group_id = 6;
1988 + case STATCOL_USB2_ULPI_SS2:
1989 + cur_base_address = stat_coll6_base_address;
1990 + cur_event_mux_req = 6;
1991 + cur_event_mux_resp = 7;
1992 + gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
1993 + cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
1994 + global_object[instance_id].group_id = 6;
1996 + case STATCOL_PCIE_SS1:
1997 + cur_base_address = stat_coll6_base_address;
1998 + cur_event_mux_req = 8;
1999 + cur_event_mux_resp = 9;
2000 + gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
2001 + cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
2002 + global_object[instance_id].group_id = 6;
2004 + case STATCOL_PCIE_SS2:
2005 + cur_base_address = stat_coll6_base_address;
2006 + cur_event_mux_req = 10;
2007 + cur_event_mux_resp = 11;
2008 + gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
2009 + cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
2010 + global_object[instance_id].group_id = 6;
2012 + case STATCOL_DSP1_CFG:
2013 + cur_base_address = stat_coll6_base_address;
2014 + cur_event_mux_req = 12;
2015 + cur_event_mux_resp = 13;
2016 + gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
2017 + cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
2018 + global_object[instance_id].group_id = 6;
2020 + case STATCOL_DSP2_CFG:
2021 + cur_base_address = stat_coll6_base_address;
2022 + cur_event_mux_req = 14;
2023 + cur_event_mux_resp = 15;
2024 + gStatColState.stat6_filter_cnt = gStatColState.stat6_filter_cnt + 1;
2025 + cur_stat_filter_cnt = gStatColState.stat6_filter_cnt;
2026 + global_object[instance_id].group_id = 6;
2028 + case STATCOL_GMAC_SW:
2029 + cur_base_address = stat_coll7_base_address;
2030 + cur_event_mux_req = 0;
2031 + cur_event_mux_resp = 1;
2032 + gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2033 + cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2034 + global_object[instance_id].group_id = 7;
2036 + case STATCOL_PRUSS1_P1:
2037 + cur_base_address = stat_coll7_base_address;
2038 + cur_event_mux_req = 2;
2039 + cur_event_mux_resp = 3;
2040 + gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2041 + cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2042 + global_object[instance_id].group_id = 7;
2044 + case STATCOL_PRUSS1_P2:
2045 + cur_base_address = stat_coll7_base_address;
2046 + cur_event_mux_req = 4;
2047 + cur_event_mux_resp = 5;
2048 + gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2049 + cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2050 + global_object[instance_id].group_id = 7;
2052 + case STATCOL_PRUSS2_P1:
2053 + cur_base_address = stat_coll7_base_address;
2054 + cur_event_mux_req = 6;
2055 + cur_event_mux_resp = 7;
2056 + gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2057 + cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2058 + global_object[instance_id].group_id = 7;
2060 + case STATCOL_PRUSS2_P2:
2061 + cur_base_address = stat_coll7_base_address;
2062 + cur_event_mux_req = 8;
2063 + cur_event_mux_resp = 9;
2064 + gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2065 + cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2066 + global_object[instance_id].group_id = 7;
2068 + case STATCOL_DMA_CRYPTO_RD:
2069 + cur_base_address = stat_coll7_base_address;
2070 + cur_event_mux_req = 10;
2071 + cur_event_mux_resp = 11;
2072 + gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2073 + cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2074 + global_object[instance_id].group_id = 7;
2076 + case STATCOL_DMA_CRYPTO_WR:
2077 + cur_base_address = stat_coll7_base_address;
2078 + cur_event_mux_req = 12;
2079 + cur_event_mux_resp = 13;
2080 + gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2081 + cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2082 + global_object[instance_id].group_id = 7;
2084 + case STATCOL_MPU2:
2085 + cur_base_address = stat_coll7_base_address;
2086 + cur_event_mux_req = 14;
2087 + cur_event_mux_resp = 15;
2088 + gStatColState.stat7_filter_cnt = gStatColState.stat7_filter_cnt + 1;
2089 + cur_stat_filter_cnt = gStatColState.stat7_filter_cnt;
2090 + global_object[instance_id].group_id = 7;
2092 + case STATCOL_MMC1:
2093 + cur_base_address = stat_coll8_base_address;
2094 + cur_event_mux_req = 0;
2095 + cur_event_mux_resp = 1;
2096 + gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2097 + cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2098 + global_object[instance_id].group_id = 8;
2100 + case STATCOL_MMC2:
2101 + cur_base_address = stat_coll8_base_address;
2102 + cur_event_mux_req = 2;
2103 + cur_event_mux_resp = 3;
2104 + gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2105 + cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2106 + global_object[instance_id].group_id = 8;
2108 + case STATCOL_SATA:
2109 + cur_base_address = stat_coll8_base_address;
2110 + cur_event_mux_req = 4;
2111 + cur_event_mux_resp = 5;
2112 + gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2113 + cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2114 + global_object[instance_id].group_id = 8;
2116 + case STATCOL_MLBSS:
2117 + cur_base_address = stat_coll8_base_address;
2118 + cur_event_mux_req = 6;
2119 + cur_event_mux_resp = 7;
2120 + gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2121 + cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2122 + global_object[instance_id].group_id = 8;
2124 + case STATCOL_BB2D_P2:
2125 + cur_base_address = stat_coll8_base_address;
2126 + cur_event_mux_req = 8;
2127 + cur_event_mux_resp = 9;
2128 + gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2129 + cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2130 + global_object[instance_id].group_id = 8;
2132 + case STATCOL_IEEE1500:
2133 + cur_base_address = stat_coll8_base_address;
2134 + cur_event_mux_req = 10;
2135 + cur_event_mux_resp = 11;
2136 + gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2137 + cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2138 + global_object[instance_id].group_id = 8;
2141 + cur_base_address = stat_coll8_base_address;
2142 + cur_event_mux_req = 12;
2143 + cur_event_mux_resp = 13;
2144 + gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2145 + cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2146 + global_object[instance_id].group_id = 8;
2148 + case STATCOL_VCP1:
2149 + cur_base_address = stat_coll8_base_address;
2150 + cur_event_mux_req = 14;
2151 + cur_event_mux_resp = 15;
2152 + gStatColState.stat8_filter_cnt = gStatColState.stat8_filter_cnt + 1;
2153 + cur_stat_filter_cnt = gStatColState.stat8_filter_cnt;
2154 + global_object[instance_id].group_id = 8;
2156 + case STATCOL_OCMC_RAM1:
2157 + cur_base_address = stat_coll9_base_address;
2158 + cur_event_mux_req = 0;
2159 + cur_event_mux_resp = 1;
2160 + gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2161 + cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2162 + global_object[instance_id].group_id = 9;
2164 + case STATCOL_OCMC_RAM2:
2165 + cur_base_address = stat_coll9_base_address;
2166 + cur_event_mux_req = 2;
2167 + cur_event_mux_resp = 3;
2168 + gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2169 + cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2170 + global_object[instance_id].group_id = 9;
2172 + case STATCOL_OCMC_RAM3:
2173 + cur_base_address = stat_coll9_base_address;
2174 + cur_event_mux_req = 4;
2175 + cur_event_mux_resp = 5;
2176 + gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2177 + cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2178 + global_object[instance_id].group_id = 9;
2180 + case STATCOL_GPMC:
2181 + cur_base_address = stat_coll9_base_address;
2182 + cur_event_mux_req = 6;
2183 + cur_event_mux_resp = 7;
2184 + gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2185 + cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2186 + global_object[instance_id].group_id = 9;
2188 + case STATCOL_MCASP1:
2189 + cur_base_address = stat_coll9_base_address;
2190 + cur_event_mux_req = 8;
2191 + cur_event_mux_resp = 9;
2192 + gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2193 + cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2194 + global_object[instance_id].group_id = 9;
2196 + case STATCOL_MCASP2:
2197 + cur_base_address = stat_coll9_base_address;
2198 + cur_event_mux_req = 10;
2199 + cur_event_mux_resp = 11;
2200 + gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2201 + cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2202 + global_object[instance_id].group_id = 9;
2204 + case STATCOL_MCASP3:
2205 + cur_base_address = stat_coll9_base_address;
2206 + cur_event_mux_req = 12;
2207 + cur_event_mux_resp = 13;
2208 + gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2209 + cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2210 + global_object[instance_id].group_id = 9;
2212 + case STATCOL_VCP2:
2213 + cur_base_address = stat_coll9_base_address;
2214 + cur_event_mux_req = 14;
2215 + cur_event_mux_resp = 15;
2216 + gStatColState.stat9_filter_cnt = gStatColState.stat9_filter_cnt + 1;
2217 + cur_stat_filter_cnt = gStatColState.stat9_filter_cnt;
2218 + global_object[instance_id].group_id = 9;
2221 + printf("ERROR: Unknown initiator %d\n", instance_id);
2226 + if ( cur_stat_filter_cnt > 4 )
2228 + printf("WARNING: We have exhausted filters/counters.....\n");
2231 + // Global Enable Stat Collector
2232 + wr_stat_reg(cur_base_address+0x8,0x1);
2234 + // Soft Enable Stat Collector
2235 + wr_stat_reg(cur_base_address+0xC,0x1);
2237 + wr_stat_reg(cur_base_address+0x18,0x5);
2238 + // Operation of Stat Collector / RespEvt => Packet
2239 + wr_stat_reg(cur_base_address+0x1C,0x5);
2243 + wr_stat_reg(cur_base_address+0x20+4*(cur_stat_filter_cnt-1),cur_event_mux_req);
2245 + // Op is EventInfo
2246 + wr_stat_reg(cur_base_address+0x1FC+(0x158*(cur_stat_filter_cnt-1)),2);
2248 + // Event Info Sel Op -> packet length
2249 + wr_stat_reg(cur_base_address+0x1F8+(0x158*(cur_stat_filter_cnt-1)),0);
2251 + // Filter Global Enable
2252 + wr_stat_reg(cur_base_address+0xAC+(0x158*(cur_stat_filter_cnt-1)),0x1);
2255 + wr_stat_reg(cur_base_address+0xBC+(0x158*(cur_stat_filter_cnt-1)),0x1);
2258 + wr_stat_reg(cur_base_address+0x54,0x1);
2259 + // use send register to reset counters
2263 + global_object[instance_id].mux_req = cur_event_mux_req;
2264 + global_object[instance_id].base_address = cur_base_address;
2265 + global_object[instance_id].counter_id = cur_stat_filter_cnt;
2266 + global_object[instance_id].b_enabled = 1;
2268 + return cur_stat_filter_cnt;
2273 +void statCollectorReadGroup(UInt32 group_id)
2276 + UInt32 cur_base_address = 0x45001000 + ((group_id - 1) * 0x1000);
2278 + wr_stat_reg(cur_base_address+0xC,0x0);
2280 + for(i=0; i < STATCOL_MAX; i++)
2282 + if(global_object[i].group_id == (group_id - 1) &&
2283 + global_object[i].b_enabled == 1)
2285 + UInt32 cur_stat_filter_cnt = global_object[i].counter_id;
2287 + global_object[i].readings[statCountIdx] = rd_stat_reg(cur_base_address+0x8C+((cur_stat_filter_cnt-1)*4));
2291 + wr_stat_reg(cur_base_address+0xC,0x1);
2295 +volatile sig_atomic_t sigtermed = 0;
2297 +void my_signal_handler(int signum)
2299 + if (signum == SIGTERM || signum == SIGINT) {
2312 +struct time_graph_create_params p;
2313 +char xpos_string[100], ypos_string[100];
2315 +void mpu_handler(int command)
2320 + char * tabledata= "/tmp/statcollfifo";
2323 + static int offset = 13;
2328 + fd = open(tabledata, O_RDONLY|O_NONBLOCK);
2333 + /* open, read, and display the message from the FIFO */
2334 + bytes=read(fd, buf, 1000);
2339 + sscanf(buf, "%s %s", str, value);
2340 + if(strcmp(str, "MOVE:") == 0)
2342 + printf("Received MOVE command : %s\n", buf);
2343 + sprintf(p.title, "CPU Usage[@position-req=%sx%s]", value, ypos_string);
2344 + move_graph(ctx, &p);
2348 + printf("ERROR: Received unexpected data from FIFO - \" %s \" \n", buf);
2350 + memset(buf, 0x0, sizeof(buf));
2364 +UInt32 statcoll_start(UInt32 TOTAL_TIME, UInt32 INTERVAL_US, char list[][50], UInt32 xpos, UInt32 ypos)
2367 + UInt32 counterIdDss, counterIdIva, counterIdBB2dP1, counterIdBB2dP2, counterIdUsb4, counterIdSata, counterIdEmif1, counterIdEmif2;
2369 + if (SIG_ERR == signal(SIGPIPE,SIG_IGN))
2372 + if (SIG_ERR == signal(SIGINT,my_signal_handler))
2375 + if (SIG_ERR == signal(SIGTERM,my_signal_handler))
2379 + struct timeval tv1, tv2;
2380 + gettimeofday(&tv1, NULL);
2381 + printf("------------------------------------------------\n");
2382 + printf("Compile time = %s %s\n",__DATE__, __TIME__);
2383 + printf("------------------------------------------------\n\n");
2384 + //printd("Start time = %d\n", time(NULL));
2385 + //printd("Time seconds = %d, usecs = %d\n", tv.tv_sec, tv.tv_usec);
2387 + statcoll_params params;
2388 + memset(¶ms, sizeof(params), 0);
2389 + params.INTERVAL_US = INTERVAL_US;
2390 + params.TOTAL_TIME = TOTAL_TIME;
2395 + while(list[i][0] != 0)
2397 + for(index=0; index< STATCOL_MAX; index++) {
2398 + if(strcmp(list[i], initiators[index].name) == 0)
2400 + strcpy(params.user_config_list[params.no_of_initiators].name, list[i]);
2401 + params.user_config_list[params.no_of_initiators++].id = initiators[index].id;
2406 + if(index == STATCOL_MAX) {
2407 + printf("ERROR: Unknown initiator.%d.. .%s. \n", i, list[i]);
2413 + struct bar_graph_create_params bg_p;
2414 + struct _y_config *y_cfg;
2415 + struct _text_config *t_cfg;
2418 + char *text_list[STATCOL_MAX];
2420 + struct _bar_graph_y_config *bg_y_cfg;
2421 + struct _text_config *bg_t_cfg;
2422 + char *bg_text_list[STATCOL_MAX];
2424 + sprintf(xpos_string, "%d", xpos);
2425 + sprintf(ypos_string, "%d", ypos);
2426 + p.title=(char *)malloc(100);
2427 + sprintf(p.title, "CPU Usage[@position-req=%sx%s]", xpos_string, ypos_string);
2428 + //p.height = MAX_HEIGHT - HEIGHT_EMIF_AREA;
2429 + p.height = MAX_HEIGHT;// - HEIGHT_EMIF_AREA;
2430 + p.width = MAX_WIDTH;
2431 + p.draw_area.bottom_left.x = TIME_GRAPH_AREA_BL_X;
2432 + p.draw_area.bottom_left.y = TIME_GRAPH_AREA_BL_Y;
2433 + p.draw_area.top_right.x = TIME_GRAPH_AREA_TR_X;
2434 + p.draw_area.top_right.y = TIME_GRAPH_AREA_TR_Y;
2435 + p.time_span = 120000; // 120 seconds
2436 + p.num_of_y_items = params.no_of_initiators+1;
2437 + p.num_of_text_items = 0;//params.no_of_initiators;
2440 + y_cfg = malloc((params.no_of_initiators+1) * sizeof(struct _y_config));
2441 + t_cfg = malloc(params.no_of_initiators * sizeof(struct _text_config));
2442 + y = malloc((params.no_of_initiators+1) * sizeof(double));
2443 + p.y_config_array = y_cfg;
2444 + p.text_config_array = t_cfg;
2446 + bg_y_cfg = malloc(TOTAL_Y_PARAMETERS * sizeof(struct _bar_graph_y_config));
2447 + bg_t_cfg = malloc(TOTAL_Y_PARAMETERS * sizeof(struct _text_config));
2448 + bg_y = malloc(TOTAL_Y_PARAMETERS * sizeof(double));
2450 + for(i=0; i<TOTAL_Y_PARAMETERS; i++)
2452 + bg_text_list[i] = malloc(100);
2453 + strcpy(bg_text_list[i],"test");
2456 + create_overall_box(bg_y_cfg, bg_t_cfg, bg_text_list);
2460 + while(i < params.no_of_initiators)
2462 + text_list[i] = malloc(100 * sizeof(char));
2463 + memset(text_list[i], 0x0, 100);
2465 + ((struct _y_config *)y_cfg+i)->line_color.r = pallette[i%MAX_COLORS].r;
2466 + ((struct _y_config *)y_cfg+i)->line_color.g = pallette[i%MAX_COLORS].g;
2467 + ((struct _y_config *)y_cfg+i)->line_color.b = pallette[i%MAX_COLORS].b;
2468 + ((struct _y_config *)y_cfg+i)->line_color.a = 0.0;//pallette[i%MAX_COLORS].a;
2470 + ((struct _y_config *)y_cfg+i)->fill_color.r = 0.0;
2471 + ((struct _y_config *)y_cfg+i)->fill_color.g = 1.0;
2472 + ((struct _y_config *)y_cfg+i)->fill_color.b = 0.0;
2473 + ((struct _y_config *)y_cfg+i)->fill_color.a = 0.5;
2478 + ((struct _y_config *)y_cfg+i)->line_color.r = 0.0;
2479 + ((struct _y_config *)y_cfg+i)->line_color.g = 0.0;
2480 + ((struct _y_config *)y_cfg+i)->line_color.b = 0.0;
2481 + ((struct _y_config *)y_cfg+i)->line_color.a = 0.5;
2482 + ((struct _y_config *)y_cfg+i)->fill_color.r = 0.1;
2483 + ((struct _y_config *)y_cfg+i)->fill_color.g = 0.9;
2484 + ((struct _y_config *)y_cfg+i)->fill_color.b = 0.5;
2485 + ((struct _y_config *)y_cfg+i)->fill_color.a = 1.0;
2487 + bg_p.title = "CPU Usage";
2489 + bg_p.num_of_y_items = TOTAL_Y_PARAMETERS;
2490 + bg_p.y_config_array = bg_y_cfg;
2491 + bg_p.num_of_text_items = TOTAL_Y_PARAMETERS;
2492 + bg_p.text_config_array = bg_t_cfg;
2497 + ctx = time_graph_create(argc, argv, &p);
2499 + printf("Error creating context\n");
2503 + printf("\n Context after time_graph_create = 0x%x\n", ctx);
2504 + ctx = bar_graph_create(argc, argv, &bg_p);
2506 + printf("Error creating context\n");
2510 + printf("\n Context after bar_graph_create= 0x%x\n", ctx);
2512 + printf("Total configured initiators = %d\n", params.no_of_initiators);
2515 + fd = open("/dev/mem", O_RDWR);
2517 + printf("error fd=open() \n");
2520 + statcoll_base_mem = mmap(NULL, STATCOLL_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, STATCOLL_BASE);
2522 + if (statcoll_base_mem == MAP_FAILED){
2523 + printf("ERROR: mmap failed \n");
2528 + fd = open("/dev/mem", O_RDWR);
2530 + printf("error fd=open() \n");
2533 + l3_3_clkctrl = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, CM_L3INSTR_REGISTER_BASE);
2534 + if (l3_3_clkctrl == MAP_FAILED){
2535 + printf("ERROR: mmap failed for CM_L3INSTR_REGISTER_BASE\n");
2540 + printf("SUCCESS: Mapped 0x%x to user space address 0x%x\n", STATCOLL_BASE, statcoll_base_mem);
2541 + printf("INTERVAL = %d usecs\n", INTERVAL_US);
2542 + printf("TOTAL TIME = %d seconds\n", TOTAL_TIME);
2543 + TRACE_SZ = (TOTAL_TIME * 1000000)/INTERVAL_US;
2544 + printf("TRACE SIZE = %d samples\n", TRACE_SZ);
2546 + printf("**************************************\n");
2547 + printf("Going to initialize the L3 clocks \n");
2548 + l3_3_clkctrl[CM_L3INSTR_L3INSTR_CLKSTCTRL_OFFSET >> 2] = 0x2;
2549 + l3_3_clkctrl[CM_L3INSTR_L3_MAIN_2_CLKCTRL_OFFSET >> 2] = 0x1;
2550 + printf("**************************************\n");
2552 + while( (l3_3_clkctrl[CM_L3INSTR_L3_MAIN_2_CLKCTRL_OFFSET >> 2] & 0x30000) != 0x0)
2554 + printf("Waiting on module to be functional\n");
2557 + statCollectorInit();
2559 + printf("SUCCESS: Initialized STAT COLLECTOR\n");
2560 + /* Initialize all enabled initiators */
2561 + for(index =0; index < params.no_of_initiators; index++) {
2562 + printf("\t\t Initialized %s\n", params.user_config_list[index].name);
2563 + statCollectorControlInitialize(params.user_config_list[index].id);
2566 + const char *bg_text = "CPU Utilization";
2568 + int second_counter=0;
2569 + memset(y, 0x0, sizeof(double)* (params.no_of_initiators+1));
2574 + mpu_handler(OPEN);
2577 + while(statCountIdx != (TRACE_SZ - 1))
2579 + usleep(INTERVAL_US);
2581 + for(group = 1; group<11; group++)
2582 + statCollectorReadGroup(group);
2584 + mpu_handler(READ);
2586 + if(statCountIdx != 0 )
2587 + for(i=0; i<params.no_of_initiators; i++) {
2588 + y[i] += (double)(global_object[params.user_config_list[i].id].readings[statCountIdx])/ (8000000000);
2592 + if(second_counter % 30 == 0)
2595 + for(i=0; i<TOTAL_Y_PARAMETERS; i++) {
2602 + sprintf(bg_text_list[8], "%02.1f%s", y[0]*100, "%");
2603 + sprintf(bg_text_list[10], "%02.1f%s", y[1]*100, "%");
2605 + struct sort sort_array[STATCOL_MAX];
2606 + memset(sort_array, 0x0, sizeof(struct sort) * STATCOL_MAX);
2608 + for(i=2; i<params.no_of_initiators; i++) {
2609 + sort_array[i-2].value = y[i];
2610 + sort_array[i-2].pos = i;
2614 + double tempdouble;
2616 + for(i=0; i<params.no_of_initiators-2; i++) {
2617 + for(j=i+1; j<params.no_of_initiators-2; j++) {
2618 + if(sort_array[i].value < sort_array[j].value) {
2619 + tempdouble = sort_array[j].value;
2620 + tempint = sort_array[j].pos;
2622 + sort_array[j].value = sort_array[i].value;
2623 + sort_array[j].pos = sort_array[i].pos;
2625 + sort_array[i].value = tempdouble;
2626 + sort_array[i].pos = tempint;
2631 + for(i=0; i<6; i++)
2634 + bg_y[14+i*2] = sort_array[i].value*2;
2635 + sprintf(bg_text_list[13+i*2], "%02.1f%s", sort_array[i].value*100, "%");
2636 + sprintf(bg_text_list[14+i*2], "%s", (params.user_config_list[sort_array[i].pos].name)+8);
2639 + bar_graph_plot(ctx, bg_y, (const char **)bg_text_list);
2641 + y[params.no_of_initiators]=y[0]+y[1];
2642 + time_graph_plot(ctx, y, (const char **)text_list);
2643 + //printf("Plotting the time_graph\n");
2644 + memset(y, 0x0, sizeof(double)* (params.no_of_initiators+1));
2650 + mpu_handler(CLOSE);
2652 + printf("------------------------------------------------\n\n");
2653 + printf("SUCCESS: Stat collection completed... Writing into file now\n");
2654 + FILE *outfile = fopen("statcollector.csv", "w+");
2656 + printf("\n ERROR: Error opening file");
2659 + /* Ignore the first index at 0 */
2660 + for(index=1; index<statCountIdx; index++) {
2661 + for(i=0; i<params.no_of_initiators; i++) {
2662 + fprintf(outfile,"%s = %d,", params.user_config_list[i].name, global_object[params.user_config_list[i].id].readings[index]);
2664 + fprintf(outfile,"\n");
2668 + time_graph_destroy(ctx);
2669 + gettimeofday(&tv2, NULL);
2670 + //printf("End time = %d\n", time(NULL));
2671 + //printf("Time seconds = %d, usecs = %d\n", tv.tv_sec, tv.tv_usec);
2672 + printf("Total execution time = %d secs, %d usecs\n\n", (tv2.tv_sec - tv1.tv_sec), (tv2.tv_usec - tv2.tv_usec));
2678 diff --git a/clients/statcoll.h b/clients/statcoll.h
2679 new file mode 100644
2680 index 0000000..fa92753
2682 +++ b/clients/statcoll.h
2684 +#ifndef __STATCOLL_H
2685 +#define __STATCOLL_H
2688 +#define CM_L3INSTR_REGISTER_BASE (0x4A008000)
2690 +#define CM_L3INSTR_L3INSTR_CLKSTCTRL_OFFSET (0xE00)
2691 +#define CM_L3INSTR_L3_MAIN_2_CLKCTRL_OFFSET (0xE20)
2693 +#define STATCOLL_SIZE 40960
2694 +#define STATCOLL_BASE (0x45001000)
2696 +#define stat_coll0_base_address (0x45001000)
2697 +#define stat_coll1_base_address (0x45002000)
2698 +#define stat_coll2_base_address (0x45003000)
2699 +#define stat_coll3_base_address (0x45004000)
2700 +#define stat_coll4_base_address (0x45005000)
2701 +#define stat_coll5_base_address (0x45006000)
2702 +#define stat_coll6_base_address (0x45007000)
2703 +#define stat_coll7_base_address (0x45008000)
2704 +#define stat_coll8_base_address (0x45009000)
2705 +#define stat_coll9_base_address (0x4500a000)
2707 +#define printd(fmt, ...) \
2708 + do { if (debug) fprintf(stderr, fmt, __VA_ARGS__); } while (0)
2710 +typedef unsigned int UInt32;
2715 + STATCOL_EMIF1_SYS,
2716 + STATCOL_EMIF2_SYS,
2717 + STATCOL_MA_MPU_P1,
2718 + STATCOL_MA_MPU_P2,
2741 + STATCOL_DSP1_MDMA,
2742 + STATCOL_DSP1_EDMA,
2743 + STATCOL_DSP2_MDMA,
2744 + STATCOL_DSP2_EDMA,
2754 + STATCOL_DMA_SYSTEM_RD,
2755 + STATCOL_DMA_SYSTEM_WR,
2759 + STATCOL_USB2_ULPI_SS1,
2760 + STATCOL_USB2_ULPI_SS2,
2766 + STATCOL_PRUSS1_P1,
2767 + STATCOL_PRUSS1_P2,
2768 + STATCOL_PRUSS2_P1,
2769 + STATCOL_PRUSS2_P2,
2770 + STATCOL_DMA_CRYPTO_RD,
2771 + STATCOL_DMA_CRYPTO_WR,
2781 + STATCOL_OCMC_RAM1,
2782 + STATCOL_OCMC_RAM2,
2783 + STATCOL_OCMC_RAM3,
2796 + UInt32 stat0_filter_cnt;
2797 + UInt32 stat1_filter_cnt;
2798 + UInt32 stat2_filter_cnt;
2799 + UInt32 stat3_filter_cnt;
2800 + UInt32 stat4_filter_cnt;
2801 + UInt32 stat5_filter_cnt;
2802 + UInt32 stat6_filter_cnt;
2803 + UInt32 stat7_filter_cnt;
2804 + UInt32 stat8_filter_cnt;
2805 + UInt32 stat9_filter_cnt;
2806 +} StatCollectorObj;
2808 +struct list_of_initiators
2816 + UInt32 INTERVAL_US;
2817 + UInt32 TOTAL_TIME;
2818 + UInt32 no_of_initiators;
2819 + struct list_of_initiators user_config_list[STATCOL_MAX];
2827 + UInt32 *timestamp;
2829 + UInt32 counter_id;
2830 + UInt32 base_address;
2832 +}statcoll_initiators_object;
2836 diff --git a/clients/statcoll_gui.h b/clients/statcoll_gui.h
2837 new file mode 100644
2838 index 0000000..7362bde
2840 +++ b/clients/statcoll_gui.h
2845 + ---------------------------------------------
2847 + | --------------------------------------- |
2863 + ---------------------------------------------
2870 + ---------------------------------------------
2876 +#define POSITION_X 2800
2877 +#define POSITION_Y 40
2879 +#define MAX_WIDTH 900
2880 +//#define MAX_WIDTH 528
2881 +#define MAX_HEIGHT 900
2883 +/* Derived parameters */
2884 +#define BAR_GAP (MAX_WIDTH/25)
2885 +#define BAR_WIDTH (MAX_WIDTH/16)
2887 +#define BAR_HEIGHT ((MX_HEIGHT/40) * 6)
2889 +#define BORDER (MAX_WIDTH/15)
2891 +#define HEIGHT_EMIF_AREA (MAX_HEIGHT/4)
2893 +#define FONT_SIZE (MAX_WIDTH/40)
2895 +#define WIDTH_EMIF_AREA (MAX_WIDTH / 4)
2897 +#define TOTAL_Y_PARAMETERS (25)
2899 +#define TIME_GRAPH_AREA_BL_X (BORDER)
2900 +#define TIME_GRAPH_AREA_BL_Y (MAX_HEIGHT - HEIGHT_EMIF_AREA - BORDER)
2901 +#define TIME_GRAPH_AREA_TR_X (MAX_WIDTH - BORDER)
2902 +#define TIME_GRAPH_AREA_TR_Y (BORDER)
2904 +#define EMIF_AREA_BL_X (0)
2905 +#define EMIF_AREA_BL_Y (MAX_HEIGHT)
2906 +#define EMIF_AREA_TR_X (WIDTH_EMIF_AREA)
2907 +#define EMIF_AREA_TR_Y (MAX_HEIGHT - HEIGHT_EMIF_AREA)
2909 +#define INITIATORS_AREA_BL_X (WIDTH_EMIF_AREA)
2910 +#define INITIATORS_AREA_BL_Y (MAX_HEIGHT)
2911 +#define INITIATORS_AREA_TR_X (MAX_WIDTH)
2912 +#define INITIATORS_AREA_TR_Y (MAX_HEIGHT - HEIGHT_EMIF_AREA)
2915 +const char *string_list[TOTAL_Y_PARAMETERS] = {
2916 + "----DDR BANDWIDTH PLOT----",
2928 + "TOP 6 INITIATORS",
2943 diff --git a/clients/time_bar_graph.c b/clients/time_bar_graph.c
2944 new file mode 100644
2945 index 0000000..9fa9c12
2947 +++ b/clients/time_bar_graph.c
2950 + * Copyright © 2008 Kristian Høgsberg
2952 + * Permission to use, copy, modify, distribute, and sell this software and its
2953 + * documentation for any purpose is hereby granted without fee, provided that
2954 + * the above copyright notice appear in all copies and that both that copyright
2955 + * notice and this permission notice appear in supporting documentation, and
2956 + * that the name of the copyright holders not be used in advertising or
2957 + * publicity pertaining to distribution of the software without specific,
2958 + * written prior permission. The copyright holders make no representations
2959 + * about the suitability of this software for any purpose. It is provided "as
2960 + * is" without express or implied warranty.
2962 + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
2963 + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
2964 + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
2965 + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
2966 + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
2967 + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
2968 + * OF THIS SOFTWARE.
2971 +#include <stdint.h>
2973 +#include <stdlib.h>
2974 +#include <string.h>
2975 +#include <stdint.h>
2976 +#include <signal.h>
2980 +#include <sys/time.h>
2981 +#include <pthread.h>
2983 +#include <unistd.h>
2984 +#include <sys/eventfd.h>
2985 +#include <sys/epoll.h>
2987 +#include <linux/input.h>
2988 +#include <wayland-client.h>
2989 +#include "window.h"
2990 +#include "../shared/cairo-util.h"
2991 +#include "time_bar_graph.h"
2995 +#define DBG(x...) printf(x)
2997 +#define DBG(x...) // printf(x)
3000 +#define MAX_ITEMS 180
3001 +#define MAX_TEXT_SIZE 128
3003 +struct graph_dataset_point {
3005 + double y_values[MAX_ITEMS];
3008 +struct graph_data {
3010 + int first_index, last_index, num_elems;
3011 + uint64_t last_time;
3012 + struct graph_dataset_point dataset[1];
3016 + struct display *display;
3017 + struct window *window;
3018 + struct widget *widget;
3019 + int width, height;
3020 + struct time_graph_create_params params;
3021 + struct bar_graph_create_params bar_graph_params;
3022 + struct _y_config y_config_array[MAX_ITEMS];
3023 + struct _text_config text_config_array[MAX_ITEMS];
3025 + /* Bar graph parameters */
3026 + struct _bar_graph_y_config bar_graph_y_config_array[MAX_ITEMS];
3027 + struct _text_config bar_graph_text_config_array[MAX_ITEMS];
3032 + double x_scaling_factor;
3033 + pthread_mutex_t mtx;
3034 + double time_graph_y_values[MAX_ITEMS];
3035 + char text_values[MAX_ITEMS][MAX_TEXT_SIZE];
3037 + double bar_graph_y_values[MAX_ITEMS];
3038 + char bar_graph_text_values[MAX_ITEMS][MAX_TEXT_SIZE];
3040 + uint64_t time_now;
3041 + time_t start_time_tv_sec;
3042 + struct graph_data *data;
3045 +struct graph *global_graph=NULL;
3047 +draw_stuff(struct graph *g, cairo_surface_t *surface)
3050 + int i, j, n_elems;
3051 + double c_x, c_y, d_x, d_y;
3053 + cr = cairo_create(surface);
3054 + cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
3055 + cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.5);
3057 + cairo_select_font_face(cr, "mono",
3058 + CAIRO_FONT_SLANT_NORMAL,
3059 + CAIRO_FONT_WEIGHT_BOLD);
3060 + cairo_set_line_width (cr, 1.0);
3061 + cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
3062 + pthread_mutex_lock(&g->mtx);
3063 + for (j=0; g->data->num_elems > 0 && j<g->params.num_of_y_items; j++) {
3064 + n_elems = g->data->num_elems;
3065 + DBG("first_index: %d, last_index: %d\n", g->data->first_index, g->data->last_index);
3066 + if (g->y_config_array[j].fill_color.a != 0.0)
3067 + cairo_move_to(cr, (double)g->params.draw_area.bottom_left.x, (double)g->params.draw_area.bottom_left.y);
3068 + c_x = (double)g->params.draw_area.bottom_left.x;
3069 + c_y = (double)g->params.draw_area.bottom_left.y;
3071 + i = g->data->first_index;
3073 + DBG("index: %d, x: %f, y: %f, next_index: %d\n", i, c_x,
3074 + g->data->dataset[i].y_values[j], g->data->dataset[i].next_index);
3075 + d_y = g->data->dataset[i].y_values[j] - c_y;
3076 + c_y = g->data->dataset[i].y_values[j];
3078 + if (g->y_config_array[j].fill_color.a == 0.0 && n_elems == g->data->num_elems) {
3079 + cairo_move_to(cr, c_x, c_y);
3081 + cairo_curve_to(cr, c_x - (d_x * 0.75), c_y - (d_y * 0.92), c_x - (d_x * 0.25), c_y - (d_y * 0.08), c_x, c_y);
3083 + if (g->data->dataset[i].next_index > i) {
3084 + d_x = (g->data->dataset[i].next_index - i);
3086 + d_x = (g->data->dataset_size + g->data->dataset[i].next_index - i);
3088 + i = g->data->dataset[i].next_index;
3091 + if (g->y_config_array[j].fill_color.a != 0.0) {
3092 + cairo_line_to(cr, c_x, (double)g->params.draw_area.bottom_left.y);
3093 + cairo_line_to(cr, (double)g->params.draw_area.bottom_left.x, (double)g->params.draw_area.bottom_left.y);
3094 + cairo_close_path(cr);
3095 + cairo_set_source_rgba(cr, g->y_config_array[j].fill_color.r, g->y_config_array[j].fill_color.g,
3096 + g->y_config_array[j].fill_color.b, g->y_config_array[j].fill_color.a);
3097 + cairo_fill_preserve(cr);
3099 + cairo_set_source_rgba(cr, g->y_config_array[j].line_color.r, g->y_config_array[j].line_color.g,
3100 + g->y_config_array[j].line_color.b, g->y_config_array[j].line_color.a);
3104 + for (j=0; j<g->params.num_of_text_items; j++) {
3105 + cairo_move_to(cr, (double)g->text_config_array[j].at.x, (double)g->text_config_array[j].at.y);
3106 + cairo_set_font_size(cr, g->text_config_array[j].fontsize);
3107 + cairo_set_source_rgba(cr, g->text_config_array[j].color.r, g->text_config_array[j].color.g,
3108 + g->text_config_array[j].color.b, g->text_config_array[j].color.a);
3109 + cairo_show_text(cr, g->text_values[j]);
3113 + for (j=0; j<g->bar_graph_params.num_of_y_items; j++) {
3114 + cairo_move_to(cr, (double)g->bar_graph_params.y_config_array[j].region.bottom_left.x,
3115 + (double)g->bar_graph_params.y_config_array[j].region.bottom_left.y);
3116 + c_y = (double)g->bar_graph_params.y_config_array[j].region.bottom_left.y -
3117 + (g->bar_graph_y_values[j] * (double)(g->bar_graph_params.y_config_array[j].region.bottom_left.y -
3118 + g->bar_graph_params.y_config_array[j].region.top_right.y));
3119 + cairo_line_to(cr, (double)g->bar_graph_params.y_config_array[j].region.bottom_left.x, c_y);
3120 + cairo_line_to(cr, (double)g->bar_graph_params.y_config_array[j].region.top_right.x, c_y);
3121 + cairo_line_to(cr, (double)g->bar_graph_params.y_config_array[j].region.top_right.x,
3122 + (double)g->bar_graph_params.y_config_array[j].region.bottom_left.y);
3123 + cairo_line_to(cr, (double)g->bar_graph_params.y_config_array[j].region.bottom_left.x,
3124 + (double)g->bar_graph_params.y_config_array[j].region.bottom_left.y);
3125 + cairo_close_path(cr);
3126 + cairo_set_source_rgba(cr, g->bar_graph_y_config_array[j].fill_color.r, g->bar_graph_y_config_array[j].fill_color.g,
3127 + g->bar_graph_y_config_array[j].fill_color.b, g->bar_graph_y_config_array[j].fill_color.a);
3128 + cairo_fill_preserve(cr);
3129 + cairo_set_source_rgba(cr, g->bar_graph_y_config_array[j].line_color.r, g->bar_graph_y_config_array[j].line_color.g,
3130 + g->bar_graph_y_config_array[j].line_color.b, g->bar_graph_y_config_array[j].line_color.a);
3133 + for (j=0; j<g->bar_graph_params.num_of_text_items; j++) {
3134 + cairo_move_to(cr, (double)g->bar_graph_text_config_array[j].at.x, (double)g->bar_graph_text_config_array[j].at.y);
3135 + cairo_set_font_size(cr, g->bar_graph_text_config_array[j].fontsize);
3136 + cairo_set_source_rgba(cr, g->bar_graph_text_config_array[j].color.r, g->bar_graph_text_config_array[j].color.g,
3137 + g->bar_graph_text_config_array[j].color.b, g->bar_graph_text_config_array[j].color.a);
3139 + //cairo_rotate(cr, 2*3.14*21/24);
3140 + cairo_show_text(cr, g->bar_graph_text_values[j]);
3141 + cairo_restore(cr);
3143 + pthread_mutex_unlock(&g->mtx);
3144 + cairo_destroy(cr);
3148 +resize_handler(struct widget *widget,
3149 + int32_t width, int32_t height, void *data)
3151 + struct graph *g = data;
3153 + /* Dont resize me */
3154 + widget_set_size(g->widget, g->width, g->height);
3158 +redraw_handler(struct widget *widget, void *data)
3160 + struct graph *g = data;
3161 + cairo_surface_t *surface;
3163 + surface = window_get_surface(g->window);
3164 + if (surface == NULL ||
3165 + cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
3166 + fprintf(stderr, "failed to create cairo egl surface\n");
3170 + draw_stuff(g, surface);
3171 + cairo_surface_destroy(surface);
3175 +button_handler(struct widget *widget,
3176 + struct input *input, uint32_t time,
3177 + uint32_t button, enum wl_pointer_button_state state, void *data)
3179 + struct graph *g = data;
3183 + if (state == WL_POINTER_BUTTON_STATE_PRESSED)
3184 + window_move(g->window, input,
3185 + display_get_serial(g->display));
3188 + if (state == WL_POINTER_BUTTON_STATE_PRESSED)
3189 + widget_schedule_redraw(widget);
3192 + if (state == WL_POINTER_BUTTON_STATE_PRESSED)
3193 + window_show_frame_menu(g->window, input, time);
3199 +touch_down_handler(struct widget *widget, struct input *input,
3200 + uint32_t serial, uint32_t time, int32_t id,
3201 + float x, float y, void *data)
3203 + struct graph *g = data;
3204 + window_move(g->window, input, display_get_serial(g->display));
3207 +static void task_run(struct task *task, uint32_t events)
3210 + struct graph *g = (struct graph *)(task->link.prev);
3211 + uint64_t time_diff;
3212 + int elems, tmp, incr, i;
3215 + eventfd_read(g->eventfd, &e);
3217 + pthread_mutex_lock(&g->mtx);
3218 + /* Process new data */
3219 + DBG("time_now: %llu, last_time: %llu\n", g->time_now, g->data->last_time);
3220 + if (g->time_now > g->data->last_time) {
3221 + time_diff = g->time_now - g->data->last_time;
3222 + y = (double)time_diff * g->x_scaling_factor;
3224 + DBG("incr: %d\n", incr);
3226 + if (g->data->last_index >= g->data->first_index) elems = g->data->last_index - g->data->first_index + 1;
3227 + else elems = g->data->dataset_size - g->data->first_index + g->data->last_index + 1;
3228 + /* Move first index to make room for new element */
3229 + while (g->data->dataset_size > 0 && (elems + incr) > g->data->dataset_size) {
3230 + tmp = g->data->dataset[g->data->first_index].next_index - g->data->first_index;
3231 + if (tmp < 0) tmp = g->data->dataset_size + tmp;
3232 + g->data->first_index = g->data->dataset[g->data->first_index].next_index;
3234 + g->data->num_elems--;
3236 + for (i=0; i<g->params.num_of_y_items; i++) {
3238 + y = g->time_graph_y_values[i] * (double)(g->params.draw_area.bottom_left.y-g->params.draw_area.top_right.y);
3239 + y = (double)g->params.draw_area.bottom_left.y - y;
3240 + g->data->dataset[g->data->last_index].y_values[i] = y;
3242 + g->data->dataset[g->data->last_index].next_index = g->data->last_index + incr;
3243 + if (g->data->dataset[g->data->last_index].next_index >= g->data->dataset_size)
3244 + g->data->dataset[g->data->last_index].next_index -= g->data->dataset_size;
3245 + g->data->num_elems++;
3246 + g->data->last_index = g->data->dataset[g->data->last_index].next_index;
3247 + g->data->last_time = g->time_now;
3249 + pthread_mutex_unlock(&g->mtx);
3251 + widget_schedule_redraw(g->widget);
3252 + DBG("event task ran...\n");
3255 +void *time_graph_create(int argc, char *argv[], struct time_graph_create_params *cp)
3258 + struct display *d;
3260 + struct timeval tv;
3262 + if (cp->num_of_y_items > MAX_ITEMS) return NULL;
3263 + if (cp->num_of_text_items > MAX_ITEMS) return NULL;
3265 + g = (struct graph*)malloc(sizeof(struct graph));
3267 + fprintf(stderr, "failed to allocate memory\n");
3272 + if (cp->num_of_y_items)
3273 + memcpy(&g->y_config_array[0], cp->y_config_array,
3274 + sizeof(struct _y_config) * cp->num_of_y_items);
3275 + if (cp->num_of_text_items)
3276 + memcpy(&g->text_config_array[0], cp->text_config_array,
3277 + sizeof(struct _text_config) * cp->num_of_text_items);
3278 + d = display_create(&argc, argv);
3280 + fprintf(stderr, "failed to create display: %m\n");
3284 + //g->bg_image = load_cairo_surface(cp->bg_image);
3285 + g->width = cp->width; //cairo_image_surface_get_width(g->bg_image);
3286 + g->height = cp->height; //cairo_image_surface_get_height(g->bg_image);
3287 + dataset_size = cp->draw_area.top_right.x - cp->draw_area.bottom_left.x;
3288 + g->data = (struct graph_data *)malloc(sizeof(struct graph_data) +
3289 + (dataset_size * sizeof(struct graph_dataset_point)));
3291 + fprintf(stderr, "failed to allocate memory\n");
3292 + display_destroy(g->display);
3293 + //cairo_surface_destroy(g->bg_image);
3297 + g->data->first_index = 0;
3298 + g->data->last_index = 0;
3299 + g->data->num_elems = 0;
3300 + g->data->dataset_size = dataset_size;
3301 + g->x_scaling_factor = (double)dataset_size / (double)cp->time_span;
3302 + g->window = window_create(d);
3303 + g->widget = window_add_widget(g->window, g);
3304 + window_set_title(g->window, cp->title);
3305 + widget_set_resize_handler(g->widget, resize_handler);
3306 + widget_set_redraw_handler(g->widget, redraw_handler);
3307 + widget_set_button_handler(g->widget, button_handler);
3308 + widget_set_default_cursor(g->widget, CURSOR_HAND1);
3309 + widget_set_touch_down_handler(g->widget, touch_down_handler);
3310 + window_schedule_resize(g->window, g->width, g->height);
3311 + g->eventfd = eventfd(0, 0);
3312 + g->task.run = task_run;
3313 + g->task.link.prev = (struct wl_list*)g;
3314 + g->task.link.next = NULL;
3315 + display_watch_fd(d, g->eventfd, EPOLLIN, &g->task);
3316 + pthread_mutex_init(&g->mtx, NULL);
3318 + if (0 != pthread_create(&g->thr, NULL, (void *(*)(void *))display_run, (void *)d)) {
3319 + fprintf(stderr, "pthread_create failed: %m\n");
3320 + widget_destroy(g->widget);
3321 + window_destroy(g->window);
3322 + display_destroy(g->display);
3323 + //cairo_surface_destroy(g->bg_image);
3325 + close(g->eventfd);
3329 + gettimeofday(&tv, NULL);
3330 + g->start_time_tv_sec = tv.tv_sec;
3331 + g->data->last_time = 0;
3335 +void move_graph(void *ctx, struct time_graph_create_params *cp)
3337 + struct graph *g = ctx;
3338 + window_set_title(g->window, cp->title);
3341 +void time_graph_plot(void *ctx, double *y_values, const char *text_values[])
3343 + struct timeval tv;
3344 + struct graph *g = ctx;
3346 + pthread_mutex_lock(&g->mtx);
3347 + gettimeofday(&tv, NULL);
3348 + g->time_now = ((tv.tv_sec - g->start_time_tv_sec) * 1000) + (tv.tv_usec / 1000);
3349 + memcpy(g->time_graph_y_values, y_values, g->params.num_of_y_items * sizeof(double));
3350 + for (i=0;i<g->params.num_of_text_items; i++) {
3351 + strncpy(g->text_values[i], text_values[i], MAX_TEXT_SIZE);
3352 + g->text_values[i][MAX_TEXT_SIZE-1] = '\0';
3354 + pthread_mutex_unlock(&g->mtx);
3355 + eventfd_write(g->eventfd, (eventfd_t)1);
3358 +void time_graph_destroy(void *ctx)
3360 + struct graph *g = (struct graph *)ctx;
3361 + display_exit(g->display);
3362 + eventfd_write(g->eventfd, (eventfd_t)1);
3363 + pthread_join(g->thr, NULL);
3364 + widget_destroy(g->widget);
3365 + window_destroy(g->window);
3366 + display_destroy(g->display);
3368 + close(g->eventfd);
3370 + global_graph=NULL;
3373 +void util_get_cpu_usage(double *cpu_usage)
3375 + static FILE *fp = NULL;
3378 + uint64_t u, n, s, i, w, x, y, z;
3379 + static uint64_t last_i = 0, last_total = 0;
3383 + if (!(fp = fopen("/proc/stat", "r")))
3384 + fprintf(stderr, "Failed /proc/stat open: %s", strerror(errno));
3390 + if (!fgets(buf, sizeof(buf), fp)) {
3391 + fprintf(stderr, "failed /proc/stat read\n");
3393 + sscanf(buf, "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu",
3403 + if (last_total == 0) {
3404 + last_total = u+n+s+i+w+x+y+z;
3408 + tot = u+n+s+i+w+x+y+z;
3409 + *cpu_usage = (1.0 - ((double)(i-last_i)/(double)(tot-last_total)));
3419 +void *bar_graph_create(int argc, char *argv[], struct bar_graph_create_params *cp)
3422 + struct display *d;
3423 + struct timeval tv;
3425 + if (cp->num_of_y_items > MAX_ITEMS) return NULL;
3426 + if (cp->num_of_text_items > MAX_ITEMS) return NULL;
3428 + if (global_graph == NULL) {
3429 + fprintf(stderr, "graph not initialized invoke time_graph_create first\n");
3433 + g->bar_graph_params = *cp;
3434 + if (cp->num_of_y_items)
3435 + memcpy(&g->bar_graph_y_config_array[0], cp->y_config_array,
3436 + sizeof(struct _bar_graph_y_config) * cp->num_of_y_items);
3437 + if (cp->num_of_text_items)
3438 + memcpy(&g->bar_graph_text_config_array[0], cp->text_config_array,
3439 + sizeof(struct _text_config) * cp->num_of_text_items);
3444 +void bar_graph_plot(void *ctx, double *y_values, const char *text_values[])
3446 + struct graph *g = ctx;
3448 + pthread_mutex_lock(&g->mtx);
3449 + memcpy(g->bar_graph_y_values, y_values, g->bar_graph_params.num_of_y_items * sizeof(double));
3450 + for (i=0;i<g->bar_graph_params.num_of_text_items; i++) {
3451 + strncpy(g->bar_graph_text_values[i], text_values[i], MAX_TEXT_SIZE);
3452 + g->bar_graph_text_values[i][MAX_TEXT_SIZE-1] = '\0';
3454 + pthread_mutex_unlock(&g->mtx);
3455 + //eventfd_write(g->eventfd, (eventfd_t)2);
3458 +void bar_graph_destroy(void *ctx)
3460 + printf("Nothing to be done for this call\n");
3464 diff --git a/clients/time_bar_graph.h b/clients/time_bar_graph.h
3465 new file mode 100644
3466 index 0000000..97ac05a
3468 +++ b/clients/time_bar_graph.h
3471 +#ifndef _BAR_GRAPH_H_
3472 +#define _BAR_GRAPH_H_
3474 +#include <stdint.h>
3477 + double r, g, b, a; // Values between 0 and 1
3480 +struct _coordinate {
3481 + uint32_t x, y; // Co-ordinates relative to top-left of the window
3485 + struct _coordinate bottom_left, top_right;
3489 + struct _rgba line_color; // Line color
3490 + struct _rgba fill_color; // Fill color, 0 alpha => no fill
3493 +struct _text_config {
3494 + struct _rgba color; // Color for drawing the text, RGBA
3495 + struct _coordinate at; // where to draw the text
3496 + int fontsize; // Font size
3499 +struct time_graph_create_params {
3501 + //const char *bg_image;
3504 + struct _rect draw_area;
3505 + uint32_t time_span; // Amount of time the graph has to span in milliseconds
3506 + uint32_t num_of_y_items;
3507 + struct _y_config *y_config_array;
3508 + uint32_t num_of_text_items;
3509 + struct _text_config *text_config_array;
3513 +struct _bar_graph_y_config {
3514 + struct _rect region; // Region for the bar graph
3515 + struct _rgba line_color; // Color for drawing the line, RGBA
3516 + struct _rgba fill_color; // Fill under the line with color RGBA, 0 => no fill
3519 +struct bar_graph_create_params {
3521 + //const char *bg_image;
3522 + uint32_t num_of_y_items;
3523 + struct _bar_graph_y_config *y_config_array;
3524 + uint32_t num_of_text_items;
3525 + struct _text_config *text_config_array;
3528 +/* Creates a time graph using create parameters */
3529 +void *bar_graph_create(int argc, char *argv[], struct bar_graph_create_params *cp);
3531 +void move_graph(void *ctx, struct time_graph_create_params *cp);
3533 +/* Plots a new set of y-values from the values in the array y_values.
3534 + The number of values must be equal to "num_of_y_items" from create params
3535 + y_values must be normalized between 0.0 to 1.0
3537 +void bar_graph_plot(void *ctx, double *y_values, const char *text_values[]);
3539 +/* Destroy the graph */
3540 +void bar_graph_destroy(void *ctx);
3543 +/* Creates a time graph using create parameters */
3544 +void *time_graph_create(int argc, char *argv[], struct time_graph_create_params *cp);
3547 + * Plots a new set of points from the values in the array y_values.
3548 + * The number of values in the array y_values must be equal to "num_of_y_items"
3549 + * from create params
3550 + * y_values must be normalized between 0.0 to 1.0
3552 + * The number of values in the array text_values must be equal to "num_of_text_items"
3553 + * from create params
3555 +void time_graph_plot(void *ctx, double *y_values, const char *text_values[]);
3557 +/* Destroy the graph */
3558 +void time_graph_destroy(void *ctx);
3560 +void util_get_cpu_usage(double *cpu_usage);
3562 +#endif /* _BAR_GRAPH_H_ */