1 |
zoff99 |
2 |
/**
|
2 |
|
|
* Navit, a modular navigation system.
|
3 |
|
|
* Copyright (C) 2005-2008 Navit Team
|
4 |
|
|
*
|
5 |
|
|
* This program is free software; you can redistribute it and/or
|
6 |
|
|
* modify it under the terms of the GNU General Public License
|
7 |
|
|
* version 2 as published by the Free Software Foundation.
|
8 |
|
|
*
|
9 |
|
|
* This program is distributed in the hope that it will be useful,
|
10 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
|
|
* GNU General Public License for more details.
|
13 |
|
|
*
|
14 |
|
|
* You should have received a copy of the GNU General Public License
|
15 |
|
|
* along with this program; if not, write to the
|
16 |
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
17 |
|
|
* Boston, MA 02110-1301, USA.
|
18 |
|
|
*/
|
19 |
|
|
|
20 |
|
|
#include <stdarg.h>
|
21 |
|
|
#include <stdio.h>
|
22 |
|
|
#include <string.h>
|
23 |
|
|
#include <stdlib.h>
|
24 |
|
|
#ifndef _MSC_VER
|
25 |
|
|
#include <sys/time.h>
|
26 |
|
|
#endif /* _MSC_VER */
|
27 |
|
|
#include "profile.h"
|
28 |
|
|
#include "debug.h"
|
29 |
|
|
|
30 |
|
|
void
|
31 |
|
|
profile_timer(int level, const char *module, const char *function, const char *fmt, ...)
|
32 |
|
|
{
|
33 |
|
|
#ifndef _MSC_VER
|
34 |
|
|
va_list ap;
|
35 |
|
|
static struct timeval last[10];
|
36 |
|
|
struct timeval curr;
|
37 |
|
|
int msec,usec;
|
38 |
|
|
char buffer[strlen(module)+20];
|
39 |
|
|
|
40 |
|
|
va_start(ap, fmt);
|
41 |
|
|
if (level < 0)
|
42 |
|
|
level=0;
|
43 |
|
|
if (level > 9)
|
44 |
|
|
level=9;
|
45 |
|
|
if (fmt) {
|
46 |
|
|
gettimeofday(&curr, NULL);
|
47 |
|
|
msec=(curr.tv_usec-last[level].tv_usec)/1000+
|
48 |
|
|
(curr.tv_sec-last[level].tv_sec)*1000;
|
49 |
|
|
|
50 |
|
|
sprintf(buffer, "profile:%s", module);
|
51 |
|
|
debug_vprintf(1, buffer, strlen(buffer), function, strlen(function), 1, fmt, ap);
|
52 |
|
|
if (msec >= 100)
|
53 |
|
|
debug_printf(1, buffer, strlen(buffer), function, strlen(function), 0, " %d msec\n", msec);
|
54 |
|
|
else {
|
55 |
|
|
usec=(curr.tv_usec-last[level].tv_usec)+(curr.tv_sec-last[level].tv_sec)*1000*1000;
|
56 |
|
|
debug_printf(1, buffer, strlen(buffer), function, strlen(function), 0, " %d.%d msec\n", usec/1000, usec%1000);
|
57 |
|
|
}
|
58 |
|
|
gettimeofday(&last[level], NULL);
|
59 |
|
|
} else {
|
60 |
|
|
gettimeofday(&curr, NULL);
|
61 |
|
|
while (level < 10)
|
62 |
|
|
last[level++]=curr;
|
63 |
|
|
}
|
64 |
|
|
va_end(ap);
|
65 |
|
|
#endif /*_MSC_VER*/
|
66 |
|
|
}
|