question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add proper profiling methods.

See original GitHub issue

🐞 What bugs you? We currently do not have a proper methord for profiling of src code. It makes it difficult for newcomers to find the slow methods.

🎯 Goal

  1. This feature will help in finding slow methods. This can be used for solving #98 .
  2. Can be used to find slow functions for refinement of codebase.

💡 Possible solutions Use of cProfile in a creative way.

  • Comment below about what you’ve started working on.
  • Add, commit, push your changes
  • Submit a pull request and add this in comments - Addresses #<put issue number here>
  • Ask for a review in comments section of pull request
  • Celebrate your contribution to this project 🎉

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
YJDoc2commented, Sep 20, 2020

It would be along the lines of :

# file defining the decorator
import time
profile_data = dict()

def profile(fn):
     profile_data[fn.__name__] = list()
     if env_is_test:
          def wrapped(*args,**kwargs):
               start = time.time()
               ret = fn(args,kwargs)
               end = time.time()
               profile_data[fn.__name__].append(end-start)
               return ret
          return wrapped
     else :  # env is production
          return fn

def get_profile_data():
    # This will average each of the list and return the dict containing function name to average time dict
     .....

# in some other file, the function that is to be timed
@profile
def function_to_be_profiled():
     .....

One of the issues in this would be that time.time() returns system time, so if the python process is not scheduled for a long time , then the time reported by profile would be large, even though actual time taken by the function is small

This can be used as :

  1. Decorate all functions and keep them that way. as the decorators are evaluated at before actually running the code, there will not be any overhead at run time in production, as the function returned by the decorator is same
  2. Use the decorator as a tool in development to check the run-time, and remove after testing
1reaction
YJDoc2commented, Sep 19, 2020

Hello, Would it be a good idea to make a decorator which will time the functions in test mode and return same function in production mode, so that we can identify slow functions?

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Is Data Profiling? Process, Best Practices and Tools
Data profiling is the process of reviewing source data, understanding structure, content and interrelationships, and identifying potential for data projects ...
Read more >
10 Easy Steps to Creating a Customer Profile [+Templates]
1. Scorecard. This customer profile uses a scoring system to determine if a prospect is a right fit for the business. It assesses...
Read more >
Fundamentals of Performance Profiling - SmartBear
Profiling methods fall into two broad categories: Instrumenting and Sampling. Let's take a look at each. Instrumentation. Instrumenting profilers insert special ...
Read more >
Customer Profiling: The Ultimate Guide for 2023 [Updated]
Customer Profiling Methods​​ There are different ways to do customer profiling. Each refers to a certain segmentation: psychographics, buying traits, buying ...
Read more >
What Are the 3 Methods of Customer Profiling?
What Are the 3 Methods of Customer Profiling? · Understanding Customer Profiling · How Customer Profiling Is Done · Creating Your Customer Profiles....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found