KiCad PCB EDA Suite
Loading...
Searching...
No Matches
profile.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25
26#include <config.h>
27#include <cstdint>
28#include <string>
29#include <sstream>
30#include <core/profile.h>
31
32#if defined( _WIN32 )
33
34#include <windows.h>
35
36int64_t GetRunningMicroSecs()
37{
38 FILETIME now;
39
40 GetSystemTimeAsFileTime( &now );
41 uint64_t t = ( UINT64( now.dwHighDateTime ) << 32 ) + now.dwLowDateTime;
42 t /= 10;
43
44 return int64_t( t );
45}
46
47#elif defined( HAVE_CLOCK_GETTIME )
48
49#include <ctime>
50
51int64_t GetRunningMicroSecs()
52{
53 struct timespec now;
54
55 clock_gettime( CLOCK_MONOTONIC, &now );
56
57 int64_t usecs = (int64_t) now.tv_sec * 1000000 + now.tv_nsec / 1000;
58 // unsigned msecs = (now.tv_nsec / (1000*1000)) + now.tv_sec * 1000;
59
60 return usecs;
61}
62
63
64#elif defined( HAVE_GETTIMEOFDAY_FUNC )
65
66#include <sys/time.h>
67int64_t GetRunningMicroSecs()
68{
69 timeval tv;
70
71 gettimeofday( &tv, 0 );
72
73 return (int64_t) tv.tv_sec * 1000000 + tv.tv_usec;
74}
75
76#endif
77
78
80{
81 std::stringstream ss;
82 TIME_POINT prev = m_start;
83 ss << "Probe stats for" << m_name << std::endl;
84 for (auto cp : m_checkpoints)
85 {
86 if( cp.isTimer )
87 ss << "tmr: " << std::left << std::setw(30) << cp.name << std::fixed << std::setprecision(3) << cp.timerDelta << std::endl;
88 else
89 {
90 ss << "chp: "<< std::left << std::setw(30) << cp.name;
91 ss << "since last : " << std::fixed << std::setprecision(3) << delta_ms( cp.timestamp, prev ) << " ";
92 ss << "accumulated: " << std::fixed << std::setprecision(3) << delta_ms( cp.timestamp, m_start ) << std::endl;
93
94 prev = cp.timestamp;
95 }
96 }
97
98 return ss.str();
99}
100
std::string to_string()
Definition profile.cpp:79
TIME_POINT m_start
Definition profile.h:355
std::vector< CHECKPOINT > m_checkpoints
Definition profile.h:357
double delta_ms(TIME_POINT a, TIME_POINT b)
Definition profile.h:347
std::chrono::time_point< CLOCK > TIME_POINT
Definition profile.h:306
std::string m_name
Definition profile.h:356
#define UINT64
int64_t GetRunningMicroSecs()
An alternate way to calculate an elapsed time (in microsecondes) to class PROF_COUNTER.