Commit | Line | Data |
---|---|---|
1d597550 | 1 | /* This file is part of the Linux Trace Toolkit viewer |
277e5b53 | 2 | * Copyright (C) 2009, 2010 Benjamin Poirier <benjamin.poirier@polymtl.ca> |
1d597550 | 3 | * |
277e5b53 BP |
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. | |
1d597550 | 8 | * |
277e5b53 BP |
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. | |
1d597550 | 13 | * |
277e5b53 BP |
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/>. | |
1d597550 BP |
16 | */ |
17 | ||
18 | #ifdef HAVE_CONFIG_H | |
19 | #include <config.h> | |
20 | #endif | |
21 | ||
22 | #include <errno.h> | |
0a87ec9a | 23 | #include <stdlib.h> |
2f076594 | 24 | #include <string.h> |
1d597550 BP |
25 | #include <unistd.h> |
26 | ||
27 | #include "sync_chain.h" | |
28 | ||
29 | ||
30 | GQueue processingModules= G_QUEUE_INIT; | |
31 | GQueue matchingModules= G_QUEUE_INIT; | |
32 | GQueue analysisModules= G_QUEUE_INIT; | |
b2da0724 | 33 | GQueue reductionModules= G_QUEUE_INIT; |
1d597550 BP |
34 | GQueue moduleOptions= G_QUEUE_INIT; |
35 | ||
36 | ||
1ed11971 | 37 | /* |
9c7696b8 | 38 | * Call the statistics function of each module of a sync chain |
1ed11971 BP |
39 | * |
40 | * Args: | |
41 | * syncState: Container for synchronization data | |
42 | */ | |
43 | void printStats(SyncState* const syncState) | |
44 | { | |
45 | if (syncState->processingModule->printProcessingStats != NULL) | |
46 | { | |
47 | syncState->processingModule->printProcessingStats(syncState); | |
48 | } | |
b2da0724 BP |
49 | if (syncState->matchingModule != NULL && |
50 | syncState->matchingModule->printMatchingStats != NULL) | |
1ed11971 BP |
51 | { |
52 | syncState->matchingModule->printMatchingStats(syncState); | |
53 | } | |
b2da0724 BP |
54 | if (syncState->analysisModule != NULL && |
55 | syncState->analysisModule->printAnalysisStats != NULL) | |
1ed11971 BP |
56 | { |
57 | syncState->analysisModule->printAnalysisStats(syncState); | |
58 | } | |
b2da0724 BP |
59 | if (syncState->reductionModule != NULL && |
60 | syncState->reductionModule->printReductionStats != NULL) | |
61 | { | |
62 | syncState->reductionModule->printReductionStats(syncState); | |
63 | } | |
1ed11971 BP |
64 | } |
65 | ||
66 | ||
1d597550 BP |
67 | /* |
68 | * Calculate the elapsed time between two timeval values | |
69 | * | |
70 | * Args: | |
71 | * end: end time, result is also stored in this structure | |
72 | * start: start time | |
73 | */ | |
74 | void timeDiff(struct timeval* const end, const struct timeval* const start) | |
75 | { | |
76 | if (end->tv_usec >= start->tv_usec) | |
77 | { | |
78 | end->tv_sec-= start->tv_sec; | |
79 | end->tv_usec-= start->tv_usec; | |
80 | } | |
81 | else | |
82 | { | |
83 | end->tv_sec= end->tv_sec - start->tv_sec - 1; | |
84 | end->tv_usec= end->tv_usec - start->tv_usec + 1e6; | |
85 | } | |
86 | } | |
87 | ||
88 | ||
89 | /* | |
90 | * A GCompareFunc for g_slist_find_custom() | |
91 | * | |
92 | * Args: | |
93 | * a: ProcessingModule*, element's data | |
94 | * b: char*, user data to compare against | |
95 | * | |
96 | * Returns: | |
97 | * 0 if the processing module a's name is b | |
98 | */ | |
99 | gint gcfCompareProcessing(gconstpointer a, gconstpointer b) | |
100 | { | |
101 | const ProcessingModule* processingModule; | |
102 | const char* name; | |
103 | ||
104 | processingModule= (const ProcessingModule*) a; | |
105 | name= (const char*) b; | |
106 | ||
107 | return strncmp(processingModule->name, name, | |
108 | strlen(processingModule->name) + 1); | |
109 | } | |
110 | ||
111 | ||
112 | /* | |
113 | * A GCompareFunc for g_slist_find_custom() | |
114 | * | |
115 | * Args: | |
116 | * a: MatchingModule*, element's data | |
117 | * b: char*, user data to compare against | |
118 | * | |
119 | * Returns: | |
120 | * 0 if the matching module a's name is b | |
121 | */ | |
122 | gint gcfCompareMatching(gconstpointer a, gconstpointer b) | |
123 | { | |
124 | const MatchingModule* matchingModule; | |
125 | const char* name; | |
126 | ||
127 | matchingModule= (const MatchingModule*) a; | |
128 | name= (const char*) b; | |
129 | ||
130 | return strncmp(matchingModule->name, name, strlen(matchingModule->name) + | |
131 | 1); | |
132 | } | |
133 | ||
134 | ||
135 | /* | |
136 | * A GCompareFunc for g_slist_find_custom() | |
137 | * | |
138 | * Args: | |
139 | * a: AnalysisModule*, element's data | |
140 | * b: char*, user data to compare against | |
141 | * | |
142 | * Returns: | |
143 | * 0 if the analysis module a's name is b | |
144 | */ | |
145 | gint gcfCompareAnalysis(gconstpointer a, gconstpointer b) | |
146 | { | |
147 | const AnalysisModule* analysisModule; | |
148 | const char* name; | |
149 | ||
150 | analysisModule= (const AnalysisModule*) a; | |
151 | name= (const char*) b; | |
152 | ||
153 | return strncmp(analysisModule->name, name, strlen(analysisModule->name) + | |
154 | 1); | |
155 | } | |
49c335f1 BP |
156 | |
157 | ||
b2da0724 BP |
158 | /* |
159 | * A GCompareFunc for g_slist_find_custom() | |
160 | * | |
161 | * Args: | |
162 | * a: ReductionModule*, element's data | |
163 | * b: char*, user data to compare against | |
164 | * | |
165 | * Returns: | |
166 | * 0 if the reduction module a's name is b | |
167 | */ | |
168 | gint gcfCompareReduction(gconstpointer a, gconstpointer b) | |
169 | { | |
170 | const ReductionModule* reductionModule; | |
171 | const char* name; | |
172 | ||
173 | reductionModule= (const ReductionModule*) a; | |
174 | name= (const char*) b; | |
175 | ||
176 | return strncmp(reductionModule->name, name, strlen(reductionModule->name) + | |
177 | 1); | |
178 | } | |
179 | ||
180 | ||
49c335f1 BP |
181 | /* |
182 | * A GFunc for g_queue_foreach() | |
183 | * | |
184 | * Concatenate analysis module names. | |
185 | * | |
186 | * Args: | |
187 | * data: AnalysisModule* | |
188 | * user_data: GString*, concatenated names | |
189 | */ | |
190 | void gfAppendAnalysisName(gpointer data, gpointer user_data) | |
191 | { | |
192 | g_string_append((GString*) user_data, ((AnalysisModule*) data)->name); | |
193 | g_string_append((GString*) user_data, ", "); | |
194 | } | |
b2da0724 BP |
195 | |
196 | ||
197 | /* | |
198 | * A GFunc for g_queue_foreach() | |
199 | * | |
200 | * Concatenate reduction module names. | |
201 | * | |
202 | * Args: | |
203 | * data: ReductionModule* | |
204 | * user_data: GString*, concatenated names | |
205 | */ | |
206 | void gfAppendReductionName(gpointer data, gpointer user_data) | |
207 | { | |
208 | g_string_append((GString*) user_data, ((ReductionModule*) data)->name); | |
209 | g_string_append((GString*) user_data, ", "); | |
210 | } |