Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Utils.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007-2008 Anael Orlinski
3 *
4 * This file is part of Panomatic.
5 *
6 * Panomatic is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * Panomatic is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Panomatic; if not, write to the Free Software
18 * <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef __utils_h
22 #define __utils_h
23 
24 #ifdef _WIN32
25 #include <vigra/windows.h>
26 #include <process.h>
27 #else
28 //#include <pthread.h>
29 #include <sys/time.h>
30 #endif
31 
32 #define TIMETRACE(TEXT, CODE) { std::ostringstream buf; utils::os_TIME t1,t2; utils::os_GetTime(&t1); CODE; \
33  utils::os_GetTime(&t2); buf << TEXT << " took " << utils::os_TimeDiff(&t2,&t1)/1000.0 << " seconds." << std::endl; std::cout << buf.str(); }
34 
35 
36 namespace utils
37 {
38 
39 //extern "C" {
40 
41 #ifdef _WIN32
42 typedef DWORD os_TIME;
43 #else
44 typedef struct timeval os_TIME;
45 #endif
46 
47 inline void os_GetTime(os_TIME* time)
48 {
49 #ifdef _WIN32
50  *time = GetTickCount();
51 #else
52  struct timezone tz;
53  gettimeofday(time, &tz);
54 #endif
55 }
56 
57 inline int os_TimeDiff(os_TIME* time1, os_TIME* time2)
58 {
59 #ifdef _WIN32
60  return *time1 - *time2;
61 #else
62  return (int)((double)time1->tv_sec*1000 + ((double)time1->tv_usec)*1e-3 -
63  (double)time2->tv_sec*1000 - ((double)time2->tv_usec)*1e-3);
64 #endif
65 }
66 
68 unsigned long long getTotalMemory();
70 unsigned int GetPhysicalCPUCount();
71 
72 }
73 
74 #endif // __utils_h
int os_TimeDiff(os_TIME *time1, os_TIME *time2)
Definition: Utils.h:57
struct timeval os_TIME
Definition: Utils.h:44
unsigned long long getTotalMemory()
returns the total memory in byte
Definition: Utils.cpp:65
unsigned int GetPhysicalCPUCount()
return the number of physical cpu cores
Definition: Utils.cpp:126
void os_GetTime(os_TIME *time)
Definition: Utils.h:47