flask-profiler源代码下载

  • Git URL:

    复制代码
    git://www.github.com/muatik/flask-profiler.git
  • Git Clone代码到本地:
    复制代码
    git clone http://www.github.com/muatik/flask-profiler
  • Subversion代码到本地:
    复制代码
    $ svn co --depth empty http://www.github.com/muatik/flask-profiler
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
 
烧瓶分析器

版本:1.6

使用 profiler测量在你的Flask 应用程序中定义的端点;并通过web界面提供细粒度的报告。

它给出了这些问题的答案:

  • 应用程序中的瓶颈在哪里?
  • 应用程序中最慢的终结点?
  • 哪些是最常被调用的终结点?
  • 什么导致我的慢速端点? 在哪个上下文中,什么是 ARGS 和 kwargs?
  • 特定请求花费了多少时间?

简而言之,如果你对端点正在做什么和接收的请求进行了了解,请尝试打瓶探查器。

通过使用烧瓶分析器接口,你可以监视所有端点的性能,并通过向下钻取过滤器来调查端点和接收的请求。

屏幕截图

指示板视图显示摘要。

你可以创建过滤器来调查某些类型的请求。 [ alt text](/resources/filtering_all_screen。pngraw=true"按端点筛选")?

你可以看到请求的所有细节。

快速启动

通过例子可以很容易理解烧瓶的轮廓。 让我们来。

按pip安装烧瓶探查器。

复制代码
pip install flask_profiler

在创建 Flask 应用程序时编辑你的代码。

复制代码
# your app.pyfrom flask import Flaskimport flask_profiler
app = Flask(__name__)
app.config["DEBUG"] =True# You need to declare necessary configuration to initialize# flask-profiler as follows:app.config["flask_profiler"] = {
"enabled": app.config["DEBUG"],
"storage": {
"engine": "sqlite" },
"basicAuth":{
"enabled": True,
"username": "admin",
"password": "admin" },
"ignore": [
"^/static/.*" ]
}@app.route('/product/<id>', methods=['GET'])defgetProduct(id):
return"product id is "+str(id)@app.route('/product/<id>', methods=['PUT'])defupdateProduct(id):
return"product {} is being updated".format(id)@app.route('/products', methods=['GET'])deflistProducts():
return"suppose I send you product list..."@app.route('/static/something/', methods=['GET'])deflistProducts():
return"this should not be tracked..."# In order to active flask-profiler, you have to pass flask# app as an argument to flask-profiler.# All the endpoints declared so far will be tracked by flask-profiler.flask_profiler.init_app(app)# endpoint declarations after flask_profiler.init_app() will be# hidden to flask_profiler.@app.route('/doSomething', methods=['GET'])defdoSomething():
return"flask-profiler will not measure this."# But in case you want an endpoint to be measured by flask-profiler,# you can specify this explicitly by using profile() decorator@app.route('/doSomethingImportant', methods=['GET'])@flask_profiler.profile()defdoSomethingImportant():
return"flask-profiler will measure this request."if__name__=='__main__':
app.run(host="127.0.0.1", port=5000)

现在运行你的app.py

复制代码
 
python app.py

并发出一些请求:

复制代码
curl http://127.0.0.1:5000/products
curl http://127.0.0.1:5000/product/123
curl -X PUT -d arg1=val1 http://127.0.0.1:5000/product/123

如果一切正常烧瓶探查器将测量这些请求。 在 http://127.0.0.1 :5000/flask-profiler/ 中可以看到结果,或者将结果作为 JSON http://127.0.0.1 :5000/flask-profiler/api/measurements?sort=elapsed,desc。

如果你想在其他文件或者使用工厂应用程序 Pattern 初始化扩展,也可以创建 Profiler 类的实例,这将在首次运行应用程序时将你的所有端点设置为 register。 例如

复制代码
from flask import Flaskfrom flask_profiler import Profiler
profiler = Profiler()
app = Flask(__name__)
app.config["DEBUG"] =True# You need to declare necessary configuration to initialize# flask-profiler as follows:app.config["flask_profiler"] = {
"enabled": app.config["DEBUG"],
"storage": {
"engine": "sqlite" },
"basicAuth":{
"enabled": True,
"username": "admin",
"password": "admin" },
"ignore": [
"^/static/.*" ]
}
profiler = Profiler() # You can have this in another moduleprofiler.init_app(app)# Or just Profiler(app)@app.route('/product/<id>', methods=['GET'])defgetProduct(id):
return"product id is "+str(id)

