Skip to content

Commit b7876e5

Browse files
committed
Change-Id: Id9022fbeed5f642cd49818447cf6136b7f0e863d Signed-off-by: panacotta <[email protected]>
1 parent dd1457a commit b7876e5

File tree

1 file changed

+153
-31
lines changed

1 file changed

+153
-31
lines changed

papiplot/src/plot.c

Lines changed: 153 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <dirent.h>
1010
typedef struct event_acumulator {
1111
char* event_name;
12-
unsigned long int count;
12+
unsigned long long count;
1313
}event_acumulator;
1414

1515
typedef struct event_acum_for_action {
@@ -44,11 +44,15 @@ int main(int argc, char **argv) {
4444
argv[0]);
4545
exit(0);
4646
}
47-
char* path = malloc(strlen(argv[1]));
47+
int len = strlen(argv[1])+2;
48+
char* path = malloc(len);
4849
strcpy(path, argv[1]);
50+
path[len-2]='/';
51+
path[len-1]='\0';
4952

5053
search_and_plot(path);
51-
//plot(path);
54+
55+
free(path);
5256

5357
return 0;
5458
}
@@ -87,6 +91,7 @@ void configure_handle(gnuplot_ctrl * h, int number_of_events, int number_of_ele
8791
gnuplot_cmd(h, "set tic scale 0");
8892
gnuplot_cmd(h, "set grid");
8993
gnuplot_cmd(h, "set label at character 1,1 \"Generated with Papify\"");
94+
gnuplot_cmd(h, "set format y \"%%.0se%%S\"");
9095

9196
}
9297

@@ -97,15 +102,16 @@ void plot_overall(char* output_path, char *path, int number_of_actors, int numbe
97102

98103
int label_rot = 20;
99104
configure_handle(h, number_of_events, number_of_actors);
100-
gnuplot_cmd(h, "set output \"%s/papiplot_overall_.png\"", output_path);
105+
gnuplot_cmd(h, "set output \"/%s/papiplot_overall_.png\"", output_path);
101106
gnuplot_cmd(h, "set title \"Events per actor\"");
102107
gnuplot_cmd(h, "set xlabel \"Actors\"");
103108

109+
110+
//draw lines:
104111
gnuplot_cmd(h, "plot \\");
105112
if(number_of_events==1){
106113
i = 0;
107114
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);
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);
109115
}
110116
else if (number_of_events==0){
111117
printf("nothing to plot\n");
@@ -115,19 +121,38 @@ void plot_overall(char* output_path, char *path, int number_of_actors, int numbe
115121
for(i=0;i<number_of_events;i++){
116122
if(i == 0){//first
117123
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);
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);
119124
}
120125
else if (i==(number_of_events-1)){//last
121126
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);
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);
123127
}
124128
else{
125129
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);
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);
127130
}
128131
}
129132
}
130-
//sleep(6);
133+
//draw numbers:
134+
//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);
147+
}
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);
153+
}
154+
}
155+
}
131156
gnuplot_close(h);
132157
}
133158

@@ -138,17 +163,17 @@ void plot(char* output_path, char *path, char* actor_name, int number_of_actions
138163

139164
int label_rot = 20;
140165
configure_handle(h, number_of_events, number_of_actions);
141-
gnuplot_cmd(h, "set output \"%s/papiplot_%s.png\"", output_path, actor_name);
166+
gnuplot_cmd(h, "set output \"/%s/papiplot_%s.png\"", output_path, actor_name);
142167
gnuplot_cmd(h, "set title \"Events in actor \\\"%s\\\" per action\"", actor_name);
143168
gnuplot_cmd(h, "set xlabel \"Actions\"");
144169

145170

146171

172+
//draw lines:
147173
gnuplot_cmd(h, "plot \\");
148174
if(number_of_events==1){
149175
i = 0;
150176
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);
152177
}
153178
else if (number_of_events==0){
154179
printf("nothing to plot\n");
@@ -158,15 +183,36 @@ void plot(char* output_path, char *path, char* actor_name, int number_of_actions
158183
for(i=0;i<number_of_events;i++){
159184
if(i == 0){//first
160185
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);
162186
}
163187
else if (i==(number_of_events-1)){//last
164188
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);
189+
//gnuplot_cmd(h, "0 notitle"); //end plot here
166190
}
167191
else{
168192
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);
193+
}
194+
}
195+
}
196+
//draw numbers:
197+
//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);
210+
}
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);
170216
}
171217
}
172218
}
@@ -190,14 +236,58 @@ int get_events_nb(char *path) {
190236
}
191237

192238
fclose(file);
193-
return nb-3;//-3 because of first two columns (not events) and bc line ends with ';'
239+
return nb-3;//-3 because of the first two columns (not events) and bc line ends with ';'
194240
}
195241

196242
const int is_papioutput(const char *filename) {
197243
if (strstr(filename,"papi_output") != NULL) return 1; //si el fichero no tiene extensión..
198244
else return 0;
199245
}
200246

247+
void html_init(FILE* htmlfile){
248+
fprintf(htmlfile, "<html><head><meta content=\"text/html; charset=ISO-8859-1\" http-equiv=\"content-type\"><title></title></head>"
249+
"<body><h1>Papify stats processed with PapiPlot</h1><hr style=\"width: 100%; height: 2px;\">");
250+
}
251+
void html_close(FILE* htmlfile){
252+
fprintf(htmlfile, "<h2>Overall: Events per actor</h2><img alt=\"\""
253+
"src=\"papiplot_overall_.png\">"
254+
"</body></html>");
255+
}
256+
257+
void html_actor(FILE* htmlfile, event_acum_for_actor* data){
258+
fprintf(htmlfile,"<table style=\"text-align: left; width: 100%;\" border=\"1\" cellpadding=\"2\""
259+
"cellspacing=\"2\">\n");
260+
261+
fprintf(htmlfile,"<table border=\"1\">"
262+
"<td>Action<br></td>");
263+
264+
265+
int i, j;
266+
fprintf(htmlfile, "<h2>Stats for actor \"%s\"</h2>\n",data->actor_name);
267+
268+
fprintf(htmlfile, "<img alt=\"\""
269+
"src=\"papiplot_%s.png\">\n",data->actor_name);
270+
271+
272+
for(i=0; i<data->actions[0]->events_nb;i++){
273+
fprintf(htmlfile,"<td>%s<br></td>\n", data->actions[0]->acumulator[i]->event_name);
274+
}
275+
fprintf(htmlfile,"</tr>\n");
276+
277+
278+
for(i=0; i<data->actions_nb;i++){
279+
fprintf(htmlfile,"<tr>\n");
280+
fprintf(htmlfile,"<td>%s<br></td>\n", data->actions[i]->action_name);
281+
for(j=0; j<data->actions[i]->events_nb;j++){
282+
fprintf(htmlfile,"<td>%llu<br></td>\n", data->actions[i]->acumulator[j]->count);
283+
}
284+
fprintf(htmlfile,"</tr>\n");
285+
}
286+
fprintf(htmlfile,"</table>\n");
287+
fprintf(htmlfile,"<hr style=\"width: 100%; height: 2px;\">\n");
288+
fprintf(htmlfile,"<br>\n");
289+
}
290+
201291
void search_and_plot(char *path) {
202292

203293
char * path_to_totals = malloc(strlen(path)+strlen("/plotdata_papi_totals.csv")+2);
@@ -206,6 +296,13 @@ void search_and_plot(char *path) {
206296
FILE* datafile = fopen(path_to_totals,"w");//reset
207297
fclose(datafile);
208298

299+
char * html = malloc(strlen(path)+strlen("/papiplot.html")+2);
300+
strcpy(html, path);
301+
strcat(html,"/papiplot.html");
302+
FILE* htmlfile = fopen(html,"w");
303+
html_init(htmlfile);
304+
305+
209306
int actors_nb = get_nb_of_actors_in_dir(path);
210307
event_acum_for_actor* data;
211308

@@ -221,20 +318,24 @@ void search_and_plot(char *path) {
221318

222319
while ((pDirent = readdir(pDir)) != NULL) {
223320
if(is_papioutput(pDirent->d_name)) {
321+
printf("going for %s\n", pDirent->d_name);
224322
path_to_csv = malloc(strlen(path)+strlen(pDirent->d_name)+2);
225323
strcpy(path_to_csv, path);
226324
strcat(path_to_csv,"/");
227325
strcat(path_to_csv,pDirent->d_name);
228326
data = process_data(path, path_to_csv, pDirent->d_name, path_to_totals);
229327
plot(path, data->proc_file_path, data->actor_name, data->actions_nb, data->actions[0]->events_nb);
230-
//todo generate html file with data
231-
remove(data->proc_file_path);
328+
html_actor(htmlfile, data);
329+
//remove(data->proc_file_path);
232330
free(data);
233331
}
234332
}
235333
plot_overall(path, path_to_totals, actors_nb, get_events_nb(path_to_totals)+1);
236-
remove(path_to_totals);
237334

335+
html_close(htmlfile);
336+
//remove(path_to_totals);
337+
338+
fclose(htmlfile);
238339
closedir (pDir);
239340
return;
240341
}
@@ -258,15 +359,16 @@ event_acum_for_actor* process_data (char* path_todir, char* path_tofile, char* f
258359
//get_actions_nb_in_file(path_tofile);
259360
int actions_nb=get_actions_nb_in_file(path_tofile);
260361

261-
actor = malloc(sizeof(event_acum_for_actor)+sizeof(event_acum_for_action*)*(actions_nb));
362+
actor = malloc(sizeof(event_acum_for_actor)+sizeof(event_acum_for_action*)*(actions_nb*3));
262363
actor->actor_name = malloc(strlen(actor_name));
263364
strcpy(actor->actor_name,actor_name);
264365
actor->proc_file_path = path_todatafile;
265366
actor->actions_nb = actions_nb;
266367
int i, j;
267368

268-
for(i=0;i<actions_nb;i++){
269-
actor->actions[i] = malloc(sizeof(event_acum_for_action)+sizeof(event_acumulator)*events_nb);
369+
printf("has %d actions\n", actions_nb);
370+
for(i=0;i<actions_nb*3;i++){
371+
actor->actions[i] = malloc(sizeof(event_acum_for_action)*2+sizeof(event_acumulator)*events_nb*3);
270372
actor->actions[i]->events_nb = events_nb;
271373
//actor->actions[i]->action_name
272374
for(j=0;j<events_nb;j++){
@@ -275,12 +377,12 @@ event_acum_for_actor* process_data (char* path_todir, char* path_tofile, char* f
275377
}
276378
}
277379

380+
278381
for(j = 0; j <actor->actions_nb; j++)
279382
for(i = 0; i <actor->actions[j]->events_nb; i++){
280383
actor->actions[j]->acumulator[i]->count = 0;
281384
}
282385

283-
284386
FILE* ofile = fopen(path_tofile, "r");
285387
fgets(buf,1500,ofile);//read first line
286388
token = strtok(buf,";");
@@ -296,6 +398,7 @@ event_acum_for_actor* process_data (char* path_todir, char* path_tofile, char* f
296398
}
297399
}
298400

401+
299402
int found = -1;
300403
int found_actions = 0;
301404
int current;
@@ -306,28 +409,46 @@ event_acum_for_actor* process_data (char* path_todir, char* path_tofile, char* f
306409
totals[i]=0;
307410
}
308411

412+
309413
//acumuating structures
414+
int result; //borrar
415+
int temp = 0; //borrar
310416
while(fgets(buf,1500,ofile)!=NULL){
311417
token = strtok(buf,";");
312418
token = strtok(NULL,";");//read action name
419+
printf("%d\n", ++temp);
313420

314421
for(i=0; i<actor->actions_nb; i++){
315-
//printf("comparing %s with %s\n", actor->actions[i]->action_name, token);
316-
if(actor->actions[i]->action_name!=NULL && strcmp(actor->actions[i]->action_name,token)==0){
317-
//printf("action %s already exist\n", actor->actions[i]->action_name);
318-
found = i;
319-
//printf("FOUND!\n");
422+
printf("continuing with %s (action %d)\n", actor->actions[i]->action_name, i);
423+
printf(" beg cos found = %d, i = %d, actions_nb = %d\n", found, i, actions_nb);
424+
if(actor->actions[i]->action_name==NULL)
320425
break;
426+
else {
427+
printf("comparing %s with %s\n", actor->actions[i]->action_name, token);
428+
printf("result = %d\n",strcmp(actor->actions[i]->action_name,token));
429+
result = strcmp(actor->actions[i]->action_name,token);
430+
printf("ea, result was %d\n", result);
431+
if(result==0){
432+
printf("action %s already exists\n", actor->actions[i]->action_name);
433+
found = i;
434+
break;
435+
}
436+
else {
437+
printf("eaea\n");
438+
printf("end? cos found = %d, i = %d, actions_nb = %d\n", found, i, actions_nb);
439+
}
321440
}
322441
}
323442
if (found == -1){
324-
//printf("not found, adding action %s\n", token);
443+
printf("not found, adding action %s\n", token);
325444
actor->actions[found_actions]->action_name = malloc(strlen(token)+1);
326445
strcpy(actor->actions[found_actions]->action_name,token);
446+
printf("%s added!\n", actor->actions[i]->action_name);
327447
}
328448

329449
current = (found == -1)? found_actions++ : found;
330450

451+
331452
for(i = 0; i <actor->actions[current]->events_nb; i++){
332453
token = strtok(NULL,";");
333454
actor->actions[current]->acumulator[i]->count += get_number(token);
@@ -349,7 +470,7 @@ event_acum_for_actor* process_data (char* path_todir, char* path_tofile, char* f
349470
for(i = 0; i< actions_nb;i++){
350471
fprintf(datafile,"%s;", actor->actions[i]->action_name);
351472
for(j=0; j < events_nb; j++){
352-
fprintf(datafile,"%lu;", actor->actions[i]->acumulator[j]->count);
473+
fprintf(datafile,"%llu;", actor->actions[i]->acumulator[j]->count);
353474
}
354475
fprintf(datafile,"\n");
355476
}
@@ -400,7 +521,8 @@ int get_number(char *line){ //removes quotes from string number
400521
}
401522
line[j] = '\0';
402523

403-
return atol(line);
524+
//char *tempptr=NULL;
525+
return strtoul(line,NULL,10);
404526
}
405527

406528
//test structure
@@ -416,7 +538,7 @@ void struct_test(struct event_acum_for_actor *data){
416538
printf("\tAction name: %s\n", data->actions[i]->action_name);
417539
printf("\tNumber of events: %d\n", data->actions[i]->events_nb);
418540
for(j=0; j < data->actions[i]->events_nb; j++){
419-
printf("\t\tEvent: %s, total: %lu\n", data->actions[i]->acumulator[j]->event_name, data->actions[i]->acumulator[j]->count);
541+
printf("\t\tEvent: %s, total: %llu\n", data->actions[i]->acumulator[j]->event_name, data->actions[i]->acumulator[j]->count);
420542
}
421543

422544
//printf("Event: %s, total: %lu\n",data->, data->acumulator->acum[i]);

0 commit comments

Comments
 (0)