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 | { | |
33 | unsigned int i, j, k, l; | |
66eaf2eb BP |
34 | long pos1, pos2; |
35 | const GraphFunctions* moduleGraphFunctions[]= { | |
36 | &syncState->processingModule->graphFunctions, | |
37 | &syncState->matchingModule->graphFunctions, | |
38 | &syncState->analysisModule->graphFunctions, | |
39 | }; | |
467066ee BP |
40 | const struct { |
41 | size_t plotsOffset, | |
42 | optionsOffset; | |
43 | char* name; | |
44 | } funcTypes[]= { | |
45 | {offsetof(GraphFunctions, writeTraceTracePlots), | |
46 | offsetof(GraphFunctions, writeTraceTraceOptions), "TraceTrace"}, | |
47 | {offsetof(GraphFunctions, writeTraceTimePlots), | |
48 | offsetof(GraphFunctions, writeTraceTimeOptions), "TraceTime"}, | |
49 | }; | |
50 | ||
66eaf2eb BP |
51 | fprintf(syncState->graphsStream, "\n"); |
52 | pos1= ftell(syncState->graphsStream); | |
53 | for (i= 0; i < syncState->traceNb; i++) | |
54 | { | |
55 | for (k= 0; k < sizeof(moduleGraphFunctions) / | |
56 | sizeof(*moduleGraphFunctions); k++) | |
57 | { | |
58 | GraphVariableFunction** writeVariables= (void*) | |
59 | moduleGraphFunctions[k] + offsetof(GraphFunctions, | |
60 | writeVariables); | |
61 | ||
62 | if (*writeVariables) | |
63 | { | |
64 | (*writeVariables)(syncState, i); | |
65 | } | |
66 | } | |
67 | } | |
68 | fflush(syncState->graphsStream); | |
69 | pos2= ftell(syncState->graphsStream); | |
70 | if (pos1 != pos2) | |
71 | { | |
72 | fprintf(syncState->graphsStream, "\n"); | |
73 | } | |
74 | ||
467066ee BP |
75 | for (l= 0; l < sizeof(funcTypes) / sizeof(*funcTypes); l++) |
76 | { | |
77 | // Cover the upper triangular matrix, i is the reference node. | |
78 | for (i= 0; i < syncState->traceNb; i++) | |
79 | { | |
80 | for (j= i + 1; j < syncState->traceNb; j++) | |
81 | { | |
66eaf2eb | 82 | long trunc; |
467066ee BP |
83 | |
84 | fprintf(syncState->graphsStream, | |
85 | "reset\n" | |
86 | "set output \"%03d-%03d-%s.eps\"\n" | |
87 | "plot \\\n", i, j, funcTypes[l].name); | |
88 | ||
89 | pos1= ftell(syncState->graphsStream); | |
90 | ||
91 | for (k= 0; k < sizeof(moduleGraphFunctions) / | |
92 | sizeof(*moduleGraphFunctions); k++) | |
93 | { | |
94 | GraphFunction** writePlots= (void*) | |
95 | moduleGraphFunctions[k] + funcTypes[l].plotsOffset; | |
96 | ||
97 | if (*writePlots) | |
98 | { | |
99 | (*writePlots)(syncState, i, j); | |
100 | } | |
101 | } | |
102 | ||
103 | fflush(syncState->graphsStream); | |
104 | pos2= ftell(syncState->graphsStream); | |
105 | if (pos1 != pos2) | |
106 | { | |
107 | // Remove the ", \\\n" from the last graph plot line | |
108 | trunc= pos2 - 4; | |
109 | } | |
110 | else | |
111 | { | |
112 | // Remove the "plot \\\n" line to avoid creating an invalid | |
113 | // gnuplot script | |
114 | trunc= pos2 - 7; | |
115 | } | |
116 | ||
117 | if (ftruncate(fileno(syncState->graphsStream), trunc) == -1) | |
118 | { | |
119 | g_error(strerror(errno)); | |
120 | } | |
121 | if (fseek(syncState->graphsStream, 0, SEEK_END) == -1) | |
122 | { | |
123 | g_error(strerror(errno)); | |
124 | } | |
125 | ||
126 | fprintf(syncState->graphsStream, | |
127 | "\nset output \"%03d-%03d-%s.eps\"\n" | |
128 | "set title \"\"\n", i, j, funcTypes[l].name); | |
129 | ||
130 | for (k= 0; k < sizeof(moduleGraphFunctions) / | |
131 | sizeof(*moduleGraphFunctions); k++) | |
132 | { | |
133 | GraphFunction** writeOptions= (void*) | |
134 | moduleGraphFunctions[k] + funcTypes[l].optionsOffset; | |
135 | ||
136 | if (*writeOptions) | |
137 | { | |
138 | (*writeOptions)(syncState, i, j); | |
139 | } | |
140 | } | |
141 | ||
142 | if (pos1 != pos2) | |
143 | { | |
144 | fprintf(syncState->graphsStream, "replot\n\n"); | |
145 | } | |
146 | else | |
147 | { | |
148 | fprintf(syncState->graphsStream, "\n"); | |
149 | } | |
150 | } | |
151 | } | |
152 | } | |
153 | } |