使用不同数据库系统的

你可以使用 flaskprofiler SqlLite MongoDB MongoDB 或者MongoDB数据库系统。 但是,它很容易支持其他数据库系统。 如果你希望拥有其他人,请访问捐赠文档。 ( 这很简单)

SQLite

为了使用 SQLite,只需将它指定为 storage.engine 指令的值,如下。

复制代码
app.config["flask_profiler"] = {
"storage": {
"engine": "sqlite",
}
}

下面列出了其他选项。

筛选键说明默认值

 
storage.FILE SQLite数据库文件 NAME flask_profiler.sql
storage.TABLE 分析数据将驻留在其中的表 NAME 度量

为了使用 MongoDB,只需将它指定为 storage.engine 指令的值,如下所示。

复制代码
app.config["flask_profiler"] = {
"storage": {
"engine": "mongodb",
}
}

SQLAchemy

使用 SQLAchemy,只需将它的指定为 storage.engine 指令的值,如下所示。 还首先使用 NAME"flask_profiler"创建一个空数据库。

复制代码
app.config["flask_profiler"] = {
"storage": {
"engine": "sqlalchemy",
"db_url": "postgresql://user:pass@localhost:5432/flask_profiler"# optional, if no db_url specified then sqlite will be used. }
}

自定义数据库引擎

将引擎指定为字符串 MODULE 和类路径。

复制代码
app.config["flask_profiler"] = {
"storage": {
"engine": "custom.project.flask_profiler.mysql.MysqlStorage",
"MYSQL": "mysql://user:password@localhost/flask_profiler" }
}

下面列出了其他选项。

筛选键说明默认值

 
storage.MONGO_URL mongodb连接字符串 mongodb://localhost
storage.DATABASE 数据库名 flask_profiler
storage.COLLECTION 收藏集名称 度量

采样

控制烧瓶探查器取样的数量

你将希望控制 Flask 分析器在生产模式下运行时需要取样的次数。 你可以根据业务逻辑提供一个函数并控制抽样。

示例 1: 100时间的样本 1,随机数

复制代码
app.config["flask_profiler"] = {
"sampling_function": lambda: Trueif random.sample(list(range(1, 101)), 1) == [42] elseFalse}

示例 2: 特定用户的示例

复制代码
app.config["flask_profiler"] = {
"sampling_function": lambda: Trueif user is'divyendu'elseFalse}

如果不存在采样函数,将对所有请求进行采样。

更换烧瓶分析器端点 root

默认情况下,我们可以访问/烧瓶分析器中的烧瓶探查器

复制代码
app.config["flask_profiler"] = {
"endpointRoot": "secret-flask-profiler"}

忽略终结点

烧瓶探查器将尝试跟踪在调用 init_app() 时定义的每个端点。 如果要排除某些终结点,则可以为它们定义匹配的正规表达式,如下所示:

复制代码
app.config["flask_profiler"] = {
"ignore": [
"^/static/.*",
"/api/users/w+/password" ]
}

flask-profiler, 监视端点调用并尝试进行某些分析的Flask 事件探查器的更多相关文章

  1. 【转】SQL Server 2008 事件探查器(SQL SERVER Profiler)

    跟踪数据库sql语句的执行情况.例:一个系统,用到了sql server 数据库,这个系统共有500张表,当用户在前台页面做某一个操作时,比如插入,登录等等,我们想知道此刻是在对哪一张表操作,打开事件 ...

  2. SQL Server 2008 事件探查器(SQL SERVER Profiler)

    要想很好地优化ERP系统,可以从客户端.服务器.网络等入手,对于我们M1系统的优化来说,SQL 语句的优化就起到很重要的作用了.为此,我们展开,学习了SQL SERVER 2008的事件探查器(SQL ...

  3. SQL Server 2008 R2 找不到 Install SQL Server Profiler 找不到 事件探查器 解决

    摘自: http://blog.csdn.net/yuxuac/article/details/8992893 SQL Server 2008 R2 Express Edition - Install ...

  4. Flask框架 (四)—— 请求上下文源码分析、g对象、第三方插件(flask_session、flask_script、wtforms)、信号

    Flask框架 (四)—— 请求上下文源码分析.g对象.第三方插件(flask_session.flask_script.wtforms).信号 目录 请求上下文源码分析.g对象.第三方插件(flas ...

  5. 除了信号触发线程与接收者线程相同的情况能直接调用到slot,其它情况都依赖事件机制(解决上面代码收不到信号的问题其实很简单,在线程的run();函数中添加一个事件循环就可以了,即加入一句exec();),信号槽不就是一个回调函数嘛

    MainWindow::MainWindow(QWidget *parent) :   QMainWindow(parent)   {   pThreadCon = new CSerialThread ...

  6. Unity-自定义事件派发器的两次尝试

    一.前言: 在游戏开发的很多时候,需要引用其他类的方法,但是一旦类多起来了,相互引用会导致引用关系混乱,极其难以阅读. 以前初次做抖音小游戏时,和一位经验老道的cocos程序员合作,看到我写的代码他不 ...

  7. SQL server Profiler 监视数据库活动

    做网站后台开始时需要考虑后台对数据库的一些操作,比如尽量减少查询次数,尽快释放连接,只选取必须的字段等等.如果是用三层开发,复杂的项目中直接拼装SQL语句多一点,拼装的SQL语句可以直接在SQL se ...

  8. Tools-->SQL Server Profiler监视数据库

    http://www.cnblogs.com/lorking/p/4062787.html https://docs.microsoft.com/en-us/sql/tools/sql-server- ...

  9. SQL2005 : 如何在SQL Server Profiler (事件查看器)中 跟踪查看死锁恢复

    SQL Profiler 通过 SQL Profiler 工具程序,可监控应用程序如何访问数据库引擎.普通来说,当系统性能需要优化或是应用程序对数据库访问的结果不合预期,都可以使用该工具确认视图问题所 ...

随机推荐

  1. HMC版本支持

      Target Version Upgrade From Upgrade Instructions Updates Date Available End of Service Models supp ...

  2. JS 循环遍历 总结

    一.循环遍历语句 for...in... (ES5) 语法:javascript for(keys in obj){} 适用:遍历对象 说明: 1.keys表示obj对象的每一个键值对的键(键名),所 ...

  3. Spring Boot JPA - Querydsl

    https://lufficc.com/blog/spring-boot-jpa-querydsl

  4. 循环结构——for语句、seq语句、while语句、break语句

    1.for语句: 运行结果: 2.seq命令生成整数序列: 3.while语句: 执行结果: 4.break语句: break语句是正常结束之前退出当前循环. 执行结果: 5.continue语句: ...

  5. 【vue-router的基础】history了解一下

    概述 window.onpopstate是popstate事件在window对象上的事件处理程序. 每当处于激活状态的历史记录条目发生变化时,popstate事件就会在对应window对象上触发. 如 ...

  6. SpringBoot+Rocketmq

    @PostConstruct:用于在依赖关系注入完成之后需要执行的方法上,以执行任何初始化.此方法必须在将类放入服务之前调用. @PreDestroy:在开发中我们如果要在关闭spring容器后释放一 ...

  7. 【leetcode】1224. Maximum Equal Frequency

    题目如下: Given an array nums of positive integers, return the longest possible length of an array prefi ...

  8. 【leetcode】1200. Minimum Absolute Difference

    题目如下: Given an array of distinct integers arr, find all pairs of elements with the minimum absolute ...

  9. sql len函数 CASE WHEN

    SELECT LEN('SQL Server LEN') length, LEN('SQL Server LEN ') length_with_trailing_blanks; SELECT (CAS ...

  10. 【CodeChef】LECOINS(同余最短路,背包DP)

    题意:给定n个物品,每个物品可以取无限次,每个物品有两种属性:价值v和颜色c 现在有q个询问,每次询问是否能取出价值和为S的方案,如有多解输出不同颜色种数的最大值 题意:看到BZOJ评论区有好心人说C ...