Skip to content

Commit 6ed6cf3

Browse files
committed
Change-Id: I3442f10d03e806835731111833b6fdf6c592902b Signed-off-by: panacotta <[email protected]>
1 parent b3498ef commit 6ed6cf3

File tree

1 file changed

+73
-18
lines changed

1 file changed

+73
-18
lines changed

papiplot/src/plot.c

Lines changed: 73 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ typedef struct event_acum_for_actor {
2626
} event_acum_for_actor;
2727

2828
event_acum_for_actor* process_data (char* path_todir, char* path_tofile, char* filename, char* path_to_totals);
29+
int get_nb_of_actors_in_dir(char* path);
2930
int get_number(char *line);
3031
void search_and_plot(char *path);
3132
void struct_test(struct event_acum_for_actor *data);
@@ -52,49 +53,59 @@ int main(int argc, char **argv) {
5253
return 0;
5354
}
5455

55-
void plot(char *path, char* actor_name, int number_of_actions, int number_of_events) {
56-
int i;
57-
gnuplot_ctrl * h ;
58-
h = gnuplot_init() ;
56+
void configure_handle(gnuplot_ctrl * h, int number_of_events, int number_of_elements){
57+
5958

6059
gnuplot_cmd(h,"list = ''");
6160
gnuplot_cmd(h,"index(w) = words(substr(list, 0, strstrt(list, w)-1))");
6261
gnuplot_cmd(h,"add_label(d) = (strstrt(list, d) == 0 ? list=list.' '.d : '')");
6362

6463
gnuplot_cmd(h, "set datafile separator \";\"");
65-
//gnuplot_cmd(h, "set xtics rotate by -35");
64+
gnuplot_cmd(h, "set xtics rotate by -25");
6665
gnuplot_cmd(h, "set logscale y");
6766

6867
gnuplot_cmd(h, "set term png size 1680,1050");
6968

70-
gnuplot_cmd(h, "set output \"papiplot_%s.png\"",actor_name);
71-
gnuplot_cmd(h, "set xlabel \"Actions\"");
7269
gnuplot_cmd(h, "set ylabel \"Number of occurrences\"");
7370

7471

7572
gnuplot_cmd(h, "dx=0.7");
73+
7674
gnuplot_cmd(h, "n=%d",number_of_events);
7775
gnuplot_cmd(h, "total_box_width_relative=0.3");
7876
gnuplot_cmd(h, "gap_width_relative=0.1");
7977
gnuplot_cmd(h, "d_width=(gap_width_relative+total_box_width_relative)*dx/2.");
8078
gnuplot_cmd(h, "set boxwidth total_box_width_relative/n relative");
8179
gnuplot_cmd(h, "set style fill transparent solid 0.5 noborder");
8280

81+
gnuplot_cmd(h, "set xrange [-1:%d]", number_of_elements);
8382

84-
gnuplot_cmd(h, "set xrange [-1:%d]", number_of_actions);
85-
gnuplot_cmd(h, "set title \"Events in %s per action\"", actor_name);
8683
gnuplot_cmd(h, "set xtics out");
8784
gnuplot_cmd(h, "set xtics nomirror");
8885
gnuplot_cmd(h, "set xtics autofreq");
8986
gnuplot_cmd(h, "set xtics font \"Verdana,8\"");
87+
gnuplot_cmd(h, "set tic scale 0");
9088
gnuplot_cmd(h, "set grid");
89+
gnuplot_cmd(h, "set label at character 1,1 \"Generated with Papify\"");
90+
91+
}
92+
93+
void plot_overall(char* output_path, char *path, int number_of_actors, int number_of_events) {
94+
int i;
95+
gnuplot_ctrl * h ;
96+
h = gnuplot_init() ;
9197

98+
int label_rot = 20;
99+
configure_handle(h, number_of_events, number_of_actors);
100+
gnuplot_cmd(h, "set output \"%s/papiplot_overall_.png\"", output_path);
101+
gnuplot_cmd(h, "set title \"Events per actor\"");
102+
gnuplot_cmd(h, "set xlabel \"Actors\"");
92103

93104
gnuplot_cmd(h, "plot \\");
94105
if(number_of_events==1){
95106
i = 0;
96107
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:xtic(1) w boxes title columnhead,\\", path, i, i+2);
97-
gnuplot_cmd(h, "\"%s\" using (d='|'.strcol(1).'|', add_label(d),index(d)):2:2 w labels rotate by 90 font \",5\" notitle", path);
108+
gnuplot_cmd(h, "\"%s\" using (d='|'.strcol(1).'|', add_label(d),index(d)):2:2 w labels rotate by %d font \",5\" notitle", path, label_rot);
98109
}
99110
else if (number_of_events==0){
100111
printf("nothing to plot\n");
@@ -104,22 +115,65 @@ void plot(char *path, char* actor_name, int number_of_actions, int number_of_eve
104115
for(i=0;i<number_of_events;i++){
105116
if(i == 0){//first
106117
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:xtic(1) w boxes title columnhead,\\", path, i, i+2);
107-
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:%d w labels rotate by 90 font \",5\" notitle,\\", path, i, i+2, i+2);
118+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:%d w labels rotate by %d font \",5\" notitle,\\", path, i, i+2, i+2, label_rot);
108119
}
109120
else if (i==(number_of_events-1)){//last
110121
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d w boxes title columnhead,\\", path, i, i+2);
111-
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:%d w labels rotate by 90 font \",5\" notitle", path, i, i+2, i+2);
122+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:%d w labels rotate by %d font \",5\" notitle", path, i, i+2, i+2, label_rot);
112123
}
113124
else{
114125
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d w boxes title columnhead,\\", path, i, i+2);
115-
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:%d w labels rotate by 90 font \",5\" notitle,\\", path, i, i+2, i+2);
126+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:%d w labels rotate by %d font \",5\" notitle,\\", path, i, i+2, i+2, label_rot);
116127
}
117128
}
118129
}
119130
//sleep(6);
120131
gnuplot_close(h);
121132
}
122133

