Changeset 371 for trunk/src


Ignore:
Timestamp:
05/22/15 13:25:59 (10 years ago)
Author:
epyon
Message:
  • profiler - removed sstream dependency - formating via snprintf
  • profiler - string_refs where applicable (still need string for unordered_map)
  • logger - removed sstream support
  • logger - log_sequence instead of detail logger functions
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/profiler.cc

    r365 r371  
    55#include "nv/core/profiler.hh"
    66
    7 #include <iomanip>
    8 #include <ios>
    97#include "nv/core/time.hh"
    108#include "nv/core/logging.hh"
     9#include <cstdio>
     10#include <cstdlib>
    1111
    1212using namespace nv;
    1313
     14#ifdef NV_MSVC
     15#define snprintf sprintf_s
     16#endif
    1417
    1518profiler::profiler()
     
    2528}
    2629
    27 void profiler::start_profile( const char* tag )
     30void profiler::start_profile( const string_ref& tag )
    2831{
    2932        if ( tag != m_current->m_tag )
     
    4245}
    4346
    44 profiler::node::node( const char* tag, node* parent )
    45         : m_tag( tag )
     47profiler::node::node( const string_ref& tag, node* parent )
     48        : m_tag( tag.to_string() )
    4649        , m_parent( parent )
    4750        , m_recusion( 0 )
     
    5356}
    5457
    55 profiler::node* profiler::node::request_child( const char* tag )
     58profiler::node* profiler::node::request_child( const string_ref& tag )
    5659{
    57         auto it = m_children.find( tag );
     60        std::string stag( tag.to_string() );
     61        auto it = m_children.find( stag );
    5862        if ( it != m_children.end() )
    5963                return it->second;
     
    6165        {
    6266                node* result = new node( tag, this );
    63                 m_children[ tag ] = result;
     67                m_children[ stag ] = result;
    6468                return result;
    6569        }
     
    101105{
    102106        m_root->stop();
    103         NV_LOG_INFO( "-- PROFILER REPORT -----------------------------------------" );
    104         NV_LOG_STREAM( LOG_INFO, std::left << std::setw(24) << "TAG"
    105                 << std::setw(7) << "%PARNT"
    106                 << std::setw(7) << "CALLS"
    107                 << std::setw(10) << "TOTAL(ms)"
    108                 << std::setw(10) << "AVG(ms)" );
    109         log_node_children( "", m_root );
    110         NV_LOG_INFO( "-- PROFILER REPORT END -------------------------------------" );
     107        NV_LOG_INFO( "-- PROFILER REPORT -------------------------------------" );
     108        char buffer[128];
     109        snprintf( buffer, 128, "%-23s %6s %6s %9s %6s", "TAG", "%PARNT", "CALLS", "TOTAL(ms)", "AVG(ms)" );
     110        NV_LOG_INFO( string_ref( buffer, strlen(buffer) ) );
     111        log_node_children( 0, m_root );
     112        NV_LOG_INFO( "-- PROFILER REPORT END ---------------------------------" );
    111113        m_root->start();
    112114}
    113115
    114 void profiler::log_node_children( const std::string& ind, const node* n )
     116void profiler::log_node_children( uint32 indent, const node* n )
    115117{
     118        char buffer[128];
    116119        for ( const auto& pair : n->m_children )
    117120        {
     
    119122                if ( c->m_calls > 0 )
    120123                {
    121                         NV_LOG_STREAM( LOG_INFO, std::left << std::setw(24) << ind + c->m_tag
    122                                 << std::setw(7) << std::setprecision(2) << std::fixed << ( (double)c->m_total_time_us / (double)c->m_parent->m_total_time_us ) * 100.0
    123                                 << std::setw(7) << c->m_calls
    124                                 << std::setw(10) << std::setprecision(2) << std::fixed << c->m_total_time_us / 1000.f
    125                                 << std::setw(10) << std::setprecision(2) << std::fixed << ( (double)c->m_total_time_us / (double)c->m_calls ) / 1000.f
    126                                 );
     124                        double pparent  = ( (double)c->m_total_time_us / (double)c->m_parent->m_total_time_us ) * 100.f;
     125                        int calls       = c->m_calls;
     126                        double total_ms = c->m_total_time_us / 1000.f;
     127                        double avg_ms   = ( (double)c->m_total_time_us / (double)c->m_calls ) / 1000.f;
     128                        if ( indent > 0 ) memset( buffer, '-', indent );
     129                        snprintf( buffer + indent, 128 - indent, "%*.*s %6.2f %6d %9.2f %6.2f", indent - 23, 23 - indent,
     130                                c->m_tag.c_str(), pparent, calls, total_ms, avg_ms );
     131                        NV_LOG_INFO( string_ref( buffer, strlen( buffer ) ) );
    127132                        if ( c->m_children.size() > 0 )
    128133                        {
    129                                 log_node_children( ind + "-", c );
     134                                log_node_children( indent + 1, c );
    130135                        }
    131136                }
Note: See TracChangeset for help on using the changeset viewer.