From 039ac92480a09266146fc5b0c9ec67a32a2565ad Mon Sep 17 00:00:00 2001 From: saurabhb17 Date: Wed, 26 Feb 2020 16:04:40 +0530 Subject: Added secondary files --- include/profile.h | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 include/profile.h (limited to 'include/profile.h') 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 + * + * 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 +#include + +/** + * 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 -- cgit