• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            歲月流轉(zhuǎn),往昔空明

            C++博客 首頁 新隨筆 聯(lián)系 聚合 管理
              118 Posts :: 3 Stories :: 413 Comments :: 0 Trackbacks

             

            struct Timer{
                
            void GetTime(__int64* ptime)
                
            {
                    
            //QueryPerformanceCounter((LARGE_INTEGER*)ptime);
                    __asm
                    
            {
                        push edx;
                        push ecx;
                        mov ecx,ptime;
                        rdtsc
                            mov [ecx],eax;
                        mov [ecx
            +4],edx;
                        pop ecx;
                        pop edx;
                    }

                }

            }
            ;

            Timer g_timer;

            struct ProfilerSample
            {
                __int64 begin;
                __int64 end;
                __int64 count;
                __int64 total;

                ProfilerSample() : begin(
            0), end(0), count(0), total(0)
                
            {}

                
            void Reset() {
                    begin 
            = end = count = total = 0;
                }


                
            void Begin() {
                    g_timer.GetTime(
            &begin);
                }


                
            void End() {
                    g_timer.GetTime(
            &end);
                    total 
            += (end - begin);
                }

            }
            ;

            class ProfilerNode
            {
            public:
                ProfilerNode
            * m_parent;
                ProfilerNode
            * m_son;
                ProfilerNode
            * m_sibling;

                
            const char* m_profName;

                ProfilerSample m_sample;

            public:
                ProfilerNode(
            const char* name, ProfilerNode* parent);
                
            ~ProfilerNode();

                
            void Begin();
                
            void End();

                
            const char* GetName();
                
            const ProfilerSample* GetProfSample();

                ProfilerNode
            * GetSon(const char* str);
                ProfilerNode
            * GetDirectSon();
                ProfilerNode
            * GetNextSibling();
                ProfilerNode
            * GetParent();
            }
            ;

            ProfilerNode::ProfilerNode(
            const char* name, ProfilerNode* parent)
                : m_profName(name), m_parent(parent), m_son(NULL), m_sibling(NULL)
            {
            }


            ProfilerNode::
            ~ProfilerNode()
            {
                delete m_son;
                delete m_sibling;
            }


            const char* ProfilerNode::GetName()
            {
                
            return m_profName;
            }


            const ProfilerSample* ProfilerNode::GetProfSample()
            {
                
            return &m_sample;
            }


            //獲取一個兒子
            ProfilerNode* ProfilerNode::GetSon(const char* str)
            {
                ProfilerNode
            * p = m_son;

                
            while(p != NULL) {
                    
            if(p->m_profName == str) {
                        
            break;
                    }

                    p 
            = p->GetNextSibling();
                }


                
            if(p == NULL)
                
            {
                    p 
            = new ProfilerNode(str, this);
                    p
            ->m_sibling = m_son;
                    m_son 
            = p;
                }


                
            return p;
            }


            //獲取一個兒子
            ProfilerNode* ProfilerNode::GetDirectSon()
            {
                
            return m_son;
            }


            ProfilerNode
            * ProfilerNode::GetNextSibling()
            {
                
            return m_sibling;
            }


            ProfilerNode
            * ProfilerNode::GetParent()
            {
                
            return m_parent;
            }


            void ProfilerNode::Begin()
            {
                m_sample.Begin();
            }


            void ProfilerNode::End()
            {
                m_sample.End();
            }


            //性能分析管理器
            //注意初始化順序!
            class ProfilerManager
            {
            private:
                ProfilerManager() : root(
            "root", NULL), m_curProfNode(&root){}
                ProfilerManager(
            const ProfilerManager& rhs);
                ProfilerManager
            &  operator = (const ProfilerManager& rhs);

                
            static ProfilerManager s_profmgr;

            private:
                ProfilerNode root;
                ProfilerNode
            * m_curProfNode;

            public:
                
            static ProfilerManager& Instance() {
                    
            return s_profmgr;
                }


                
            void BeginProfiler(const char* name);
                
            void EndProfiler();

                ProfilerNode
            * GetRootProfilerNode() {
                    
            return &root;
                }

            }
            ;

            ProfilerManager ProfilerManager::s_profmgr;

            void ProfilerManager::BeginProfiler(const char* name)
            {
                m_curProfNode 
            = m_curProfNode->GetSon(name);
                m_curProfNode
            ->Begin();
            }


            void ProfilerManager::EndProfiler()
            {
                m_curProfNode
            ->End();
                m_curProfNode 
            = m_curProfNode->GetParent();
            }


            class Profiler
            {
            public:
                Profiler(
            const char* name)
                
            {
                    ProfilerManager::Instance().BeginProfiler(name);
                }

                
            ~Profiler()
                
            {
                    ProfilerManager::Instance().EndProfiler();
                }

            }
            ;

            #define BEGIN_PROF(name) ProfilerManager::Instance().BeginProfiler(name);
            #define END_PROF(name) ProfilerManager::Instance().EndProfiler();

            LARGE_INTEGER j;

            void OutputProf(ProfilerNode* p, int space = 0)
            {
                ProfilerNode
            * tmp;

                
            const ProfilerSample* ps = p->GetProfSample();
                
            for(int i = 0; i < space; ++i) {
                    cout 
            << " ";
                }

                cout 
            << p->GetName() << ": 調(diào)用次數(shù): " << ps->count << " 調(diào)用總耗時: " << ps->total << endl;

                
            if(tmp = p->GetDirectSon()) {
                    OutputProf(tmp, space
            +1);
                }
             else {
                    
            if(tmp = p->GetNextSibling()) {
                        OutputProf(tmp, space);
                    }

                }

            }
            posted on 2005-11-30 11:32 空明流轉(zhuǎn) 閱讀(1500) 評論(0)  編輯 收藏 引用

            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            久久久久久精品久久久久| 精品国产一区二区三区久久| 深夜久久AAAAA级毛片免费看| 久久久久久青草大香综合精品| 午夜精品久久久久9999高清| 伊人久久一区二区三区无码| 久久精品天天中文字幕人妻| 精品久久久久中文字| 久久亚洲AV成人无码软件| 精品久久一区二区| 久久只这里是精品66| 99久久精品国内| 久久婷婷五月综合国产尤物app| 国产精品美女久久久m| 欧美精品九九99久久在观看| 国产精品久久久久影院嫩草| 久久99九九国产免费看小说| 国产91久久精品一区二区| 少妇无套内谢久久久久| 91精品免费久久久久久久久| 日产精品99久久久久久| 亚洲欧美日韩精品久久亚洲区| 91精品国产高清久久久久久io| 亚洲欧美成人久久综合中文网 | 韩国三级中文字幕hd久久精品| 国产精品久久久久久五月尺| 久久国产成人午夜aⅴ影院| 狠狠色丁香婷婷久久综合不卡| 色老头网站久久网| 久久99热这里只频精品6| 色婷婷久久久SWAG精品| 国产亚洲精午夜久久久久久| 亚洲天堂久久精品| 蜜桃麻豆www久久| 亚洲国产精品久久66| 狠狠人妻久久久久久综合蜜桃| 亚洲欧美日韩精品久久| 久久99精品久久久久久野外| 久久国产精品免费一区| 久久久久久国产a免费观看黄色大片| 亚洲国产成人久久一区久久|