- Timestamp:
- 05/22/15 13:25:59 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/profiler.cc
r365 r371 5 5 #include "nv/core/profiler.hh" 6 6 7 #include <iomanip>8 #include <ios>9 7 #include "nv/core/time.hh" 10 8 #include "nv/core/logging.hh" 9 #include <cstdio> 10 #include <cstdlib> 11 11 12 12 using namespace nv; 13 13 14 #ifdef NV_MSVC 15 #define snprintf sprintf_s 16 #endif 14 17 15 18 profiler::profiler() … … 25 28 } 26 29 27 void profiler::start_profile( const char*tag )30 void profiler::start_profile( const string_ref& tag ) 28 31 { 29 32 if ( tag != m_current->m_tag ) … … 42 45 } 43 46 44 profiler::node::node( const char* tag, node* parent )45 : m_tag( tag )47 profiler::node::node( const string_ref& tag, node* parent ) 48 : m_tag( tag.to_string() ) 46 49 , m_parent( parent ) 47 50 , m_recusion( 0 ) … … 53 56 } 54 57 55 profiler::node* profiler::node::request_child( const char*tag )58 profiler::node* profiler::node::request_child( const string_ref& tag ) 56 59 { 57 auto it = m_children.find( tag ); 60 std::string stag( tag.to_string() ); 61 auto it = m_children.find( stag ); 58 62 if ( it != m_children.end() ) 59 63 return it->second; … … 61 65 { 62 66 node* result = new node( tag, this ); 63 m_children[ tag ] = result;67 m_children[ stag ] = result; 64 68 return result; 65 69 } … … 101 105 { 102 106 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 ---------------------------------" ); 111 113 m_root->start(); 112 114 } 113 115 114 void profiler::log_node_children( const std::string& ind, const node* n )116 void profiler::log_node_children( uint32 indent, const node* n ) 115 117 { 118 char buffer[128]; 116 119 for ( const auto& pair : n->m_children ) 117 120 { … … 119 122 if ( c->m_calls > 0 ) 120 123 { 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 ) ) ); 127 132 if ( c->m_children.size() > 0 ) 128 133 { 129 log_node_children( ind + "-", c );134 log_node_children( indent + 1, c ); 130 135 } 131 136 }
Note: See TracChangeset
for help on using the changeset viewer.