From dbeec76cb8305b7f94203da2eb56a760c46ec835 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 12 Jun 2013 17:56:02 +0300 Subject: [PATCH] smatch: add --time option for debugging what takes so long Put the following code: struct timeval start; gettimeofday(&start, NULL); ... ms = ms_since(&start); sm_msg("used %d ms", ms); Signed-off-by: Dan Carpenter --- smatch.c | 2 ++ smatch.h | 3 +++ smatch_helper.c | 11 +++++++++++ 3 files changed, 16 insertions(+) diff --git a/smatch.c b/smatch.c index 6befae15..fe1114cb 100644 --- a/smatch.c +++ b/smatch.c @@ -26,6 +26,7 @@ int option_call_tree = 0; int option_no_db = 0; int option_debug_related; int option_file_output; +int option_time; char *option_datadir_str; FILE *sm_outfd; @@ -145,6 +146,7 @@ void parse_args(int *argcp, char ***argvp) OPTION(param_mapper); OPTION(call_tree); OPTION(file_output); + OPTION(time); if (!found) break; (*argcp)--; diff --git a/smatch.h b/smatch.h index 64e6d663..c58b53a3 100644 --- a/smatch.h +++ b/smatch.h @@ -13,6 +13,7 @@ #include #include #include +#include #include "lib.h" #include "allocate.h" #include "parse.h" @@ -274,6 +275,7 @@ char *get_fnptr_name(struct expression *expr); int positions_eq(struct position pos1, struct position pos2); struct statement *get_current_statement(void); int get_param_num_from_sym(struct symbol *sym); +int ms_since(struct timeval *start); /* smatch_type.c */ struct symbol *get_real_base_type(struct symbol *sym); @@ -333,6 +335,7 @@ extern int option_known_conditions; extern int option_two_passes; extern int option_no_db; extern int option_file_output; +extern int option_time; extern struct expression_list *big_expression_stack; extern struct statement_list *big_statement_stack; int inlinable(struct expression *expr); diff --git a/smatch_helper.c b/smatch_helper.c index 0ec43d55..732ccaae 100644 --- a/smatch_helper.c +++ b/smatch_helper.c @@ -535,3 +535,14 @@ int get_param_num_from_sym(struct symbol *sym) return -1; } +int ms_since(struct timeval *start) +{ + struct timeval end; + double diff; + + gettimeofday(&end, NULL); + diff = (end.tv_sec - start->tv_sec) * 1000.0; + diff += (end.tv_usec - start->tv_usec) / 1000.0; + return (int)diff; +} + -- 2.11.4.GIT