Skip to content

Commit 5ea9bac

Browse files
committed
Initial release commit
Change-Id: I472c0d95737070858af94ddebe40620343d0f6b8 Signed-off-by: panacotta <[email protected]>
1 parent 014085b commit 5ea9bac

File tree

2 files changed

+136
-63
lines changed

2 files changed

+136
-63
lines changed

papiplot/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/Debug/
2+
/Release/

papiplot/src/plot.c

Lines changed: 135 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,95 @@ void search_and_plot(char *path);
3232
void struct_test(struct event_acum_for_actor *data);
3333
int get_events_nb(char *path);
3434
int get_actions_nb_in_file(char* path_tofile);
35+
int NOLABELS;
36+
unsigned int res_x;
37+
unsigned int res_y;
38+
int tics_font_size;
39+
int labels_font_size;
40+
41+
void printhelp(char** argv){
42+
printf("\tPapiPlot options:\n"
43+
"\t-p [path]"
44+
"\t Set path to the papi-output folder generated with Papify. If not specified, current directory will be used.\n\n"
45+
"\t-x [res_x]"
46+
"\t Change horizontal resolution. If not specified, default is 1680.\n\n"
47+
"\t-y [res_y]"
48+
"\t Change vertical resolution. If not specified, default is 1050.\n\n"
49+
"\t-t [font size]"
50+
"\t Change tics font size. If not specified, default is 8.\n\n"
51+
"\t-l [font size]"
52+
"\t Change labels font size. If not specified, default is 8.\n\n"
53+
"\t-n \t \tNo labels will be printed\n\n"
54+
"\t-h \t \tPrint help\n\n"
55+
"\tPapiPlot requires GNUPLOT. If not installed, assuming you are on Ubuntu, run:\n"
56+
"\tsudo apt-get install gnuplot\n\n");
57+
}
58+
3559

