Thursday, 4 May 2017

django debug toolbar - improve application performance

django debug toolbar
django debug toolbar

debugging:

  • It is the process of locating and correcting the errors in a computer program or code.
  • debugging is an integral part of software testing.
  • debugging improves  code quality and eases the maintainability of a software.

 debugging tool:

  • A debugging tool is comprised of one or more computer programs that are  used to locate the errors in other programs.

django debug toolbar: 

  • It is one of the best debugging tools for the django applications.
  • debug toolbar makes developer life simple. Developer need not to worry about common lookups like settings, request data, etc.
  • By using this tool we can quickly find out the error location. It helps developers to keep headache away.

tools provided by debug toolbar: 

  • versions:

    • It provides the information of packages that are used in our django application.
    • It lists out package, package name and package version.
    • In some cases we need to have a specific version of a package but we may use advanced version of the package. We may get errors  by using toolbar we can quickly have a look on it. 
    • example: wee need djcelery==2.9.1 but we used djcelery==3.2.1
     
  • time:

    • It helps to use our system resources(CPU) effectively.
    • It lists out the time used by each resource(user CPU time, System CPU time, etc) in milli seconds.
    • It also provides the timing browser when our web page is loaded.
    • It provides the time information like domain lookup, connect, request, response, DOM loading, DOM ContentLoadedEvent, load event.
     
  • Settings:

    • It quickly lists out  our django project settings in a tabular format.
    • We need not go to the ide/editor to see project settings.
  • Headers: 

    • It summaries the information of  HTTP request.
    • It provides information of headers sent in the HTTP request as well as  headers received in the HTTP response.
    • In some cases we need to send authentication information like tokens in HTTP request headers.
    • It helps us to check whether we sent authentication token in headers or not.
  • Request:

    • It contains the information of view, session data, cookies, GET data, POST data
    •  By using this we can quickly navigate to the respective view
    • And also can be able to see data handled by the request
  • SQL:

    • It shows the number of queries executed on a page and time taken each query in milliseconds.
    • It also shows the django equivalent of raw SQL.
    • Reduce the number of queries to improve the application performance.
  • Static files:

    • It lists the static files and paths of static files for quick navigation. 
  • Templates: 

    • It shows template directory paths
    • It  also lists out the templates used in creating the response.
    • It helps us for quick navigation to a template.
  • Cache: 

    • It summaries the  cache of our django application
  • Signals: 

    • It lists out the signals and receivers used in the page rendering.
    • It helps if we write custom signals or receivers.
       
  • Logging: 

    • It shows  logging messages information

How to use django debug toolbar ?

add the below code at the end of the settings file.
settings.py
if DEBUG:
    MIDDLEWARE_CLASSES = MIDDLEWARE_CLASSES + [
        'debug_toolbar.middleware.DebugToolbarMiddleware',
    ]
    INSTALLED_APPS = INSTALLED_APPS + [
        'debug_toolbar',
    ]
    INTERNAL_IPS = ('127.0.0.1', )
    DEBUG_TOOLBAR_CONFIG = {
        'INTERCEPT_REDIRECTS': False,
    }
add the below code at the end of the project urls file. 
urls.py 
if settings.DEBUG:
    import debug_toolbar
    urlpatterns += [
        url(r'^__debug__/', include(debug_toolbar.urls)),
    ]


EmoticonEmoticon