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