Skip to content

Commit 560ff33

Browse files
committed
Memory problems 100% fixed! (hopefully)
thank you valgrind!! Change-Id: I8ae12a49e640c3c3580f2a65b49a93deb7b3221c Signed-off-by: panacotta <[email protected]>
1 parent 4bd65ce commit 560ff33

File tree

4 files changed

+66
-45
lines changed

4 files changed

+66
-45
lines changed

papiplot/.cproject

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
<folderInfo id="cdt.managedbuild.config.gnu.cross.exe.debug.1391840483." name="/" resourcePath="">
1919
<toolChain id="cdt.managedbuild.toolchain.gnu.cross.exe.debug.1565545621" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.exe.debug">
2020
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.368477015" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
21-
<builder buildPath="${workspace_loc:/plot_test}/Debug" id="cdt.managedbuild.builder.gnu.cross.590927943" managedBuildOn="true" name="Gnu Make Builder.Debug" superClass="cdt.managedbuild.builder.gnu.cross"/>
21+
<builder buildPath="${workspace_loc:/plot_test}/Debug" id="cdt.managedbuild.builder.gnu.cross.590927943" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.builder.gnu.cross"/>
2222
<tool id="cdt.managedbuild.tool.gnu.cross.c.compiler.594641248" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler">
23-
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.option.optimization.level.2003558576" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
24-
<option id="gnu.c.compiler.option.debugging.level.551723003" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.max" valueType="enumerated"/>
23+
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.option.optimization.level.2003558576" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
24+
<option id="gnu.c.compiler.option.debugging.level.551723003" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.max" valueType="enumerated"/>
2525
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1123349267" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
2626
</tool>
2727
<tool id="cdt.managedbuild.tool.gnu.cross.cpp.compiler.409824799" name="Cross G++ Compiler" superClass="cdt.managedbuild.tool.gnu.cross.cpp.compiler">
28-
<option id="gnu.cpp.compiler.option.optimization.level.1969275390" superClass="gnu.cpp.compiler.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
29-
<option id="gnu.cpp.compiler.option.debugging.level.1614499791" superClass="gnu.cpp.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
28+
<option id="gnu.cpp.compiler.option.optimization.level.1969275390" name="Optimization Level" superClass="gnu.cpp.compiler.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
29+
<option id="gnu.cpp.compiler.option.debugging.level.1614499791" name="Debug Level" superClass="gnu.cpp.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
3030
</tool>
3131
<tool id="cdt.managedbuild.tool.gnu.cross.c.linker.365644319" name="Cross GCC Linker" superClass="cdt.managedbuild.tool.gnu.cross.c.linker">
3232
<inputType id="cdt.managedbuild.tool.gnu.c.linker.input.2048517126" superClass="cdt.managedbuild.tool.gnu.c.linker.input">
@@ -62,15 +62,15 @@
6262
<folderInfo id="cdt.managedbuild.config.gnu.cross.exe.release.1382231523." name="/" resourcePath="">
6363
<toolChain id="cdt.managedbuild.toolchain.gnu.cross.exe.release.1736900047" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.exe.release">
6464
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.2277642" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
65-
<builder buildPath="${workspace_loc:/plot_test}/Release" id="cdt.managedbuild.builder.gnu.cross.1538376542" managedBuildOn="true" name="Gnu Make Builder.Release" superClass="cdt.managedbuild.builder.gnu.cross"/>
65+
<builder buildPath="${workspace_loc:/plot_test}/Release" id="cdt.managedbuild.builder.gnu.cross.1538376542" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.builder.gnu.cross"/>
6666
<tool id="cdt.managedbuild.tool.gnu.cross.c.compiler.29963286" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler">
67-
<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.option.optimization.level.337190259" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
68-
<option id="gnu.c.compiler.option.debugging.level.1565902536" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/>
67+
<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.option.optimization.level.337190259" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
68+
<option id="gnu.c.compiler.option.debugging.level.1565902536" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/>
6969
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1203242239" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
7070
</tool>
7171
<tool id="cdt.managedbuild.tool.gnu.cross.cpp.compiler.266930548" name="Cross G++ Compiler" superClass="cdt.managedbuild.tool.gnu.cross.cpp.compiler">
72-
<option id="gnu.cpp.compiler.option.optimization.level.656050058" superClass="gnu.cpp.compiler.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
73-
<option id="gnu.cpp.compiler.option.debugging.level.2107971850" superClass="gnu.cpp.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
72+
<option id="gnu.cpp.compiler.option.optimization.level.656050058" name="Optimization Level" superClass="gnu.cpp.compiler.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
73+
<option id="gnu.cpp.compiler.option.debugging.level.2107971850" name="Debug Level" superClass="gnu.cpp.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
7474
</tool>
7575
<tool id="cdt.managedbuild.tool.gnu.cross.c.linker.1041894374" name="Cross GCC Linker" superClass="cdt.managedbuild.tool.gnu.cross.c.linker">
7676
<inputType id="cdt.managedbuild.tool.gnu.c.linker.input.193461595" superClass="cdt.managedbuild.tool.gnu.c.linker.input">
303 KB
Loading

