Commit 06f4662e authored by Maciej Suminski's avatar Maciej Suminski

Profile counter simplified, so it should be more portable.

parent 251f0c7f
...@@ -189,7 +189,7 @@ void GPU_CACHED_MANAGER::uploadToGpu() ...@@ -189,7 +189,7 @@ void GPU_CACHED_MANAGER::uploadToGpu()
{ {
#ifdef __WXDEBUG__ #ifdef __WXDEBUG__
prof_counter totalTime; prof_counter totalTime;
prof_start( &totalTime, false ); prof_start( &totalTime );
#endif /* __WXDEBUG__ */ #endif /* __WXDEBUG__ */
if( !m_buffersInitialized ) if( !m_buffersInitialized )
...@@ -214,8 +214,7 @@ void GPU_CACHED_MANAGER::uploadToGpu() ...@@ -214,8 +214,7 @@ void GPU_CACHED_MANAGER::uploadToGpu()
#ifdef __WXDEBUG__ #ifdef __WXDEBUG__
prof_end( &totalTime ); prof_end( &totalTime );
wxLogDebug( wxT( "Uploading %d vertices to GPU / %.1f ms" ), wxLogDebug( wxT( "Uploading %d vertices to GPU / %.1f ms" ), bufferSize, totalTime.msecs() );
bufferSize, (double) totalTime.value / 1000.0 );
#endif /* __WXDEBUG__ */ #endif /* __WXDEBUG__ */
} }
......
/*
* 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 rdtsc
* Returns processor's time-stamp counter. Main purpose is precise time measuring of code
* execution time.
* @return unsigned long long - Value of time-stamp counter.
*/
#if defined(__i386__)
static __inline__ unsigned long long rdtsc()
{
unsigned long long int x;
__asm__ volatile ( ".byte 0x0f, 0x31" : "=A" ( x ) );
return x;
}
#elif defined(__x86_64__)
static __inline__ unsigned long long rdtsc()
{
unsigned hi, lo;
__asm__ __volatile__ ( "rdtsc" : "=a" ( lo ), "=d" ( hi ) );
return ( (unsigned long long) lo ) | ( ( (unsigned long long) hi ) << 32 );
}
#elif defined(__powerpc__)
static __inline__ unsigned long long rdtsc()
{
unsigned long long int result = 0;
unsigned long int upper, lower, tmp;
__asm__ volatile (
"0: \n"
"\tmftbu %0 \n"
"\tmftb %1 \n"
"\tmftbu %2 \n"
"\tcmpw %2,%0 \n"
"\tbne 0b \n"
: "=r" ( upper ), "=r" ( lower ), "=r" ( tmp )
);
result = upper;
result = result << 32;
result = result | lower;
return result;
}
#endif /* __powerpc__ */
// Fixme: OS X version
/**
* 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 value; /// Stored timer value
bool use_rdtsc; /// Method of time measuring (rdtsc or tics)
};
/**
* Function prof_start
* Begins code execution time counting for a given profiling counter.
* @param cnt is the counter which should be started.
* @param 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* cnt, bool use_rdtsc )
{
cnt->use_rdtsc = use_rdtsc;
if( use_rdtsc )
{
cnt->value = rdtsc();
}
else
{
cnt->value = get_tics();
}
}
/**
* Function prof_stop
* Ends code execution time counting for a given profiling counter.
* @param cnt is the counter which should be stopped.
*/
static inline void prof_end( prof_counter* cnt )
{
if( cnt->use_rdtsc )
cnt->value = rdtsc() - cnt->value;
else
cnt->value = get_tics() - cnt->value;
}
#endif
...@@ -971,7 +971,7 @@ void VIEW::RecacheAllItems( bool aImmediately ) ...@@ -971,7 +971,7 @@ void VIEW::RecacheAllItems( bool aImmediately )
#ifdef __WXDEBUG__ #ifdef __WXDEBUG__
prof_counter totalRealTime; prof_counter totalRealTime;
prof_start( &totalRealTime, false ); prof_start( &totalRealTime );
#endif /* __WXDEBUG__ */ #endif /* __WXDEBUG__ */
for( LAYER_MAP_ITER i = m_layers.begin(); i != m_layers.end(); ++i ) for( LAYER_MAP_ITER i = m_layers.begin(); i != m_layers.end(); ++i )
...@@ -992,7 +992,7 @@ void VIEW::RecacheAllItems( bool aImmediately ) ...@@ -992,7 +992,7 @@ void VIEW::RecacheAllItems( bool aImmediately )
prof_end( &totalRealTime ); prof_end( &totalRealTime );
wxLogDebug( wxT( "RecacheAllItems::immediately: %u %.1f ms" ), wxLogDebug( wxT( "RecacheAllItems::immediately: %u %.1f ms" ),
aImmediately, (double) totalRealTime.value / 1000.0 ); aImmediately, totalRealTime.msecs() );
#endif /* __WXDEBUG__ */ #endif /* __WXDEBUG__ */
} }
......
...@@ -31,60 +31,9 @@ ...@@ -31,60 +31,9 @@
#define __TPROFILE_H #define __TPROFILE_H
#include <sys/time.h> #include <sys/time.h>
#include <string>
#include <stdint.h> #include <stdint.h>
/**
* Function rdtsc
* Returns processor's time-stamp counter. Main purpose is precise time measuring of code
* execution time.
* @return unsigned long long - Value of time-stamp counter.
*/
#if defined(__i386__)
static __inline__ unsigned long long rdtsc()
{
unsigned long long int x;
__asm__ volatile ( ".byte 0x0f, 0x31" : "=A" ( x ) );
return x;
}
#elif defined(__x86_64__)
static __inline__ unsigned long long rdtsc()
{
unsigned hi, lo;
__asm__ __volatile__ ( "rdtsc" : "=a" ( lo ), "=d" ( hi ) );
return ( (unsigned long long) lo ) | ( ( (unsigned long long) hi ) << 32 );
}
#elif defined(__powerpc__)
static __inline__ unsigned long long rdtsc()
{
unsigned long long int result = 0;
unsigned long int upper, lower, tmp;
__asm__ volatile (
"0: \n"
"\tmftbu %0 \n"
"\tmftb %1 \n"
"\tmftbu %2 \n"
"\tcmpw %2,%0 \n"
"\tbne 0b \n"
: "=r" ( upper ), "=r" ( lower ), "=r" ( tmp )
);
result = upper;
result = result << 32;
result = result | lower;
return result;
}
#endif /* __powerpc__ */
// Fixme: OS X version
/** /**
* Function get_tics * Function get_tics
* Returns the number of microseconds that have elapsed since the system was started. * Returns the number of microseconds that have elapsed since the system was started.
...@@ -98,14 +47,22 @@ static inline uint64_t get_tics() ...@@ -98,14 +47,22 @@ static inline uint64_t get_tics()
return (uint64_t) tv.tv_sec * 1000000ULL + (uint64_t) tv.tv_usec; return (uint64_t) tv.tv_sec * 1000000ULL + (uint64_t) tv.tv_usec;
} }
/** /**
* Structure for storing data related to profiling counters. * Structure for storing data related to profiling counters.
*/ */
struct prof_counter struct prof_counter
{ {
uint64_t value; /// Stored timer value uint64_t start, end; // Stored timer value
bool use_rdtsc; /// Method of time measuring (rdtsc or tics)
uint64_t usecs() const
{
return end - start;
}
float msecs() const
{
return ( end - start ) / 1000.0;
}
}; };
/** /**
...@@ -116,32 +73,19 @@ struct prof_counter ...@@ -116,32 +73,19 @@ struct prof_counter
* Otherwise is system tics method will be used. IMPORTANT: time-stamp counter should not * Otherwise is system tics method will be used. IMPORTANT: time-stamp counter should not
* be used on multicore machines executing threaded code. * be used on multicore machines executing threaded code.
*/ */
static inline void prof_start( prof_counter* cnt, bool use_rdtsc ) static inline void prof_start( prof_counter* aCnt )
{ {
cnt->use_rdtsc = use_rdtsc; aCnt->start = get_tics();
if( use_rdtsc )
{
cnt->value = rdtsc();
}
else
{
cnt->value = get_tics();
}
} }
/** /**
* Function prof_stop * Function prof_stop
* Ends code execution time counting for a given profiling counter. * Ends code execution time counting for a given profiling counter.
* @param cnt is the counter which should be stopped. * @param cnt is the counter which should be stopped.
*/ */
static inline void prof_end( prof_counter* cnt ) static inline void prof_end( prof_counter* aCnt )
{ {
if( cnt->use_rdtsc ) aCnt->end = get_tics();
cnt->value = rdtsc() - cnt->value;
else
cnt->value = get_tics() - cnt->value;
} }
#endif #endif
...@@ -343,11 +343,11 @@ PNS_SHOVE::ShoveStatus PNS_SHOVE::ShoveLines( PNS_LINE* aCurrentHead ) ...@@ -343,11 +343,11 @@ PNS_SHOVE::ShoveStatus PNS_SHOVE::ShoveLines( PNS_LINE* aCurrentHead )
PNS_LINE* currentLine = lineStack.top(); PNS_LINE* currentLine = lineStack.top();
prof_start( &totalRealTime, false ); prof_start( &totalRealTime );
nearest = node->NearestObstacle( currentLine, PNS_ITEM::ANY ); nearest = node->NearestObstacle( currentLine, PNS_ITEM::ANY );
prof_end( &totalRealTime ); prof_end( &totalRealTime );
TRACE( 2, "t-nearestObstacle %lld us", (totalRealTime.value ) ); TRACE( 2, "t-nearestObstacle %lld us", totalRealTime.usecs() );
if( !nearest ) if( !nearest )
{ {
...@@ -362,7 +362,7 @@ PNS_SHOVE::ShoveStatus PNS_SHOVE::ShoveLines( PNS_LINE* aCurrentHead ) ...@@ -362,7 +362,7 @@ PNS_SHOVE::ShoveStatus PNS_SHOVE::ShoveLines( PNS_LINE* aCurrentHead )
TRACE( 1, "Iter %d optimize-line [range %d-%d, total %d]", TRACE( 1, "Iter %d optimize-line [range %d-%d, total %d]",
iter % r_start % r_end % original->GetCLine().PointCount() ); iter % r_start % r_end % original->GetCLine().PointCount() );
// lastWalkSolid = NULL; // lastWalkSolid = NULL;
prof_start( &totalRealTime, false ); prof_start( &totalRealTime );
if( optimizer.Optimize( original, &optimized ) ) if( optimizer.Optimize( original, &optimized ) )
{ {
...@@ -376,7 +376,7 @@ PNS_SHOVE::ShoveStatus PNS_SHOVE::ShoveLines( PNS_LINE* aCurrentHead ) ...@@ -376,7 +376,7 @@ PNS_SHOVE::ShoveStatus PNS_SHOVE::ShoveLines( PNS_LINE* aCurrentHead )
prof_end( &totalRealTime ); prof_end( &totalRealTime );
TRACE( 2, "t-optimizeObstacle %lld us", (totalRealTime.value ) ); TRACE( 2, "t-optimizeObstacle %lld us", totalRealTime.usecs() );
} }
lineStack.pop(); lineStack.pop();
...@@ -393,12 +393,12 @@ PNS_SHOVE::ShoveStatus PNS_SHOVE::ShoveLines( PNS_LINE* aCurrentHead ) ...@@ -393,12 +393,12 @@ PNS_SHOVE::ShoveStatus PNS_SHOVE::ShoveLines( PNS_LINE* aCurrentHead )
PNS_LINE* collidingLine = node->AssembleLine( pseg ); PNS_LINE* collidingLine = node->AssembleLine( pseg );
PNS_LINE* shovedLine = collidingLine->CloneProperties(); PNS_LINE* shovedLine = collidingLine->CloneProperties();
prof_start( &totalRealTime, false ); prof_start( &totalRealTime );
ShoveStatus st = shoveSingleLine( node, currentLine, collidingLine, ShoveStatus st = shoveSingleLine( node, currentLine, collidingLine,
*pseg, shovedLine ); *pseg, shovedLine );
prof_end( &totalRealTime ); prof_end( &totalRealTime );
TRACE( 2, "t-shoveSingle %lld us", (totalRealTime.value ) ); TRACE( 2, "t-shoveSingle %lld us", totalRealTime.usecs() );
if( st == SH_OK ) if( st == SH_OK )
{ {
...@@ -441,11 +441,11 @@ PNS_SHOVE::ShoveStatus PNS_SHOVE::ShoveLines( PNS_LINE* aCurrentHead ) ...@@ -441,11 +441,11 @@ PNS_SHOVE::ShoveStatus PNS_SHOVE::ShoveLines( PNS_LINE* aCurrentHead )
walkaround.SetSolidsOnly( true ); walkaround.SetSolidsOnly( true );
walkaround.SetSingleDirection( true ); walkaround.SetSingleDirection( true );
prof_start( &totalRealTime, false ); prof_start( &totalRealTime );
walkaround.Route( *currentLine, *walkaroundLine, false ); walkaround.Route( *currentLine, *walkaroundLine, false );
prof_end( &totalRealTime ); prof_end( &totalRealTime );
TRACE( 2, "t-walkSolid %lld us", (totalRealTime.value ) ); TRACE( 2, "t-walkSolid %lld us", totalRealTime.usecs() );
node->Replace( currentLine, walkaroundLine ); node->Replace( currentLine, walkaroundLine );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment