Store graph callbacks in a structure
[lttv.git] / lttv / lttv / sync / graph_functions.c
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;
34 const struct {
35 size_t plotsOffset,
36 optionsOffset;
37 char* name;
38 } funcTypes[]= {
39 {offsetof(GraphFunctions, writeTraceTracePlots),
40 offsetof(GraphFunctions, writeTraceTraceOptions), "TraceTrace"},
41 {offsetof(GraphFunctions, writeTraceTimePlots),
42 offsetof(GraphFunctions, writeTraceTimeOptions), "TraceTime"},
43 };
44
45 for (l= 0; l < sizeof(funcTypes) / sizeof(*funcTypes); l++)
46 {
47 // Cover the upper triangular matrix, i is the reference node.
48 for (i= 0; i < syncState->traceNb; i++)
49 {
50 for (j= i + 1; j < syncState->traceNb; j++)
51 {
52 long pos1, pos2, trunc;
53 const GraphFunctions* moduleGraphFunctions[]= {
54 &syncState->processingModule->graphFunctions,
55 &syncState->matchingModule->graphFunctions,
56 &syncState->analysisModule->graphFunctions,
57 };
58
59 fprintf(syncState->graphsStream,
60 "reset\n"
61 "set output \"%03d-%03d-%s.eps\"\n"
62 "plot \\\n", i, j, funcTypes[l].name);
63
64 pos1= ftell(syncState->graphsStream);
65
66 for (k= 0; k < sizeof(moduleGraphFunctions) /
67 sizeof(*moduleGraphFunctions); k++)
68 {
69 GraphFunction** writePlots= (void*)
70 moduleGraphFunctions[k] + funcTypes[l].plotsOffset;
71
72 if (*writePlots)
73 {
74 (*writePlots)(syncState, i, j);
75 }
76 }
77
78 fflush(syncState->graphsStream);
79 pos2= ftell(syncState->graphsStream);
80 if (pos1 != pos2)
81 {
82 // Remove the ", \\\n" from the last graph plot line
83 trunc= pos2 - 4;
84 }
85 else
86 {
87 // Remove the "plot \\\n" line to avoid creating an invalid
88 // gnuplot script
89 trunc= pos2 - 7;
90 }
91
92 if (ftruncate(fileno(syncState->graphsStream), trunc) == -1)
93 {
94 g_error(strerror(errno));
95 }
96 if (fseek(syncState->graphsStream, 0, SEEK_END) == -1)
97 {
98 g_error(strerror(errno));
99 }
100
101 fprintf(syncState->graphsStream,
102 "\nset output \"%03d-%03d-%s.eps\"\n"
103 "set title \"\"\n", i, j, funcTypes[l].name);
104
105 for (k= 0; k < sizeof(moduleGraphFunctions) /
106 sizeof(*moduleGraphFunctions); k++)
107 {
108 GraphFunction** writeOptions= (void*)
109 moduleGraphFunctions[k] + funcTypes[l].optionsOffset;
110
111 if (*writeOptions)
112 {
113 (*writeOptions)(syncState, i, j);
114 }
115 }
116
117 if (pos1 != pos2)
118 {
119 fprintf(syncState->graphsStream, "replot\n\n");
120 }
121 else
122 {
123 fprintf(syncState->graphsStream, "\n");
124 }
125 }
126 }
127 }
128 }
This page took 0.031578 seconds and 4 git commands to generate.