1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2009 Benjamin Poirier <benjamin.poirier@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 #include <sys/types.h>
31 #include "sync_chain.h"
32 #include "graph_functions.h"
36 * Create the directory used to hold graphs and the header of the gnuplot
40 * graphsDir: name of directory
43 * The current working directory before the execution of the function. The
44 * string must be free'd by the caller.
46 FILE* createGraphsDir(const char* const graphsDir
)
53 cwd
= changeToGraphsDir(graphsDir
);
55 if ((graphsFp
= open("graphs.gnu", O_WRONLY
| O_CREAT
| O_TRUNC
, S_IRUSR
|
56 S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
| S_IROTH
57 | S_IWOTH
| S_IXOTH
)) == -1)
59 g_error(strerror(errno
));
61 if ((result
= fdopen(graphsFp
, "w")) == NULL
)
63 g_error(strerror(errno
));
67 "#!/usr/bin/gnuplot\n\n"
68 "set terminal postscript eps color size 8in,6in\n");
73 g_error(strerror(errno
));
82 * Change to the directory used to hold graphs. Create it if necessary.
85 * graphsDir: name of directory
88 * The current working directory before the execution of the function. The
89 * string must be free'd by the caller.
91 char* changeToGraphsDir(const char* const graphsDir
)
99 g_error(strerror(errno
));
101 while ((retval
= chdir(graphsDir
)) != 0)
105 retval
= mkdir(graphsDir
, S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
|
106 S_IWGRP
| S_IXGRP
| S_IROTH
| S_IWOTH
| S_IXOTH
);
109 g_error(strerror(errno
));
114 g_error(strerror(errno
));
123 * Call each graph variable, option and plot line function of each module to
124 * produce a gnuplot script.
127 * syncState: container for synchronization data
129 void writeGraphsScript(SyncState
* const syncState
)
131 unsigned int i
, j
, k
, l
, m
;
133 const GraphFunctions
* moduleGraphFunctions
[]= {
134 &syncState
->processingModule
->graphFunctions
,
135 &syncState
->matchingModule
->graphFunctions
,
136 &syncState
->analysisModule
->graphFunctions
,
140 size_t plotsOffsets
[2];
141 size_t optionsOffset
;
146 offsetof(GraphFunctions
, writeTraceTraceBackPlots
),
147 offsetof(GraphFunctions
, writeTraceTraceForePlots
),
149 offsetof(GraphFunctions
, writeTraceTraceOptions
),
154 offsetof(GraphFunctions
, writeTraceTimeBackPlots
),
155 offsetof(GraphFunctions
, writeTraceTimeForePlots
),
157 offsetof(GraphFunctions
, writeTraceTimeOptions
),
161 fprintf(syncState
->graphsStream
, "\n");
164 pos1
= ftell(syncState
->graphsStream
);
165 for (i
= 0; i
< syncState
->traceNb
; i
++)
167 for (k
= 0; k
< sizeof(moduleGraphFunctions
) /
168 sizeof(*moduleGraphFunctions
); k
++)
170 GraphVariableFunction
** writeVariables
= (void*)
171 moduleGraphFunctions
[k
] + offsetof(GraphFunctions
,
176 (*writeVariables
)(syncState
, i
);
180 fflush(syncState
->graphsStream
);
181 pos2
= ftell(syncState
->graphsStream
);
184 fprintf(syncState
->graphsStream
, "\n");
187 // Write plots and options
188 for (l
= 0; l
< sizeof(graphTypes
) / sizeof(*graphTypes
); l
++)
190 // Cover the upper triangular matrix, i is the reference node.
191 for (i
= 0; i
< syncState
->traceNb
; i
++)
193 for (j
= i
+ 1; j
< syncState
->traceNb
; j
++)
197 fprintf(syncState
->graphsStream
,
199 "set output \"%03d-%03d-%s.eps\"\n"
200 "plot \\\n", i
, j
, graphTypes
[l
].name
);
202 pos1
= ftell(syncState
->graphsStream
);
204 for (m
= 0; m
< sizeof(graphTypes
[l
].plotsOffsets
) /
205 sizeof(*graphTypes
[l
].plotsOffsets
); m
++)
207 for (k
= 0; k
< sizeof(moduleGraphFunctions
) /
208 sizeof(*moduleGraphFunctions
); k
++)
210 GraphFunction
** writePlots
= (void*)
211 moduleGraphFunctions
[k
] +
212 graphTypes
[l
].plotsOffsets
[m
];
216 (*writePlots
)(syncState
, i
, j
);
221 fflush(syncState
->graphsStream
);
222 pos2
= ftell(syncState
->graphsStream
);
225 // Remove the ", \\\n" from the last graph plot line
230 // Remove the "plot \\\n" line to avoid creating an invalid
235 if (ftruncate(fileno(syncState
->graphsStream
), trunc
) == -1)
237 g_error(strerror(errno
));
239 if (fseek(syncState
->graphsStream
, 0, SEEK_END
) == -1)
241 g_error(strerror(errno
));
244 fprintf(syncState
->graphsStream
,
245 "\nset output \"%03d-%03d-%s.eps\"\n"
246 "set title \"\"\n", i
, j
, graphTypes
[l
].name
);
248 for (k
= 0; k
< sizeof(moduleGraphFunctions
) /
249 sizeof(*moduleGraphFunctions
); k
++)
251 GraphFunction
** writeOptions
= (void*)
252 moduleGraphFunctions
[k
] + graphTypes
[l
].optionsOffset
;
256 (*writeOptions
)(syncState
, i
, j
);
262 fprintf(syncState
->graphsStream
, "replot\n\n");
266 fprintf(syncState
->graphsStream
, "\n");
This page took 0.035098 seconds and 4 git commands to generate.