GithubHelp home page GithubHelp logo

func_stats's Introduction

func_stats

使用表格方式显示函数调用统计, 实现的原理很简单就是通过inspect来打印调用栈. 对于模块调用方面没有使用装饰器来实现函数的统计,而是创建pointer的来实现, 这样更加的方便使用.

这样最大的好处是不管在哪个上下文,你只要复用你定制的pointer就可以增加统计。

注意:

整个项目里就一个依赖外部的模块, prettytable.py , 索性直接把该模块引入到项目中.

For test

#!/usr/bin/env python
# -*- coding:utf-8 -*-
import time

from func_stats.func_stats import CreateStats
b = CreateStats()

b.point("once counter")

for i in range(1,5):
    b.point("loop counter")

b.point("t1 complated")

for i in range(10):
    b.point('sleep counter')
    time.sleep(0.1)

b.point("t1 complated")

b.display()

Result:

+---------------+------+------+----------+---------+---------+
| Point         | Line | count| Avg Time | Runtime | Percent |
+---------------+------+------+----------+---------+---------+
| once counter  |    8 |    1 |  0.00001 | 0.00001 |    0.00 |
| loop counter  |   11 |    4 |  0.00000 | 0.00001 |    0.00 |
| t1 complated  |   19 |    2 |  0.05046 | 0.10091 |    9.90 |
| sleep counter |   16 |   10 |  0.09184 | 0.91837 |   90.07 |
+---------------+------+------+----------+---------+---------+
Total runtime: 1.02

func_stats's People

Contributors

rfyiamcool avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.