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> | |
2f076594 | 23 | #include <string.h> |
1d597550 BP |
24 | #include <unistd.h> |
25 | ||
26 | #include "sync_chain.h" | |
27 | ||
28 | ||
29 | GQueue processingModules= G_QUEUE_INIT; | |
30 | GQueue matchingModules= G_QUEUE_INIT; | |
31 | GQueue analysisModules= G_QUEUE_INIT; | |
32 | GQueue moduleOptions= G_QUEUE_INIT; | |
33 | ||
34 | ||
1ed11971 BP |
35 | /* |
36 | * Calculate the elapsed time between two timeval values | |
37 | * | |
38 | * Args: | |
39 | * syncState: Container for synchronization data | |
40 | */ | |
41 | void printStats(SyncState* const syncState) | |
42 | { | |
43 | if (syncState->processingModule->printProcessingStats != NULL) | |
44 | { | |
45 | syncState->processingModule->printProcessingStats(syncState); | |
46 | } | |
47 | if (syncState->matchingModule->printMatchingStats != NULL) | |
48 | { | |
49 | syncState->matchingModule->printMatchingStats(syncState); | |
50 | } | |
51 | if (syncState->analysisModule->printAnalysisStats != NULL) | |
52 | { | |
53 | syncState->analysisModule->printAnalysisStats(syncState); | |
54 | } | |
55 | } | |
56 | ||
57 | ||
1d597550 BP |
58 | /* |
59 | * Calculate the elapsed time between two timeval values | |
60 | * | |
61 | * Args: | |
62 | * end: end time, result is also stored in this structure | |
63 | * start: start time | |
64 | */ | |
65 | void timeDiff(struct timeval* const end, const struct timeval* const start) | |
66 | { | |
67 | if (end->tv_usec >= start->tv_usec) | |
68 | { | |
69 | end->tv_sec-= start->tv_sec; | |
70 | end->tv_usec-= start->tv_usec; | |
71 | } | |
72 | else | |
73 | { | |
74 | end->tv_sec= end->tv_sec - start->tv_sec - 1; | |
75 | end->tv_usec= end->tv_usec - start->tv_usec + 1e6; | |
76 | } | |
77 | } | |
78 | ||
79 | ||
80 | /* | |
81 | * A GCompareFunc for g_slist_find_custom() | |
82 | * | |
83 | * Args: | |
84 | * a: ProcessingModule*, element's data | |
85 | * b: char*, user data to compare against | |
86 | * | |
87 | * Returns: | |
88 | * 0 if the processing module a's name is b | |
89 | */ | |
90 | gint gcfCompareProcessing(gconstpointer a, gconstpointer b) | |
91 | { | |
92 | const ProcessingModule* processingModule; | |
93 | const char* name; | |
94 | ||
95 | processingModule= (const ProcessingModule*) a; | |
96 | name= (const char*) b; | |
97 | ||
98 | return strncmp(processingModule->name, name, | |
99 | strlen(processingModule->name) + 1); | |
100 | } | |
101 | ||
102 | ||
103 | /* | |
104 | * A GCompareFunc for g_slist_find_custom() | |
105 | * | |
106 | * Args: | |
107 | * a: MatchingModule*, element's data | |
108 | * b: char*, user data to compare against | |
109 | * | |
110 | * Returns: | |
111 | * 0 if the matching module a's name is b | |
112 | */ | |
113 | gint gcfCompareMatching(gconstpointer a, gconstpointer b) | |
114 | { | |
115 | const MatchingModule* matchingModule; | |
116 | const char* name; | |
117 | ||
118 | matchingModule= (const MatchingModule*) a; | |
119 | name= (const char*) b; | |
120 | ||
121 | return strncmp(matchingModule->name, name, strlen(matchingModule->name) + | |
122 | 1); | |
123 | } | |
124 | ||
125 | ||
126 | /* | |
127 | * A GCompareFunc for g_slist_find_custom() | |
128 | * | |
129 | * Args: | |
130 | * a: AnalysisModule*, element's data | |
131 | * b: char*, user data to compare against | |
132 | * | |
133 | * Returns: | |
134 | * 0 if the analysis module a's name is b | |
135 | */ | |
136 | gint gcfCompareAnalysis(gconstpointer a, gconstpointer b) | |
137 | { | |
138 | const AnalysisModule* analysisModule; | |
139 | const char* name; | |
140 | ||
141 | analysisModule= (const AnalysisModule*) a; | |
142 | name= (const char*) b; | |
143 | ||
144 | return strncmp(analysisModule->name, name, strlen(analysisModule->name) + | |
145 | 1); | |
146 | } | |
49c335f1 BP |
147 | |
148 | ||
149 | /* | |
150 | * A GFunc for g_queue_foreach() | |
151 | * | |
152 | * Concatenate analysis module names. | |
153 | * | |
154 | * Args: | |
155 | * data: AnalysisModule* | |
156 | * user_data: GString*, concatenated names | |
157 | */ | |
158 | void gfAppendAnalysisName(gpointer data, gpointer user_data) | |
159 | { | |
160 | g_string_append((GString*) user_data, ((AnalysisModule*) data)->name); | |
161 | g_string_append((GString*) user_data, ", "); | |
162 | } |