Skip to content

Commit 97ecf24

Browse files
committed
Change-Id: Ib126c83423e61400bf369985815d7030b2e03c6e Signed-off-by: panacotta <[email protected]>
1 parent 1885c08 commit 97ecf24

File tree

2 files changed

+190
-35
lines changed

2 files changed

+190
-35
lines changed

papiplot/src/plot.c

Lines changed: 190 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
*/
77

88
#include "gnuplot_i.h"
9+
#include <dirent.h>
910

10-
/*typedef struct tot_event_per_actor {
11-
char *plot_file;
11+
typedef struct event_acum_ {
12+
int events_nb;
13+
unsigned long int *acum;
1214
char *event_name[];
13-
} action_s;*/
15+
} event_acum_;
1416

1517
int main(int argc, char **argv) {
1618

@@ -26,41 +28,204 @@ int main(int argc, char **argv) {
2628
char* path = malloc(strlen(argv[1]));
2729
strcpy(path, argv[1]);
2830

29-
plot(path);
31+
search_and_plot(path);
32+
//plot(path);
3033

3134
return 0;
3235
}
3336

34-
void plot(char *path) {
37+
void plot(char *path, char* actor_name) {
38+
int i;
39+
3540
gnuplot_ctrl * h ;
3641
h = gnuplot_init() ;
3742

38-
int n = 2; //number of events
43+
gnuplot_cmd(h,"list = ''");
44+
gnuplot_cmd(h,"index(w) = words(substr(list, 0, strstrt(list, w)-1))");
45+
gnuplot_cmd(h,"add_label(d) = (strstrt(list, d) == 0 ? list=list.' '.d : '')");
46+
47+
gnuplot_cmd(h, "set datafile separator \";\"");
48+
gnuplot_cmd(h, "set xtics rotate by -35");
49+
50+
int number_of_actions = 4; //TODO function that returns number of actions
51+
int number_of_events = get_events_nb(path);
52+
53+
gnuplot_cmd(h, "set term png size 1680,1050");
54+
gnuplot_cmd(h, "set output \"bar_labels.png\"");
55+
gnuplot_cmd(h, "set xlabel \"Actions\"");
56+
gnuplot_cmd(h, "set ylabel \"Number of occurrences\"");
3957

4058

41-
gnuplot_cmd(h, "reset");
42-
gnuplot_cmd(h, "dx=5.");
43-
gnuplot_cmd(h, "n=%d", n);
44-
gnuplot_cmd(h, "total_box_width_relative=0.75");
59+
gnuplot_cmd(h, "dx=0.7");
60+
gnuplot_cmd(h, "n=%d",number_of_events);
61+
gnuplot_cmd(h, "total_box_width_relative=0.3");
4562
gnuplot_cmd(h, "gap_width_relative=0.1");
4663
gnuplot_cmd(h, "d_width=(gap_width_relative+total_box_width_relative)*dx/2.");
47-
gnuplot_cmd(h, "reset");
64+
gnuplot_cmd(h, "set boxwidth total_box_width_relative/n relative");
65+
gnuplot_cmd(h, "set style fill transparent solid 0.5 noborder");
4866

49-
gnuplot_cmd(h,"list = ''");
50-
gnuplot_cmd(h,"index(w) = words(substr(list, 0, strstrt(list, w)-1))");
51-
gnuplot_cmd(h,"add_label(d) = (strstrt(list, d) == 0 ? list=list.' '.d : '')");
52-
gnuplot_cmd(h, "set datafile separator \";\"");
53-
gnuplot_cmd(h, "set xtics rotate");
54-
//gnuplot_cmd(h, "set logscale y");
55-
gnuplot_cmd(h, "plot \"%s\" "
56-
"every ::1 using (d='|'.strcol(2).'|', add_label(d),index(d)):3:xtic(2) smooth frequency w boxes lc rgb\"green\" title \"PAPI TOT INS\"",
57-
path);
67+
gnuplot_cmd(h, "set xrange [-1:%d]", number_of_actions);
68+
gnuplot_cmd(h, "set title \"Events in %s per action\"", actor_name);
69+
gnuplot_cmd(h, "set xtics out");
70+
gnuplot_cmd(h, "set xtics nomirror");
71+
gnuplot_cmd(h, "set xtics autofreq");
72+
gnuplot_cmd(h, "set xtics font \"Verdana,8\"");
73+
gnuplot_cmd(h, "set label rotate by 90");
74+
gnuplot_cmd(h, "set grid");
75+
76+
/*gnuplot_cmd(h, "set xtics(\\");
77+
for (i=0;i<(number_of_actions-1);i++)
78+
gnuplot_cmd(h,"\"\" %d,\\",i);
79+
gnuplot_cmd(h,"\"\" %d)",i);*/
80+
81+
82+
gnuplot_cmd(h, "plot \\");
83+
if(number_of_events==1){
84+
i = 0;
85+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(2).'|', add_label(d),index(d))+(d_width*%d)):%d:xtic(2) smooth frequency w boxes title columnhead,\\", path, i, i+3);
86+
//gnuplot_cmd(h, "\"%s\" using (d='|'.strcol(2).'|', add_label(d),index(d)):3:3 smooth frequency w labels rotate by 90 font \",5\" notitle", path);
87+
}
88+
else if (number_of_events==0){
89+
printf("nothing to plot\n");
90+
exit(0);
91+
}
92+
else{
93+
for(i=0;i<number_of_events;i++){
94+
if(i == 0){//first
95+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(2).'|', add_label(d),index(d))+(d_width*%d)):%d:xtic(2) smooth frequency w boxes title columnhead,\\", path, i, i+3);
96+
//gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(2).'|', add_label(d),index(d))+(d_width*%d)):%d:%d smooth frequency w labels rotate by 90 font \",5\" notitle,\\", path,i,i+3,i+3);
97+
}
98+
else if (i==(number_of_events-1)){//last
99+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(2).'|', add_label(d),index(d))+(d_width*%d)):%d smooth frequency w boxes title columnhead,\\", path, i, i+3);
100+
//gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(2).'|', add_label(d),index(d))+d_width*%d):%d:%d smooth frequency w labels rotate by 90 font \",5\" notitle", path,i,i+3,i+3);
101+
}
102+
else
103+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(2).'|', add_label(d)),index(d)+(d_width*%d)):%d smooth frequency w boxes title columnhead,\\", path, i, i+3);
104+
//gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(2).'|', add_label(d),index(d))+(d_width*%d)):%d:%d smooth frequency w labels rotate by 90 font \",5\" notitle,\\", path,i,i+3,i+3);
105+
}
106+
}
107+
108+
gnuplot_close(h);
109+
110+
111+
// gnuplot_cmd(h, "plot \\");
112+
113+
// gnuplot_cmd(h, "\"%s\" using (d='|'.strcol(2).'|', add_label(d),index(d)):3:xtic(2) smooth frequency w boxes title columnhead,\\", path);
114+
// gnuplot_cmd(h, "\"%s\" using (d='|'.strcol(2).'|', add_label(d),index(d)):3:3 smooth frequency w labels rotate by 90 font \",5\" notitle,\\", path);
115+
116+
// gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(2).'|', add_label(d),index(d))+d_width):4 smooth frequency w boxes title columnhead,\\", path);
117+
// gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(2).'|', add_label(d),index(d))+d_width):4:4 smooth frequency w labels rotate by 90 font \",5\" notitle,\\", path);
58118

