Changeset 409


Ignore:
Timestamp:
06/21/15 02:44:51 (10 years ago)
Author:
epyon
Message:
  • core/profiler uses new literal_map
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/core/profiler.hh

    r399 r409  
    1717#include <nv/stl/singleton.hh>
    1818#include <nv/stl/string.hh>
    19 #include <nv/stl/unordered_map.hh>
     19#include <nv/stl/string_map.hh>
    2020
    2121#if NV_PROFILER
    22 #define NV_PROFILE( tag ) nv::profiler_guard __profile( tag )
    23 #define NV_PROFILE_IF( tag, condition ) nv::profiler_condition_guard __profile( tag, condition )
     22#define NV_PROFILE( tag ) nv::profiler_guard __profile( tag##_hls64 )
     23#define NV_PROFILE_IF( tag, condition ) nv::profiler_condition_guard __profile( tag##_hls64, condition )
    2424#else
    2525#define NV_PROFILE( tag )
     
    3333        {
    3434        protected:
     35                typedef hashed_literal_string_64 string_type;
     36
    3537                class node
    3638                {
     39                        friend class profiler;
    3740                public:
    38                         friend class profiler;
     41                        ~node();
     42                protected:
     43                        node( string_view tag, node* parent );
    3944                        node* get_parent() { return m_parent; }
    40                         node* get_child( const std::string& tag )
    41                         {
    42                                 auto it = m_children.find( tag );
    43                                 return ( it != m_children.end() ) ? it->second : nullptr;
    44                         }
    45                 protected:
    46                         node( const string_view& tag, node* parent );
    47                         node* request_child( const string_view& tag );
     45                        node* request_child( string_type&& tag );
    4846                        void start();
    4947                        bool stop();
    50                         ~node();
    51                 protected:
    52                         typedef unordered_map< std::string, node* > map;
    5348
    54                         std::string m_tag;
     49                        typedef literal_map< node* > map;
     50
     51                        string_view m_tag;
    5552                        map         m_children;
    5653                        node*       m_parent;
     
    6663                ~profiler();
    6764
    68                 void start_profile( const string_view& tag );
     65                void start_profile( string_type&& tag );
    6966                void stop_profile();
    7067        public:
     
    8279        {
    8380        public:
    84                 profiler_guard( string_view tag )
     81                profiler_guard( hashed_literal_string_64&& tag )
    8582                {
    86                         profiler::pointer()->start_profile( tag );
     83                        profiler::pointer()->start_profile( ::nv::move( tag ) );
    8784                }
    8885
     
    9693        {
    9794        public:
    98                 profiler_condition_guard( string_view tag, bool condition )
     95                profiler_condition_guard( hashed_literal_string_64&& tag, bool condition )
    9996                        : m_active( condition )
    10097                {
    101                         if ( m_active ) profiler::pointer()->start_profile( tag );
     98                        if ( m_active ) profiler::pointer()->start_profile( ::nv::move( tag ) );
    10299                }
    103100
  • trunk/src/core/profiler.cc

    r402 r409  
    2020profiler::profiler()
    2121{
    22         m_root = new node( "root", nullptr );
     22        m_root = new node( "root"_hls64, nullptr );
    2323        m_root->start();
    2424        m_current = m_root;
     
    3030}
    3131
    32 void profiler::start_profile( const string_view& tag )
     32void profiler::start_profile( string_type&& tag )
    3333{
    3434        if ( tag != m_current->m_tag )
    3535        {
    36                 m_current = m_current->request_child( tag );
     36                m_current = m_current->request_child( ::nv::move( tag ) );
    3737        }
    3838        m_current->start();
     
    4747}
    4848
    49 profiler::node::node( const string_view& tag, node* parent )
    50         : m_tag( tag.to_string() )
     49profiler::node::node( string_view tag, node* parent )
     50        : m_tag( ::nv::move( tag ) )
    5151        , m_parent( parent )
    5252        , m_recusion( 0 )
     
    5858}
    5959
    60 profiler::node* profiler::node::request_child( const string_view& tag )
     60profiler::node* profiler::node::request_child( string_type&& tag )
    6161{
    62         std::string stag( tag.to_string() );
    63         auto it = m_children.find( stag );
     62        auto it = m_children.find( tag );
    6463        if ( it != m_children.end() )
    6564                return it->second;
     
    6766        {
    6867                node* result = new node( tag, this );
    69                 m_children[ stag ] = result;
     68                m_children.assign( ::nv::move( tag ), result );
    7069                return result;
    7170        }
     
    131130                        if ( indent > 0 ) nvmemset( buffer, '-', indent );
    132131                        snprintf( buffer + indent, 128 - indent, "%*.*s %6.2f %6d %9.2f %6.2f", indent - 23, 23 - indent,
    133                                 c->m_tag.c_str(), pparent, calls, total_ms, avg_ms );
     132                                c->m_tag.data(), pparent, calls, total_ms, avg_ms );
    134133                        NV_LOG_INFO( string_view( buffer, nvstrlen( buffer ) ) );
    135134                        if ( c->m_children.size() > 0 )
Note: See TracChangeset for help on using the changeset viewer.