| 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 | * end: end time, result is also stored in this structure |
| 41 | * start: start time |
| 42 | */ |
| 43 | void timeDiff(struct timeval* const end, const struct timeval* const start) |
| 44 | { |
| 45 | if (end->tv_usec >= start->tv_usec) |
| 46 | { |
| 47 | end->tv_sec-= start->tv_sec; |
| 48 | end->tv_usec-= start->tv_usec; |
| 49 | } |
| 50 | else |
| 51 | { |
| 52 | end->tv_sec= end->tv_sec - start->tv_sec - 1; |
| 53 | end->tv_usec= end->tv_usec - start->tv_usec + 1e6; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | |
| 58 | /* |
| 59 | * A GCompareFunc for g_slist_find_custom() |
| 60 | * |
| 61 | * Args: |
| 62 | * a: ProcessingModule*, element's data |
| 63 | * b: char*, user data to compare against |
| 64 | * |
| 65 | * Returns: |
| 66 | * 0 if the processing module a's name is b |
| 67 | */ |
| 68 | gint gcfCompareProcessing(gconstpointer a, gconstpointer b) |
| 69 | { |
| 70 | const ProcessingModule* processingModule; |
| 71 | const char* name; |
| 72 | |
| 73 | processingModule= (const ProcessingModule*) a; |
| 74 | name= (const char*) b; |
| 75 | |
| 76 | return strncmp(processingModule->name, name, |
| 77 | strlen(processingModule->name) + 1); |
| 78 | } |
| 79 | |
| 80 | |
| 81 | /* |
| 82 | * A GCompareFunc for g_slist_find_custom() |
| 83 | * |
| 84 | * Args: |
| 85 | * a: MatchingModule*, element's data |
| 86 | * b: char*, user data to compare against |
| 87 | * |
| 88 | * Returns: |
| 89 | * 0 if the matching module a's name is b |
| 90 | */ |
| 91 | gint gcfCompareMatching(gconstpointer a, gconstpointer b) |
| 92 | { |
| 93 | const MatchingModule* matchingModule; |
| 94 | const char* name; |
| 95 | |
| 96 | matchingModule= (const MatchingModule*) a; |
| 97 | name= (const char*) b; |
| 98 | |
| 99 | return strncmp(matchingModule->name, name, strlen(matchingModule->name) + |
| 100 | 1); |
| 101 | } |
| 102 | |
| 103 | |
| 104 | /* |
| 105 | * A GCompareFunc for g_slist_find_custom() |
| 106 | * |
| 107 | * Args: |
| 108 | * a: AnalysisModule*, element's data |
| 109 | * b: char*, user data to compare against |
| 110 | * |
| 111 | * Returns: |
| 112 | * 0 if the analysis module a's name is b |
| 113 | */ |
| 114 | gint gcfCompareAnalysis(gconstpointer a, gconstpointer b) |
| 115 | { |
| 116 | const AnalysisModule* analysisModule; |
| 117 | const char* name; |
| 118 | |
| 119 | analysisModule= (const AnalysisModule*) a; |
| 120 | name= (const char*) b; |
| 121 | |
| 122 | return strncmp(analysisModule->name, name, strlen(analysisModule->name) + |
| 123 | 1); |
| 124 | } |