diff options
author | saurabhb17 | 2020-02-26 16:20:48 +0530 |
---|---|---|
committer | GitHub | 2020-02-26 16:20:48 +0530 |
commit | b77f5d9d8097c38159c6f60917995d6af13bbe1c (patch) | |
tree | 1392c90227aeea231c1d86371131e04c40382918 /include/profile.h | |
parent | dadc4d490966a24efe15b5cc533ef8695986048a (diff) | |
parent | 003d02608917e7a69d1a98438837e94ccf68352a (diff) | |
download | KiCad-eSim-b77f5d9d8097c38159c6f60917995d6af13bbe1c.tar.gz KiCad-eSim-b77f5d9d8097c38159c6f60917995d6af13bbe1c.tar.bz2 KiCad-eSim-b77f5d9d8097c38159c6f60917995d6af13bbe1c.zip |
Merge pull request #4 from FOSSEE/develop
merging dev into master
Diffstat (limited to 'include/profile.h')
-rw-r--r-- | include/profile.h | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/include/profile.h b/include/profile.h new file mode 100644 index 0000000..acf9166 --- /dev/null +++ b/include/profile.h @@ -0,0 +1,90 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013 CERN + * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/** + * @file profile.h: + * @brief Simple profiling functions for measuring code execution time. + */ + +#ifndef __TPROFILE_H +#define __TPROFILE_H + +#include <sys/time.h> +#include <stdint.h> + +/** + * Function get_tics + * Returns the number of microseconds that have elapsed since the system was started. + * @return uint64_t Number of microseconds. + */ +static inline uint64_t get_tics() +{ + struct timeval tv; + gettimeofday( &tv, NULL ); + + return (uint64_t) tv.tv_sec * 1000000ULL + (uint64_t) tv.tv_usec; +} + +/** + * Structure for storing data related to profiling counters. + */ +struct prof_counter +{ + uint64_t start, end; // Stored timer value + + uint64_t usecs() const + { + return end - start; + } + + float msecs() const + { + return ( end - start ) / 1000.0; + } +}; + +/** + * Function prof_start + * Begins code execution time counting for a given profiling counter. + * @param aCnt is the counter which should be started. + * use_rdtsc tells if processor's time-stamp counter should be used for time counting. + * Otherwise is system tics method will be used. IMPORTANT: time-stamp counter should not + * be used on multicore machines executing threaded code. + */ +static inline void prof_start( prof_counter* aCnt ) +{ + aCnt->start = get_tics(); +} + +/** + * Function prof_stop + * Ends code execution time counting for a given profiling counter. + * @param aCnt is the counter which should be stopped. + */ +static inline void prof_end( prof_counter* aCnt ) +{ + aCnt->end = get_tics(); +} + +#endif |