Commit | Line | Data |
---|---|---|
467066ee BP |
1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2009 Benjamin Poirier <benjamin.poirier@polymtl.ca> | |
3 | * | |
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; | |
7 | * | |
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. | |
12 | * | |
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, | |
16 | * MA 02111-1307, USA. | |
17 | */ | |
18 | ||
19 | #ifdef HAVE_CONFIG_H | |
20 | #include <config.h> | |
21 | #endif | |
22 | ||
23 | #include <errno.h> | |
24 | #include <sys/types.h> | |
25 | #include <unistd.h> | |
26 | ||
27 | #include "sync_chain.h" | |
28 | #include "graph_functions.h" | |
29 | ||
30 | ||
31 | void writeGraphsScript(SyncState* const syncState) | |
32 | { | |
c6356aa7 | 33 | unsigned int i, j, k, l, m; |
66eaf2eb BP |
34 | long pos1, pos2; |
35 | const GraphFunctions* moduleGraphFunctions[]= { | |
36 | &syncState->processingModule->graphFunctions, | |
37 | &syncState->matchingModule->graphFunctions, | |
38 | &syncState->analysisModule->graphFunctions, | |
39 | }; | |
467066ee | 40 | const struct { |
467066ee | 41 | char* name; |
c6356aa7 BP |
42 | size_t plotsOffsets[2]; |
43 | size_t optionsOffset; | |
44 | } graphTypes[]= { | |
45 | { | |
46 | "TraceTrace", | |
47 | { | |
48 | offsetof(GraphFunctions, writeTraceTraceBackPlots), | |
49 | offsetof(GraphFunctions, writeTraceTraceForePlots), | |
50 | }, | |
51 | offsetof(GraphFunctions, writeTraceTraceOptions), | |
52 | }, | |
53 | { | |
54 | "TraceTime", | |
55 | { | |
56 | offsetof(GraphFunctions, writeTraceTimeBackPlots), | |
57 | offsetof(GraphFunctions, writeTraceTimeForePlots), | |
58 | }, | |
59 | offsetof(GraphFunctions, writeTraceTimeOptions), | |
60 | }, | |
467066ee BP |
61 | }; |
62 | ||
66eaf2eb | 63 | fprintf(syncState->graphsStream, "\n"); |
c6356aa7 BP |
64 | |
65 | // Write variables | |
66eaf2eb BP |
66 | pos1= ftell(syncState->graphsStream); |
67 | for (i= 0; i < syncState->traceNb; i++) | |
68 | { | |
69 | for (k= 0; k < sizeof(moduleGraphFunctions) / | |
70 | sizeof(*moduleGraphFunctions); k++) | |
71 | { | |
72 | GraphVariableFunction** writeVariables= (void*) | |
73 | moduleGraphFunctions[k] + offsetof(GraphFunctions, | |
74 | writeVariables); | |
75 | ||
76 | if (*writeVariables) | |
77 | { | |
78 | (*writeVariables)(syncState, i); | |
79 | } | |
80 | } | |
81 | } | |
82 | fflush(syncState->graphsStream); | |
83 | pos2= ftell(syncState->graphsStream); | |
84 | if (pos1 != pos2) | |
85 | { | |
86 | fprintf(syncState->graphsStream, "\n"); | |
87 | } | |
88 | ||
c6356aa7 BP |
89 | // Write plots and options |
90 | for (l= 0; l < sizeof(graphTypes) / sizeof(*graphTypes); l++) | |
467066ee BP |
91 | { |
92 | // Cover the upper triangular matrix, i is the reference node. | |
93 | for (i= 0; i < syncState->traceNb; i++) | |
94 | { | |
95 | for (j= i + 1; j < syncState->traceNb; j++) | |
96 | { | |
66eaf2eb | 97 | long trunc; |
467066ee BP |
98 | |
99 | fprintf(syncState->graphsStream, | |
100 | "reset\n" | |
101 | "set output \"%03d-%03d-%s.eps\"\n" | |
c6356aa7 | 102 | "plot \\\n", i, j, graphTypes[l].name); |
467066ee BP |
103 | |
104 | pos1= ftell(syncState->graphsStream); | |
105 | ||
c6356aa7 BP |
106 | for (m= 0; m < sizeof(graphTypes[l].plotsOffsets) / |
107 | sizeof(*graphTypes[l].plotsOffsets); m++) | |
467066ee | 108 | { |
c6356aa7 BP |
109 | for (k= 0; k < sizeof(moduleGraphFunctions) / |
110 | sizeof(*moduleGraphFunctions); k++) | |
467066ee | 111 | { |
c6356aa7 BP |
112 | GraphFunction** writePlots= (void*) |
113 | moduleGraphFunctions[k] + | |
114 | graphTypes[l].plotsOffsets[m]; | |
115 | ||
116 | if (*writePlots) | |
117 | { | |
118 | (*writePlots)(syncState, i, j); | |
119 | } | |
467066ee BP |
120 | } |
121 | } | |
122 | ||
123 | fflush(syncState->graphsStream); | |
124 | pos2= ftell(syncState->graphsStream); | |
125 | if (pos1 != pos2) | |
126 | { | |
127 | // Remove the ", \\\n" from the last graph plot line | |
128 | trunc= pos2 - 4; | |
129 | } | |
130 | else | |
131 | { | |
132 | // Remove the "plot \\\n" line to avoid creating an invalid | |
133 | // gnuplot script | |
134 | trunc= pos2 - 7; | |
135 | } | |
136 | ||
137 | if (ftruncate(fileno(syncState->graphsStream), trunc) == -1) | |
138 | { | |
139 | g_error(strerror(errno)); | |
140 | } | |
141 | if (fseek(syncState->graphsStream, 0, SEEK_END) == -1) | |
142 | { | |
143 | g_error(strerror(errno)); | |
144 | } | |
145 | ||
146 | fprintf(syncState->graphsStream, | |
147 | "\nset output \"%03d-%03d-%s.eps\"\n" | |
c6356aa7 | 148 | "set title \"\"\n", i, j, graphTypes[l].name); |
467066ee BP |
149 | |
150 | for (k= 0; k < sizeof(moduleGraphFunctions) / | |
151 | sizeof(*moduleGraphFunctions); k++) | |
152 | { | |
153 | GraphFunction** writeOptions= (void*) | |
c6356aa7 | 154 | moduleGraphFunctions[k] + graphTypes[l].optionsOffset; |
467066ee BP |
155 | |
156 | if (*writeOptions) | |
157 | { | |
158 | (*writeOptions)(syncState, i, j); | |
159 | } | |
160 | } | |
161 | ||
162 | if (pos1 != pos2) | |
163 | { | |
164 | fprintf(syncState->graphsStream, "replot\n\n"); | |
165 | } | |
166 | else | |
167 | { | |
168 | fprintf(syncState->graphsStream, "\n"); | |
169 | } | |
170 | } | |
171 | } | |
172 | } | |
173 | } |