119+
// gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(2).'|', add_label(d),index(d))+d_width*2):5 smooth frequency w boxes title columnhead,\\", path);
120+
// gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(2).'|', add_label(d),index(d))+d_width*2):5:5 smooth frequency w labels rotate by 90 font \",5\" notitle", path);
59121

60122

61-
/* plot "profit.dat" u 1:2 w boxes lc rgb"green" notitle,\
62-
"profit.dat" u ($1+d_width):3 w boxes lc rgb"red" notitle
63-
http://gnuplot-surprising.blogspot.com.es/2011/09/plot-histograms-using-boxes.html
64-
*/
65-
sleep(50000000);
123+
// gnuplot_close(h);
124+
// sleep(100);
66125
}
126+
127+
int get_events_nb(char *path) {
128+
char buf[1500];
129+
char *token;
130+
int nb = 0;
131+
FILE* file = fopen(path,"r");
132+
133+
fgets(buf,1500,file);
134+
135+
token = strtok(buf,";");
136+
137+
while(token !=NULL){
138+
nb++;
139+
token = strtok(NULL,";");
140+
}
141+
142+
fclose(file);
143+
return nb-3;//-3 because of first two columns (not events) and bc line ends with ';'
144+
}
145+
146+
const int is_papioutput(const char *filename) {
147+
if (strstr(filename,"papi_output") != NULL) return 1; //si el fichero no tiene extensión..
148+
else return 0;
149+
}
150+
151+
void search_and_plot(char *path) {
152+
153+
struct dirent *pDirent;
154+
DIR *pDir;
155+
int success = 0;
156+
pDir = opendir (path);
157+
if (pDir == NULL) {
158+
perror ("Cannot open directory\n");
159+
exit(1);
160+
}
161+
char * path_to_csv;
162+
163+
while ((pDirent = readdir(pDir)) != NULL) {
164+
//usleep(30000);
165+
if(is_papioutput(pDirent->d_name)) {
166+
path_to_csv = malloc(strlen(path)+strlen(pDirent->d_name)+2);
167+
strcpy(path_to_csv, path);
168+
strcat(path_to_csv,"/");
169+
strcat(path_to_csv,pDirent->d_name);
170+
printf("plot of %s\n", pDirent->d_name);
171+
//plot(path_to_csv, pDirent->d_name);
172+
process_data(path, path_to_csv, pDirent->d_name);
173+
break;//temp..
174+
}
175+
}
176+
printf("out of the loooop!\n");
177+
return;
178+
}
179+
180+
void process_data (char* path_todir, char* path_tofile, char* filename){
181+
char buf[1500];
182+
char *token;
183+
int nb = 0;
184+
char *saveptr;
185+
event_acum_* acum;
186+
FILE* ofile = fopen(path_tofile,"r");//original csv
187+
char* path_todatafile = malloc(strlen(path_todir)+strlen("/papidata.temp")+4);
188+
char* actor_name = &(*filename)+12;
189+
printf("actor name is %s\n", actor_name);
190+
strcpy(path_todatafile, path_todir);
191+
strcat(path_todatafile,"/");
192+
strcat(path_todatafile,"plotdata_");
193+
strcat(path_todatafile,actor_name);
194+
printf("creating %s\n", path_todatafile);
195+
FILE* datafile = fopen(path_todatafile,"w");
196+
197+
int columns = get_events_nb(path_tofile)+2;
198+
acum = malloc(sizeof(event_acum_)+sizeof(char*)*(columns-2));
199+
acum->events_nb = get_events_nb(path_tofile);
200+
acum->acum = malloc(sizeof(long int)*get_events_nb(path_tofile));
201+
int i;
202+
for(i = 0; i <acum->events_nb; i++){
203+
acum->acum[i]=0;
204+
}
205+
206+
fgets(buf,1500,ofile);//read first line
207+
token = strtok(buf,";");
208+
token = strtok(NULL,";");//skip action column
209+
for(i=0;i<acum->events_nb;i++){
210+
token = strtok(NULL,";");
211+
acum->event_name[i] = malloc(strlen(token)+1);
212+
strcpy(acum->event_name[i], token);
213+
printf("%s saved\n", acum->event_name[i]);
214+
}
215+
216+
//do{
217+
fgets(buf,1500,ofile);
218+
token = strtok(buf,";");
219+
token = strtok(NULL,";");//skip actor name
220+
token = strtok(NULL,";");//skip action name
221+
for(i=0;i<acum->events_nb;i++){
222+
acum->acum[i] += atol(strtok_r(token,"\"", &saveptr));
223+
printf("evento %s, se suma: %s, total = %lu\n", acum->event_name[i], token, acum->acum[i]);
224+
token = strtok(saveptr,";");
225+
}
226+
227+
228+
229+
//}while(buf != NULL);
230+
}
231+

papiplot/tablefilename

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)