papiplot/readme/madness.png

664 KB
Loading

papiplot/src/plot.c

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
#include "gnuplot_i.h"
99
#include <dirent.h>
10+
#include <getopt.h>
11+
#include <ctype.h>
12+
1013
typedef struct event_acumulator {
1114
char* event_name;
1215
unsigned long long count;
@@ -113,7 +116,10 @@ int main(int argc, char **argv) {
113116

114117
if(path==NULL){
115118
char cwd[3000];
116-
getcwd(cwd, sizeof(cwd));
119+
if(getcwd(cwd, sizeof(cwd))==NULL){
120+
perror("Error retrieving working path:");
121+
exit(0);
122+
}
117123
len = strlen(cwd)+2;
118124
path = malloc(len);
119125
strcpy(path, cwd);
@@ -123,6 +129,7 @@ int main(int argc, char **argv) {
123129

124130
search_and_plot(path);
125131

132+
printf("All done!\n");
126133
return 0;
127134
}
128135

@@ -311,7 +318,9 @@ int get_events_nb(char *path) {
311318
int nb = 0;
312319
FILE* file = fopen(path,"r");
313320

314-
fgets(buf,1500,file);
321+
if(fgets(buf,1500,file)==NULL){
322+
return 0;
323+
}
315324

316325
token = strtok(buf,";");
317326

@@ -331,8 +340,8 @@ const int is_papioutput(const char *filename) {
331340
}
332341

333342
void html_init(FILE* htmlfile){
334-
fprintf(htmlfile, "<html><head><meta content=\"text/html; charset=ISO-8859-1\" http-equiv=\"content-type\"><title>PAPI stats</title></head>"
335-
"<body><h1>Papify stats processed with PapiPlot</h1><hr style=\"width: 100%; height: 2px;\">");
343+
fprintf(htmlfile, "<html><head><meta content=\"text/html; charset=ISO-8859-1\" http-equiv=\"content-type\"><title>PAPI stats</title></head>\n"
344+
"<body><h1>Papify stats processed with PapiPlot</h1><hr style=\"width: 100%%; height: 2px;\">\n");
336345
}
337346
void html_close(FILE* htmlfile, char* path){
338347
fprintf(htmlfile, "<h2>Overall: Events per actor</h2><img alt=\"\""
@@ -349,7 +358,11 @@ void html_close(FILE* htmlfile, char* path){
349358

350359
fprintf(htmlfile,"<table border=\"1\">"
351360
"<td>Actor<br></td>");
352-
fgets(buf, 1500, ofile);
361+
362+
if(fgets(buf, 1500, ofile)==NULL){
363+
perror("");
364+
}
365+
353366
token = strtok(buf,";");
354367
for(i=0;i<events_nb;i++){
355368
token = strtok(NULL,";");
@@ -360,7 +373,8 @@ void html_close(FILE* htmlfile, char* path){
360373
int actors_nb = get_actions_nb_in_file(path);
361374
for(i=0;i<actors_nb;i++){
362375
fprintf(htmlfile,"<tr>\n");
363-
fgets(buf, 1500, ofile);
376+
if(fgets(buf, 1500, ofile)==NULL)
377+
perror("");
364378
token = strtok(buf,";");
365379
for(j=0;j<events_nb+1;j++){
366380
fprintf(htmlfile,"<td>%s<br></td>\n", token);
@@ -370,7 +384,7 @@ void html_close(FILE* htmlfile, char* path){
370384
}
371385

372386
fprintf(htmlfile,"</table>\n");
373-
fprintf(htmlfile,"<hr style=\"width: 100%; height: 2px;\">\n");
387+
fprintf(htmlfile,"<hr style=\"width: 100%%; height: 2px;\">\n");
374388
fprintf(htmlfile,"<br>\n");
375389

376390

@@ -379,7 +393,7 @@ void html_close(FILE* htmlfile, char* path){
379393
}
380394

381395
void html_actor(FILE* htmlfile, event_acum_for_actor* data){
382-
fprintf(htmlfile,"<table style=\"text-align: left; width: 100%;\" border=\"1\" cellpadding=\"2\""
396+
fprintf(htmlfile,"<table style=\"text-align: left; width: 100%%;\" border=\"1\" cellpadding=\"2\""
383397
"cellspacing=\"2\">\n");
384398

385399
fprintf(htmlfile,"<table border=\"1\">"
@@ -408,20 +422,20 @@ void html_actor(FILE* htmlfile, event_acum_for_actor* data){
408422
fprintf(htmlfile,"</tr>\n");
409423
}
410424
fprintf(htmlfile,"</table>\n");
411-
fprintf(htmlfile,"<hr style=\"width: 100%; height: 2px;\">\n");
425+
fprintf(htmlfile,"<hr style=\"width: 100%%; height: 2px;\">\n");
412426
fprintf(htmlfile,"<br>\n");
413427
}
414428

415429
void search_and_plot(char *path) {
416430

417-
char * path_to_totals = malloc(strlen(path)+strlen("plotdata_papi_totals.csv")+2);
431+
char * path_to_totals = malloc(sizeof(char)*(strlen(path)+strlen("plotdata_papi_totals.csv")+2));
418432
strcpy(path_to_totals, path);
419433
strcat(path_to_totals,"plotdata_papi_totals.csv");
420434

421435
FILE* datafile = fopen(path_to_totals,"w");//reset
422436
fclose(datafile);
423437

424-
char * html = malloc(strlen(path)+strlen("papiplot.html")+2);
438+
char * html = malloc(sizeof(char)*(strlen(path)+strlen("papiplot.html")+2));
425439
strcpy(html, path);
426440
strcat(html,"papiplot.html");
427441
FILE* htmlfile = fopen(html,"w");
@@ -434,15 +448,15 @@ void search_and_plot(char *path) {
434448

435449
pDir = opendir (path);
436450
if (pDir == NULL) {
437-
perror ("Cannot open directory\n");
451+
perror ("Cannot open directory");
438452
exit(1);
439453
}
440454
char * path_to_csv;
441455

442456
while ((pDirent = readdir(pDir)) != NULL) {
443457
if(is_papioutput(pDirent->d_name)) {
444-
//printf("going for %s\n", pDirent->d_name);
445-
path_to_csv = malloc(strlen(path)+strlen(pDirent->d_name)+2);
458+
printf("Plotting %s\n", pDirent->d_name);
459+
path_to_csv = malloc(sizeof(char)*(strlen(path)+strlen(pDirent->d_name)+2));
446460
strcpy(path_to_csv, path);
447461
strcat(path_to_csv,"/");
448462
strcat(path_to_csv,pDirent->d_name);
@@ -453,12 +467,14 @@ void search_and_plot(char *path) {
453467
free(data);
454468
}
455469
}
456-
//printf("going for overalls\n");
470+
printf("Plotting overalls\n");
457471
plot_overall(path, path_to_totals, actors_nb, get_events_nb(path_to_totals)+1);
458472

459473
html_close(htmlfile, path_to_totals);
460474
remove(path_to_totals);
461475

476+
free(path_to_totals);
477+
free(html);
462478
fclose(htmlfile);
463479
closedir (pDir);
464480
return;
@@ -468,47 +484,52 @@ event_acum_for_actor* process_data (char* path_todir, char* path_tofile, char* f
468484
char buf[1500];
469485
char *token;
470486
event_acum_for_actor* actor;
471-
char* path_todatafile = malloc(strlen(path_todir)+strlen("/papidata.temp")+4);
472-
char* actor_name = &(*filename)+12;
473-
//printf("actor name is %s\n", actor_name);
487+
char* path_todatafile = malloc(sizeof(char)*(strlen(path_todir)+strlen("/plotdata_")+strlen(filename)+1));
488+
char* actor_name = malloc(sizeof(char)*(strlen(filename)+1));
489+
strcpy(actor_name,filename);
490+
//memmove(actor_name, actor_name+12, strlen(actor_name));//or
491+
actor_name+=12;
492+
474493
strcpy(path_todatafile, path_todir);
475-
strcat(path_todatafile,"/");
476-
strcat(path_todatafile,"plotdata_");
494+
strcat(path_todatafile,"/plotdata_");
495+
char temp2[strlen(actor_name)];
496+
strcpy(temp2, actor_name);
477497
strcat(path_todatafile,actor_name);
478498
//printf("creating %s\n", path_todatafile);
479499

480-
500+
strcpy(actor_name, temp2);
481501
int events_nb = get_events_nb(path_tofile);
482502
//printf("we have %d actions here\n",get_actions_nb_in_file(path_tofile));/////////////////////////////////////////////
483503
//get_actions_nb_in_file(path_tofile);
484504
int actions_nb=get_actions_nb_in_file(path_tofile);
485505

486-
actor = malloc(sizeof(event_acum_for_actor)*2+sizeof(event_acum_for_action*)*(actions_nb)*3);//weird memory is weird..
487-
actor->actor_name = malloc(strlen(actor_name));
506+
actor = malloc(sizeof(event_acum_for_actor)+sizeof(event_acum_for_action*)*(actions_nb));//weird memory is weird..
507+
actor->actor_name = malloc(strlen(actor_name)+1);
488508
strcpy(actor->actor_name,actor_name);
509+
489510
actor->proc_file_path = path_todatafile;
490511
actor->actions_nb = actions_nb;
491512
int i, j;
492513

493514

494-
for(i=0;i<actions_nb*3;i++){
495-
actor->actions[i] = malloc(sizeof(event_acum_for_action)*2+sizeof(event_acumulator)*events_nb*3);//weird memory is weird..
515+
for(i=0;i<actions_nb;i++){
516+
actor->actions[i] = malloc(sizeof(event_acum_for_action)+sizeof(event_acumulator)*events_nb);//weird memory is weird..
496517
actor->actions[i]->events_nb = events_nb;
497-
//actor->actions[i]->action_name
498518
for(j=0;j<events_nb;j++){
499519
actor->actions[i]->acumulator[j] = malloc(sizeof(event_acumulator));
500-
//actor->actions[i]->acumulator->event_name
501520
}
502521
}
503522

504523

505-
for(j = 0; j <actor->actions_nb; j++)
524+
for(j = 0; j <actor->actions_nb; j++){
525+
actor->actions[j]->action_name=NULL;
506526
for(i = 0; i <actor->actions[j]->events_nb; i++){
507527
actor->actions[j]->acumulator[i]->count = 0;
508528
}
529+
}
509530

510531
FILE* ofile = fopen(path_tofile, "r");
511-
fgets(buf,1500,ofile);//read first line
532+
if(fgets(buf,1500,ofile)==NULL) perror("");//read first line
512533
token = strtok(buf,";");
513534
token = strtok(NULL,";");//skip action column (actot name)
514535

@@ -518,18 +539,17 @@ event_acum_for_actor* process_data (char* path_todir, char* path_tofile, char* f
518539
if(token[strlen(token)-1]=='\n') token[strlen(token)-1] = '\0';
519540
actor->actions[j]->acumulator[i]->event_name = malloc(strlen(token)+1);
520541
strcpy(actor->actions[j]->acumulator[i]->event_name, token);
521-
//acum->acumulator->event_name[i] = malloc(strlen(token)+1);
522-
//strcpy(acum->acumulator->event_name[i], token);
523542
}
524543
}
525544

526545

546+
527547
int found = -1;
528548
int found_actions = 0;
529549
int current;
530550

531551

532-
long unsigned int totals[events_nb];
552+
long long unsigned int totals[events_nb];
533553
for (i=0;i<events_nb;i++){
534554
totals[i]=0;
535555
}
@@ -574,6 +594,7 @@ event_acum_for_actor* process_data (char* path_todir, char* path_tofile, char* f
574594
}
575595

576596

597+
577598
fclose(ofile);
578599

579600
//writing events per action
@@ -595,7 +616,7 @@ event_acum_for_actor* process_data (char* path_todir, char* path_tofile, char* f
595616
//adding to totals per actor
596617
int label_set = 0;
597618
datafile = fopen(path_to_totals,"r");
598-
fgets(buf,1500,datafile);
619+
if(fgets(buf,1500,datafile)==NULL);// perror("");
599620
if(strstr(buf,"Actor;")!=NULL) label_set = 1;
600621
fclose(datafile);
601622

@@ -610,7 +631,7 @@ event_acum_for_actor* process_data (char* path_todir, char* path_tofile, char* f
610631

611632
fprintf(datafile,"%s;",strtok(actor->actor_name,"."));
612633
for(j=0; j < events_nb; j++){
613-
fprintf(datafile,"%lu;", totals[j]);
634+
fprintf(datafile,"%llu;", totals[j]);
614635
}
615636
fprintf(datafile,"\n");
616637
fclose(datafile);
@@ -694,7 +715,7 @@ int get_actions_nb_in_file(char* path_tofile){//weird memory allocation... ¿??
694715

695716
FILE* ofile = fopen(path_tofile, "r");
696717

697-
fgets(buf,1500,ofile);//skip labels lines
718+
if(fgets(buf,1500,ofile)==NULL) perror("");//skip labels lines
698719
while(fgets(buf,1500,ofile)!=NULL){
699720
token = strtok(buf,";");
700721
token = strtok(NULL,";");//read action name

0 commit comments

Comments
 (0)