Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. logging optimization.

logging optimization.

Scheduled Pinned Locked Moved C / C++ / MFC
c++algorithmsperformancequestionannouncement
5 Posts 3 Posters 0 Views 1 Watching
  • 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.
  • V Offline
    V Offline
    vikramlinux
    wrote on last edited by
    #1

    Hi Friends, My product has a feature of logging. Currently it is simple MACRO based where during release build compiler removes logging function calls. Now I am planning to make logging available during release build as well. As a result user will simply pass some command line parameter during process start and things will start logging. Now as logging code will be present in my binary during release time, this will enforce some types of checks even if the logging is not enabled which will lead to CPU cost. Is there any way to optimize these checks? Are there any way where I can bypass these checks during normal functional behavior. Assembly, C, C++ compiler/code specific suggestions are welcome. - Vikram S

    K N 2 Replies Last reply
    0
    • V vikramlinux

      Hi Friends, My product has a feature of logging. Currently it is simple MACRO based where during release build compiler removes logging function calls. Now I am planning to make logging available during release build as well. As a result user will simply pass some command line parameter during process start and things will start logging. Now as logging code will be present in my binary during release time, this will enforce some types of checks even if the logging is not enabled which will lead to CPU cost. Is there any way to optimize these checks? Are there any way where I can bypass these checks during normal functional behavior. Assembly, C, C++ compiler/code specific suggestions are welcome. - Vikram S

      K Offline
      K Offline
      KarstenK
      wrote on last edited by
      #2

      If you write some generic logging function the type checking overhead is minimized. I use a global logging file, so there isnt a lot of stuff to do. Be careful if you do logging and multithreading!!

      Greetings from Germany

      1 Reply Last reply
      0
      • V vikramlinux

        Hi Friends, My product has a feature of logging. Currently it is simple MACRO based where during release build compiler removes logging function calls. Now I am planning to make logging available during release build as well. As a result user will simply pass some command line parameter during process start and things will start logging. Now as logging code will be present in my binary during release time, this will enforce some types of checks even if the logging is not enabled which will lead to CPU cost. Is there any way to optimize these checks? Are there any way where I can bypass these checks during normal functional behavior. Assembly, C, C++ compiler/code specific suggestions are welcome. - Vikram S

        N Offline
        N Offline
        Nishad S
        wrote on last edited by
        #3

        vikrams wrote:

        Now as logging code will be present in my binary during release time, this will enforce some types of checks even if the logging is not enabled which will lead to CPU cost.

        You mean you cant even check like this too? if( bLogEnabled ) { // code for logging... }

        - ns ami -

        V 1 Reply Last reply
        0
        • N Nishad S

          vikrams wrote:

          Now as logging code will be present in my binary during release time, this will enforce some types of checks even if the logging is not enabled which will lead to CPU cost.

          You mean you cant even check like this too? if( bLogEnabled ) { // code for logging... }

          - ns ami -

          V Offline
          V Offline
          vikramlinux
          wrote on last edited by
          #4

          I can do this. But When there are hundreds of checks at runtime, will this be not an issue? - Vikram S

          N 1 Reply Last reply
          0
          • V vikramlinux

            I can do this. But When there are hundreds of checks at runtime, will this be not an issue? - Vikram S

            N Offline
            N Offline
            Nishad S
            wrote on last edited by
            #5

            AFAIK, this 'if' check will not bring any noticable change in the performance. I know even more complex logging mechanisms are used in professional softwares. Also you can avoid logs (if that much necessary) in some extremely performance oriented functions. Note: You may simplyfy the code (only look) using by using macros, so that repeated if blocks can be avoided. Eg.

            #define LOG(x) if( bLogEnabled ) { LogString( x ); }

            - ns ami -

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups