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, see <https://www.gnu.org/licenses/>.
19 */
20
21
22#include <config.h>
23#include <cstdint>
24#include <string>
25#include <sstream>
26#include <core/profile.h>
27
28#if defined( _WIN32 )
29
30#include <windows.h>
31
32int64_t GetRunningMicroSecs()
33{
34 FILETIME now;
35
36 GetSystemTimeAsFileTime( &now );
37 uint64_t t = ( UINT64( now.dwHighDateTime ) << 32 ) + now.dwLowDateTime;
38 t /= 10;
39
40 return int64_t( t );
41}
42
43#elif defined( HAVE_CLOCK_GETTIME )
44
45#include <ctime>
46
47int64_t GetRunningMicroSecs()
48{
49 struct timespec now;
50
51 clock_gettime( CLOCK_MONOTONIC, &now );
52
53 int64_t usecs = (int64_t) now.tv_sec * 1000000 + now.tv_nsec / 1000;
54 // unsigned msecs = (now.tv_nsec / (1000*1000)) + now.tv_sec * 1000;
55
56 return usecs;
57}
58
59
60#elif defined( HAVE_GETTIMEOFDAY_FUNC )
61
62#include <sys/time.h>
63int64_t GetRunningMicroSecs()
64{
65 timeval tv;
66
67 gettimeofday( &tv, 0 );
68
69 return (int64_t) tv.tv_sec * 1000000 + tv.tv_usec;
70}
71
72#endif
73
74
76{
77 std::stringstream ss;
78 TIME_POINT prev = m_start;
79 ss << "Probe stats for" << m_name << std::endl;
80 for (auto cp : m_checkpoints)
81 {
82 if( cp.isTimer )
83 ss << "tmr: " << std::left << std::setw(30) << cp.name << std::fixed << std::setprecision(3) << cp.timerDelta << std::endl;
84 else
85 {
86 ss << "chp: "<< std::left << std::setw(30) << cp.name;
87 ss << "since last : " << std::fixed << std::setprecision(3) << delta_ms( cp.timestamp, prev ) << " ";
88 ss << "accumulated: " << std::fixed << std::setprecision(3) << delta_ms( cp.timestamp, m_start ) << std::endl;
89
90 prev = cp.timestamp;
91 }
92 }
93
94 return ss.str();
95}
96
std::string to_string()
Definition profile.cpp:75
TIME_POINT m_start
Definition profile.h:351
std::vector< CHECKPOINT > m_checkpoints
Definition profile.h:353
double delta_ms(TIME_POINT a, TIME_POINT b)
Definition profile.h:343
std::chrono::time_point< CLOCK > TIME_POINT
Definition profile.h:302
std::string m_name
Definition profile.h:352
#define UINT64
int64_t GetRunningMicroSecs()
An alternate way to calculate an elapsed time (in microsecondes) to class PROF_COUNTER.