Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Custom profiler
QtWS25 Last Chance

Custom profiler

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • QT-static-prgmQ Offline
    QT-static-prgmQ Offline
    QT-static-prgm
    wrote on last edited by
    #1

    Hi,

    When compiling this for release, all TIC and TOCs are ignored and completely removed from the code by the compiler right??

    #pragma once
    
    #ifdef _DEBUG
    	#include <QElapsedTimer.h>
    	#include <iostream>
    	#define TIC Profiler::getInstance().startTimer();
    	#define TOC Profiler::getInstance().takeTime();
    
    class Profiler
    {
    private:
    	Profiler() { timer.start(); };
    
    	QElapsedTimer timer;
    
    public:
    	~Profiler() {};
    
    	static Profiler& getInstance() {
    		static Profiler instance;
    		return instance;
    	}
    
    	void startTimer() {
    		timer.restart();
    	};
    
    	void takeTime() {
    		std::cout << "time elapsed: " << timer.elapsed() << std::endl;
    	};
    };
    
    #else
    	#define TIC
    	#define TOC
    #endif
    
    
    jsulmJ kshegunovK 2 Replies Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Yes if _DEBUG is set for debug and not release.

      1 Reply Last reply
      1
      • QT-static-prgmQ QT-static-prgm

        Hi,

        When compiling this for release, all TIC and TOCs are ignored and completely removed from the code by the compiler right??

        #pragma once
        
        #ifdef _DEBUG
        	#include <QElapsedTimer.h>
        	#include <iostream>
        	#define TIC Profiler::getInstance().startTimer();
        	#define TOC Profiler::getInstance().takeTime();
        
        class Profiler
        {
        private:
        	Profiler() { timer.start(); };
        
        	QElapsedTimer timer;
        
        public:
        	~Profiler() {};
        
        	static Profiler& getInstance() {
        		static Profiler instance;
        		return instance;
        	}
        
        	void startTimer() {
        		timer.restart();
        	};
        
        	void takeTime() {
        		std::cout << "time elapsed: " << timer.elapsed() << std::endl;
        	};
        };
        
        #else
        	#define TIC
        	#define TOC
        #endif
        
        
        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @QT-static-prgm You could answer this question by yourself by just trying it out...

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • QT-static-prgmQ Offline
          QT-static-prgmQ Offline
          QT-static-prgm
          wrote on last edited by
          #4

          @jsulm no since for release there is no console ;) and even if there is a console it may still have the code merged into the project and that'd be unused code.

          jsulmJ 1 Reply Last reply
          0
          • QT-static-prgmQ QT-static-prgm

            @jsulm no since for release there is no console ;) and even if there is a console it may still have the code merged into the project and that'd be unused code.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @QT-static-prgm What do you mean with "no console"? You can always print to console, even in release mode and even in a GUI application. Do you think if somebody in this forum says it is OK what you are doing there is no need to check to be sure?
            You can check generated binary using nm tool to see whether Profiler class is in or not.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • QT-static-prgmQ Offline
              QT-static-prgmQ Offline
              QT-static-prgm
              wrote on last edited by
              #6

              nm tool??

              mrjjM 1 Reply Last reply
              0
              • QT-static-prgmQ QT-static-prgm

                nm tool??

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @QT-static-prgm

                Its a linux tool
                http://www.thegeekstuff.com/2012/03/linux-nm-command/?utm_source=feedburner

                Listing symbols and other info

                1 Reply Last reply
                1
                • QT-static-prgmQ QT-static-prgm

                  Hi,

                  When compiling this for release, all TIC and TOCs are ignored and completely removed from the code by the compiler right??

                  #pragma once
                  
                  #ifdef _DEBUG
                  	#include <QElapsedTimer.h>
                  	#include <iostream>
                  	#define TIC Profiler::getInstance().startTimer();
                  	#define TOC Profiler::getInstance().takeTime();
                  
                  class Profiler
                  {
                  private:
                  	Profiler() { timer.start(); };
                  
                  	QElapsedTimer timer;
                  
                  public:
                  	~Profiler() {};
                  
                  	static Profiler& getInstance() {
                  		static Profiler instance;
                  		return instance;
                  	}
                  
                  	void startTimer() {
                  		timer.restart();
                  	};
                  
                  	void takeTime() {
                  		std::cout << "time elapsed: " << timer.elapsed() << std::endl;
                  	};
                  };
                  
                  #else
                  	#define TIC
                  	#define TOC
                  #endif
                  
                  
                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #8
                  1. You should use NDEBUG.
                  2. Or better yet just define your own debug macro for your project
                  3. Or better use one of the standard tools for profiling like callgrind
                  4. And why try to profile a debug build to begin with? This doesn't make much sense.

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  1

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved