91feef0c45c5a64f2cc28dc3424d3cf748ec4297
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2009, 2010 Benjamin Poirier <benjamin.poirier@polymtl.ca>
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 2.1 of the License, or (at
7 * your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12 * License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include <sys/types.h>
30 #include "sync_chain.h"
31 #include "graph_functions.h"
35 * Create the directory used to hold graphs and the header of the gnuplot
39 * graphsDir: name of directory
42 * The current working directory before the execution of the function. The
43 * string must be free'd by the caller.
45 FILE* createGraphsDir(const char* const graphsDir
)
52 cwd
= changeToGraphsDir(graphsDir
);
54 if ((graphsFp
= open("graphs.gnu", O_WRONLY
| O_CREAT
| O_TRUNC
, S_IRUSR
|
55 S_IWUSR
| S_IXUSR
| S_IRGRP
| S_IWGRP
| S_IXGRP
| S_IROTH
56 | S_IWOTH
| S_IXOTH
)) == -1)
58 g_error("%s", strerror(errno
));
60 if ((result
= fdopen(graphsFp
, "w")) == NULL
)
62 g_error("%s", strerror(errno
));
66 "#!/usr/bin/gnuplot\n\n"
67 "set terminal postscript eps color size 8in,6in\n");
72 g_error("%s", strerror(errno
));
81 * Change to the directory used to hold graphs. Create it if necessary.
84 * graphsDir: name of directory
87 * The current working directory before the execution of the function. The
88 * string must be free'd by the caller.
90 char* changeToGraphsDir(const char* const graphsDir
)
98 g_error("%s", strerror(errno
));
100 while ((retval
= chdir(graphsDir
)) != 0)
104 retval
= mkdir(graphsDir
, S_IRUSR
| S_IWUSR
| S_IXUSR
| S_IRGRP
|
105 S_IWGRP
| S_IXGRP
| S_IROTH
| S_IWOTH
| S_IXOTH
);
108 g_error("%s", strerror(errno
));
113 g_error("%s", strerror(errno
));
122 * Call each graph variable, option and plot line function of each module to
123 * produce a gnuplot script.
126 * syncState: container for synchronization data
128 void writeGraphsScript(SyncState
* const syncState
)
130 unsigned int i
, j
, k
, l
, m
;
132 const GraphFunctions
* moduleGraphFunctions
[]= {
133 &syncState
->processingModule
->graphFunctions
,
134 &syncState
->matchingModule
->graphFunctions
,
135 &syncState
->analysisModule
->graphFunctions
,
139 size_t plotsOffsets
[2];
140 size_t optionsOffset
;
145 offsetof(GraphFunctions
, writeTraceTraceBackPlots
),
146 offsetof(GraphFunctions
, writeTraceTraceForePlots
),
148 offsetof(GraphFunctions
, writeTraceTraceOptions
),
153 offsetof(GraphFunctions
, writeTraceTimeBackPlots
),
154 offsetof(GraphFunctions
, writeTraceTimeForePlots
),
156 offsetof(GraphFunctions
, writeTraceTimeOptions
),
160 fprintf(syncState
->graphsStream
, "\n");
163 pos1
= ftell(syncState
->graphsStream
);
164 for (i
= 0; i
< syncState
->traceNb
; i
++)
166 for (k
= 0; k
< sizeof(moduleGraphFunctions
) /
167 sizeof(*moduleGraphFunctions
); k
++)
169 GraphVariableFunction
** writeVariables
= (void*)
170 moduleGraphFunctions
[k
] + offsetof(GraphFunctions
,
175 (*writeVariables
)(syncState
, i
);
179 fflush(syncState
->graphsStream
);
180 pos2
= ftell(syncState
->graphsStream
);
183 fprintf(syncState
->graphsStream
, "\n");
186 // Write plots and options
187 for (l
= 0; l
< sizeof(graphTypes
) / sizeof(*graphTypes
); l
++)
189 // Cover the upper triangular matrix, i is the reference node.
190 for (i
= 0; i
< syncState
->traceNb
; i
++)
192 for (j
= i
+ 1; j
< syncState
->traceNb
; j
++)
196 fprintf(syncState
->graphsStream
,
198 "set output \"%03d-%03d-%s.eps\"\n"
199 "plot \\\n", i
, j
, graphTypes
[l
].name
);
201 pos1
= ftell(syncState
->graphsStream
);
203 for (m
= 0; m
< sizeof(graphTypes
[l
].plotsOffsets
) /
204 sizeof(*graphTypes
[l
].plotsOffsets
); m
++)
206 for (k
= 0; k
< sizeof(moduleGraphFunctions
) /
207 sizeof(*moduleGraphFunctions
); k
++)
209 GraphFunction
** writePlots
= (void*)
210 moduleGraphFunctions
[k
] +
211 graphTypes
[l
].plotsOffsets
[m
];
215 (*writePlots
)(syncState
, i
, j
);
220 fflush(syncState
->graphsStream
);
221 pos2
= ftell(syncState
->graphsStream
);
224 // Remove the ", \\\n" from the last graph plot line
229 // Remove the "plot \\\n" line to avoid creating an invalid
234 if (ftruncate(fileno(syncState
->graphsStream
), trunc
) == -1)
236 g_error("%s", strerror(errno
));
238 if (fseek(syncState
->graphsStream
, 0, SEEK_END
) == -1)
240 g_error("%s", strerror(errno
));
243 fprintf(syncState
->graphsStream
,
244 "\nset output \"%03d-%03d-%s.eps\"\n"
245 "set title \"\"\n", i
, j
, graphTypes
[l
].name
);
247 for (k
= 0; k
< sizeof(moduleGraphFunctions
) /
248 sizeof(*moduleGraphFunctions
); k
++)
250 GraphFunction
** writeOptions
= (void*)
251 moduleGraphFunctions
[k
] + graphTypes
[l
].optionsOffset
;
255 (*writeOptions
)(syncState
, i
, j
);
261 fprintf(syncState
->graphsStream
, "replot\n\n");
265 fprintf(syncState
->graphsStream
, "\n");
This page took 0.037124 seconds and 5 git commands to generate.