134+
void plot(char* output_path, char *path, char* actor_name, int number_of_actions, int number_of_events) {
135+
int i;
136+
gnuplot_ctrl * h ;
137+
h = gnuplot_init() ;
138+
139+
int label_rot = 20;
140+
configure_handle(h, number_of_events, number_of_actions);
141+
gnuplot_cmd(h, "set output \"%s/papiplot_%s.png\"", output_path, actor_name);
142+
gnuplot_cmd(h, "set title \"Events in actor \\\"%s\\\" per action\"", actor_name);
143+
gnuplot_cmd(h, "set xlabel \"Actions\"");
144+
145+
146+
147+
gnuplot_cmd(h, "plot \\");
148+
if(number_of_events==1){
149+
i = 0;
150+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:xtic(1) w boxes title columnhead,\\", path, i, i+2);
151+
gnuplot_cmd(h, "\"%s\" using (d='|'.strcol(1).'|', add_label(d),index(d)):2:2 w labels rotate by %d font \",5\" notitle", path, label_rot);
152+
}
153+
else if (number_of_events==0){
154+
printf("nothing to plot\n");
155+
exit(0);
156+
}
157+
else{
158+
for(i=0;i<number_of_events;i++){
159+
if(i == 0){//first
160+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:xtic(1) w boxes title columnhead,\\", path, i, i+2);
161+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:%d w labels rotate by %d font \",5\" notitle,\\", path, i, i+2, i+2, label_rot);
162+
}
163+
else if (i==(number_of_events-1)){//last
164+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d w boxes title columnhead,\\", path, i, i+2);
165+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:%d w labels rotate by %d font \",5\" notitle", path, i, i+2, i+2, label_rot);
166+
}
167+
else{
168+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d w boxes title columnhead,\\", path, i, i+2);
169+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:%d w labels rotate by %d font \",5\" notitle,\\", path, i, i+2, i+2, label_rot);
170+
}
171+
}
172+
}
173+
174+
gnuplot_close(h);
175+
}
176+
123177
int get_events_nb(char *path) {
124178
char buf[1500];
125179
char *token;
@@ -149,10 +203,10 @@ void search_and_plot(char *path) {
149203
char * path_to_totals = malloc(strlen(path)+strlen("/plotdata_papi_totals.csv")+2);
150204
strcpy(path_to_totals, path);
151205
strcat(path_to_totals,"/plotdata_papi_totals.csv");
152-
FILE* datafile = fopen(path_to_totals,"w");
206+
FILE* datafile = fopen(path_to_totals,"w");//reset
153207
fclose(datafile);
154208

155-
//int actors_nb = get_nb_of_actors_in_dir(path);
209+
int actors_nb = get_nb_of_actors_in_dir(path);
156210
event_acum_for_actor* data;
157211

158212
struct dirent *pDirent;
@@ -171,14 +225,15 @@ void search_and_plot(char *path) {
171225
strcpy(path_to_csv, path);
172226
strcat(path_to_csv,"/");
173227
strcat(path_to_csv,pDirent->d_name);
174-
//printf("plot of %s\n", pDirent->d_name);
175228
data = process_data(path, path_to_csv, pDirent->d_name, path_to_totals);
176-
plot(data->proc_file_path, data->actor_name, data->actions_nb, data->actions[0]->events_nb);
229+
plot(path, data->proc_file_path, data->actor_name, data->actions_nb, data->actions[0]->events_nb);
177230
//todo generate html file with data
178-
//remove temp files
231+
remove(data->proc_file_path);
179232
free(data);
180233
}
181234
}
235+
plot_overall(path, path_to_totals, actors_nb, get_events_nb(path_to_totals)+1);
236+
remove(path_to_totals);
182237

183238
closedir (pDir);
184239
return;

0 commit comments

Comments
 (0)