3660
int main(int argc, char **argv) {
61+
int c, len;
62+
res_x = 1680;
63+
res_y = 1050;
64+
tics_font_size = 8;
65+
labels_font_size = 8;
66+
char* path = NULL;
67+
68+
while ((c = getopt (argc, argv, "l:t:nhp:x:y:")) != -1) {
69+
switch (c)
70+
{
71+
case 'h':
72+
printhelp(argv);
73+
exit(0);
74+
case 'x':
75+
res_x = atoi(optarg);
76+
break;
77+
case 'y':
78+
res_y = atoi(optarg);
79+
break;
80+
case 'l':
81+
labels_font_size = atoi(optarg);
82+
break;
83+
case 't':
84+
tics_font_size = atoi(optarg);
85+
break;
86+
case 'p':
87+
path = optarg;
88+
break;
89+
case 'n':
90+
NOLABELS = 1;
91+
break;
92+
case '?':
93+
if (isprint (optopt)) {
94+
fprintf (stderr, "Unknown option '-%c'.\n", optopt);
95+
}
96+
else {
97+
fprintf (stderr,
98+
"Unknown option character `\\x%x'.\n",
99+
optopt);
100+
}
101+
return 1;
102+
default:
103+
printhelp(argv);
104+
abort();
105+
}
106+
}
37107

38-
if (argc == 1){
39-
printf("PapiPlot usage:\n"
40-
"%s {path}\n"
41-
"being {path} the path to your papify-output generated folder\n"
42-
"\nIf not installed, you need to install gnuplot. In Ubuntu run:\n"
43-
"sudo apt-get install gnuplot\n",
44-
argv[0]);
45-
exit(0);
108+
if(path==NULL){
109+
char cwd[3000];
110+
getcwd(cwd, sizeof(cwd));
111+
len = strlen(cwd)+2;
112+
path = malloc(len);
113+
strcpy(path, cwd);
114+
path[len-2]='/';
115+
path[len-1]='\0';
46116
}
47-
int len = strlen(argv[1])+2;
48-
char* path = malloc(len);
49-
strcpy(path, argv[1]);
50-
path[len-2]='/';
51-
path[len-1]='\0';
52117

53118
search_and_plot(path);
54119

55-
free(path);
56-
57120
return 0;
58121
}
59122

60-
void configure_handle(gnuplot_ctrl * h, int number_of_events, int number_of_elements){
123+
void configure_handle(gnuplot_ctrl * h, int number_of_events, int number_of_elements, unsigned int res_x, unsigned int res_y){
61124

62125

63126
gnuplot_cmd(h,"list = ''");
@@ -68,7 +131,7 @@ void configure_handle(gnuplot_ctrl * h, int number_of_events, int number_of_ele
68131
gnuplot_cmd(h, "set xtics rotate by -25");
69132
gnuplot_cmd(h, "set logscale y");
70133

71-
gnuplot_cmd(h, "set term png size 1680,1050");
134+
gnuplot_cmd(h, "set term png size %d,%d", res_x, res_y);
72135

73136
gnuplot_cmd(h, "set ylabel \"Number of occurrences\"");
74137

@@ -87,7 +150,7 @@ void configure_handle(gnuplot_ctrl * h, int number_of_events, int number_of_ele
87150
gnuplot_cmd(h, "set xtics out");
88151
gnuplot_cmd(h, "set xtics nomirror");
89152
gnuplot_cmd(h, "set xtics autofreq");
90-
gnuplot_cmd(h, "set xtics font \"Verdana,8\"");
153+
gnuplot_cmd(h, "set xtics font \"Verdana,%d\"", tics_font_size);
91154
gnuplot_cmd(h, "set tic scale 0");
92155
gnuplot_cmd(h, "set grid");
93156
gnuplot_cmd(h, "set label at character 1,1 \"Generated with Papify\"");
@@ -100,9 +163,9 @@ void plot_overall(char* output_path, char *path, int number_of_actors, int numbe
100163
gnuplot_ctrl * h ;
101164
h = gnuplot_init() ;
102165

103-
int label_rot = 20;
104-
configure_handle(h, number_of_events, number_of_actors);
105-
gnuplot_cmd(h, "set output \"/%s/papiplot_overall_.png\"", output_path);
166+
//int label_rot = 20;
167+
configure_handle(h, number_of_events, number_of_actors, res_x, res_y);
168+
gnuplot_cmd(h, "set output \"%s/papiplot_overall_.png\"", output_path);
106169
gnuplot_cmd(h, "set title \"Events per actor\"");
107170
gnuplot_cmd(h, "set xlabel \"Actors\"");
108171

@@ -132,24 +195,29 @@ void plot_overall(char* output_path, char *path, int number_of_actors, int numbe
132195
}
133196
//draw numbers:
134197
//gnuplot_cmd(h, "plot \\");
135-
if(number_of_events==1){
136-
i = 0;
137-
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:(gprintf(\"%%.2se%%S\", $%d)) w labels rotate by 20 font \",5\" notitle", path, i, i+2, i+2);
138-
}
139-
else if (number_of_events==0){
140-
printf("nothing to plot\n");
141-
exit(0);
142-
}
143-
else{
144-
for(i=0;i<number_of_events;i++){
145-
if(i == 0){//first
146-
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:(gprintf(\"%%.2se%%S\", $%d)) w labels rotate by 20 font \",5\" notitle,\\", path, i, i+2, i+2);
198+
if (NOLABELS)
199+
gnuplot_cmd(h, "0 notitle"); //end plot here
200+
else
201+
{
202+
if(number_of_events==1){
203+
i = 0;
204+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:(gprintf(\"%%.2se%%S\", $%d)) w labels rotate by 20 font \",5\" notitle", path, i, i+2, i+2);
205+
}
206+
else if (number_of_events==0){
207+
printf("nothing to plot\n");
208+
exit(0);
209+
}
210+
else{
211+
for(i=0;i<number_of_events;i++){
212+
if(i == 0){//first
213+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:(gprintf(\"%%.2se%%S\", $%d)) w labels rotate by 20 font \"Verdana,%d\" notitle,\\", path, i, i+2, i+2, labels_font_size);
214+
}
215+
else if (i==(number_of_events-1)){//last
216+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:(gprintf(\"%%.2se%%S\", $%d)) w labels rotate by 20 font \"Verdana,%d\" notitle", path, i, i+2, i+2, labels_font_size);
217+
}
218+
else{
219+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:(gprintf(\"%%.2se%%S\", $%d)) w labels rotate by 20 font \"Verdana,%d\" notitle,\\", path, i, i+2, i+2, labels_font_size);
147220
}
148-
else if (i==(number_of_events-1)){//last
149-
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:(gprintf(\"%%.2se%%S\", $%d)) w labels rotate by 20 font \",5\" notitle", path, i, i+2, i+2);
150-
}
151-
else{
152-
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:(gprintf(\"%%.2se%%S\", $%d)) w labels rotate by 20 font \",5\" notitle,\\", path, i, i+2, i+2);
153221
}
154222
}
155223
}
@@ -161,8 +229,8 @@ void plot(char* output_path, char *path, char* actor_name, int number_of_actions
161229
gnuplot_ctrl * h ;
162230
h = gnuplot_init() ;
163231

164-
int label_rot = 20;
165-
configure_handle(h, number_of_events, number_of_actions);
232+
//int label_rot = 20;
233+
configure_handle(h, number_of_events, number_of_actions, res_x, res_y);
166234
gnuplot_cmd(h, "set output \"/%s/papiplot_%s.png\"", output_path, actor_name);
167235
gnuplot_cmd(h, "set title \"Events in actor \\\"%s\\\" per action\"", actor_name);
168236
gnuplot_cmd(h, "set xlabel \"Actions\"");
@@ -195,24 +263,29 @@ void plot(char* output_path, char *path, char* actor_name, int number_of_actions
195263
}
196264
//draw numbers:
197265
//gnuplot_cmd(h, "plot \\");
198-
if(number_of_events==1){
199-
i = 0;
200-
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:(gprintf(\"%%.2se%%S\", $%d)) w labels rotate by 20 font \",5\" notitle", path, i, i+2, i+2);
201-
}
202-
else if (number_of_events==0){
203-
printf("nothing to plot\n");
204-
exit(0);
205-
}
206-
else{
207-
for(i=0;i<number_of_events;i++){
208-
if(i == 0){//first
209-
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:(gprintf(\"%%.2se%%S\", $%d)) w labels rotate by 20 font \",5\" notitle,\\", path, i, i+2, i+2);
266+
if (NOLABELS)
267+
gnuplot_cmd(h, "0 notitle"); //end plot here
268+
else
269+
{
270+
if(number_of_events==1){
271+
i = 0;
272+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:(gprintf(\"%%.2se%%S\", $%d)) w labels rotate by 20 font \",5\" notitle", path, i, i+2, i+2);
273+
}
274+
else if (number_of_events==0){
275+
printf("nothing to plot\n");
276+
exit(0);
277+
}
278+
else{
279+
for(i=0;i<number_of_events;i++){
280+
if(i == 0){//first
281+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:(gprintf(\"%%.2se%%S\", $%d)) w labels rotate by 20 font \"Verdana,%d\" notitle,\\", path, i, i+2, i+2, labels_font_size);
282+
}
283+
else if (i==(number_of_events-1)){//last
284+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:(gprintf(\"%%.2se%%S\", $%d)) w labels rotate by 20 font \"Verdana,%d\" notitle", path, i, i+2, i+2, labels_font_size);
285+
}
286+
else{
287+
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:(gprintf(\"%%.2se%%S\", $%d)) w labels rotate by 20 font \"Verdana,%d\" notitle,\\", path, i, i+2, i+2, labels_font_size);
210288
}
211-
else if (i==(number_of_events-1)){//last
212-
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:(gprintf(\"%%.2se%%S\", $%d)) w labels rotate by 20 font \",5\" notitle", path, i, i+2, i+2);
213-
}
214-
else{
215-
gnuplot_cmd(h, "\"%s\" using ((d='|'.strcol(1).'|', add_label(d),index(d))+(d_width*%d)):%d:(gprintf(\"%%.2se%%S\", $%d)) w labels rotate by 20 font \",5\" notitle,\\", path, i, i+2, i+2);
216289
}
217290
}
218291
}
@@ -290,19 +363,18 @@ void html_actor(FILE* htmlfile, event_acum_for_actor* data){
290363

291364
void search_and_plot(char *path) {
292365

293-
char * path_to_totals = malloc(strlen(path)+strlen("/plotdata_papi_totals.csv")+2);
366+
char * path_to_totals = malloc(strlen(path)+strlen("plotdata_papi_totals.csv")+2);
294367
strcpy(path_to_totals, path);
295-
strcat(path_to_totals,"/plotdata_papi_totals.csv");
368+
strcat(path_to_totals,"plotdata_papi_totals.csv");
369+
296370
FILE* datafile = fopen(path_to_totals,"w");//reset
297371
fclose(datafile);
298372

299-
char * html = malloc(strlen(path)+strlen("/papiplot.html")+2);
373+
char * html = malloc(strlen(path)+strlen("papiplot.html")+2);
300374
strcpy(html, path);
301-
strcat(html,"/papiplot.html");
375+
strcat(html,"papiplot.html");
302376
FILE* htmlfile = fopen(html,"w");
303377
html_init(htmlfile);
304-
305-
306378
int actors_nb = get_nb_of_actors_in_dir(path);
307379
event_acum_for_actor* data;
308380

0 commit comments

Comments
 (0)