{"id":1591,"date":"2016-12-01T00:00:48","date_gmt":"2016-11-30T15:00:48","guid":{"rendered":"https:\/\/blog.ymyzk.com\/?p=1591"},"modified":"2016-11-30T23:03:58","modified_gmt":"2016-11-30T14:03:58","slug":"line-profiler-as-a-wsgi-middleware","status":"publish","type":"post","link":"https:\/\/blog.ymyzk.com\/2016\/12\/line-profiler-as-a-wsgi-middleware\/","title":{"rendered":"WSGI \u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3068\u3057\u3066\u4f7f\u3048\u308b\u30e9\u30a4\u30f3\u30d7\u30ed\u30d5\u30a1\u30a4\u30e9\u3092\u4f5c\u3063\u305f\u8a71"},"content":{"rendered":"
\u3053\u306e\u8a18\u4e8b\u306f CAMPHOR- Advent Calendar 2016<\/a> \u306e1\u65e5\u76ee\u306e\u8a18\u4e8b\u3067\u3059.<\/p>\n Python \u306e WSGI \u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3068\u3057\u3066\u4f7f\u3048\u308b\u30e9\u30a4\u30f3\u30d7\u30ed\u30d5\u30a1\u30a4\u30e9 wsgi_lineprof<\/a> \u3092\u4f5c\u6210\u3057\u307e\u3057\u305f. wsgi_lineprof \u306f Django \u3084 Pyramid, Flask, Bottle \u306a\u3069\u306e WSGI \u4e92\u63db\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3084\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3068\u7d44\u307f\u5408\u308f\u305b\u3066\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059.<\/p>\n <\/p>\n Web \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3059\u308b\u969b\u306b, \u30dc\u30c8\u30eb\u30cd\u30c3\u30af\u3068\u306a\u3063\u3066\u3044\u308b\u90e8\u5206\u3092\u767a\u898b\u3059\u308b\u305f\u3081\u306b, \u30e9\u30a4\u30f3\u30d7\u30ed\u30d5\u30a1\u30a4\u30e9\u306f\u6709\u7528\u3067\u3059. Ruby \u3067\u306e WSGI \u306b\u5bfe\u5fdc\u3059\u308b\u00a0Rack \u306b\u306f rack-lineprof<\/a> \u3068\u3044\u3046\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u3042\u308a, Rack \u306e middleware \u3068\u3057\u3066\u7c21\u5358\u306b\u30e9\u30a4\u30f3\u30d7\u30ed\u30d5\u30a1\u30a4\u30e9\u3092\u5229\u7528\u3067\u304d\u307e\u3059. ISUCON \u306e\u53c2\u52a0\u8a18\u4e8b\u7b49\u3092\u898b\u3066\u3044\u308b\u3068, Ruby \u30e6\u30fc\u30b6\u30fc\u306f\u3053\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u6d3b\u7528\u3057\u3066\u3044\u308b\u3088\u3046\u3067, \u7fa8\u307e\u3057\u3044\u306a\u3068\u3044\u3046\u601d\u3044\u304c\u3042\u308a\u307e\u3057\u305f.<\/p>\n Python \u3067\u306f line_profiler<\/a>\u00a0\u3068\u3044\u3046\u30e9\u30a4\u30f3\u30d7\u30ed\u30d5\u30a1\u30a4\u30e9\u30fc\u304c\u3042\u308a\u307e\u3059\u304c, kernprof \u3068\u3044\u3046\u5c02\u7528\u306e\u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u3063\u3066 Python \u30b9\u30af\u30ea\u30d7\u30c8\u3092\u5b9f\u884c\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a, Web \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30d7\u30ed\u30d5\u30a1\u30a4\u30ea\u30f3\u30b0\u306b\u306f\u6c7a\u3057\u3066\u4f7f\u3044\u3084\u3059\u3044\u3082\u306e\u3068\u306f\u8a00\u3048\u307e\u305b\u3093\u3067\u3057\u305f.<\/p>\n wsgi_lineprof \u306f WSGI \u306e\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3068\u3057\u3066\u5229\u7528\u3067\u304d\u308b\u30e9\u30a4\u30f3\u30d7\u30ed\u30d5\u30a1\u30a4\u30e9\u3067\u3059. Python \u306e\u591a\u304f\u306e Web \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3084\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306f WSGI \u306b\u5bfe\u5fdc\u3057\u3066\u3044\u308b\u305f\u3081, \u3053\u308c\u3092\u7c21\u5358\u306b\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059. wsgi_lineprof \u306f Web \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3078\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u305f\u3073\u306b, \u5b9f\u884c\u3055\u308c\u305f\u5168\u3066\u306e\u95a2\u6570\u3068\u95a2\u6570\u5185\u306e\u5404\u884c\u306e\u5b9f\u884c\u6642\u9593\u3092\u53d6\u5f97\u3057, \u305d\u306e\u7d50\u679c\u3092\u51fa\u529b\u3057\u307e\u3059.<\/p>\n \u3053\u306e\u8a18\u4e8b\u3067\u306f, Bottle \u3067\u5b9f\u88c5\u3055\u308c\u305f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5229\u7528\u3057\u307e\u3059. \u6b21\u306e\u30d5\u30a1\u30a4\u30eb\u3092 wsgi_lineprof \u306f pip \u3067\u7c21\u5358\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u304d\u307e\u3059: \u5148\u307b\u3069\u306e \u518d\u3073 \u30d7\u30ed\u30d5\u30a1\u30a4\u30ea\u30f3\u30b0\u306e\u7d50\u679c\u306f\u5404\u30e1\u30bd\u30c3\u30c9\u30fb\u95a2\u6570\u3054\u3068\u306b\u8868\u793a\u3055\u308c\u307e\u3059. \u307e\u305a, \u5148\u982d\u306e\u884c\u304b\u3089\u3053\u306e\u30d7\u30ed\u30d5\u30a1\u30a4\u30eb\u7d50\u679c\u306e\u6642\u9593\u306e\u5358\u4f4d\u306f1\u03bcs (\u30de\u30a4\u30af\u30ed\u79d2) \u3067\u3042\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059.<\/p>\n \u4ee5\u964d\u306f\u5404\u95a2\u6570\u3054\u3068\u306e\u7d50\u679c\u3067\u3059. \u6b21\u306e\u7d50\u679c\u304b\u3089\u306f, \u3053\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u51e6\u7406\u3059\u308b\u9593\u306b\u5229\u7528\u3057\u305f\u5168\u3066\u306e\u30e1\u30bd\u30c3\u30c9\u306e\u7d50\u679c\u304c\u8868\u793a\u3055\u308c\u308b\u305f\u3081, \u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u7b49\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u5834\u5408\u306f\u7d50\u679c\u304c\u81a8\u5927\u306b\u306a\u308a\u307e\u3059. \u7d50\u679c\u3092\u898b\u3084\u3059\u304f\u3059\u308b\u305f\u3081\u306b, \u30d5\u30a1\u30a4\u30eb\u540d\u3067\u8868\u793a\u3059\u308b\u7bc4\u56f2\u3092\u6307\u5b9a\u3057\u305f\u308a, \u5b9f\u884c\u6642\u9593\u306e\u9045\u3044\u9806\u306b\u30bd\u30fc\u30c8\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059.<\/p>\n wsgi_lineprof \u3067\u306f\u30d5\u30a3\u30eb\u30bf\u30fc\u3068\u547c\u3070\u308c\u308b\u6a5f\u80fd\u3092\u7528\u3044\u3066, \u30d7\u30ed\u30d5\u30a1\u30a4\u30eb\u7d50\u679c\u3092\u6574\u7406\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059.\u00a0 \u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3059\u308b\u3068, \u6b21\u306e\u3088\u3046\u306a\u7d50\u679c\u304c\u5f97\u3089\u308c\u307e\u3059:<\/p>\n \u30d5\u30a3\u30eb\u30bf\u30fc\u3092\u4f7f\u3046\u3053\u3068\u3067\u30e9\u30a4\u30d6\u30e9\u30ea\u5185\u90e8\u306e\u51e6\u7406\u6642\u9593\u306f\u8868\u793a\u305b\u305a\u306b, \u76ee\u7684\u306e\u30d5\u30a1\u30a4\u30eb\u3060\u3051\u306e\u30d7\u30ed\u30d5\u30a1\u30a4\u30eb\u7d50\u679c\u3092\u8868\u793a\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3057\u305f!<\/p>\n \u3044\u304f\u3064\u304b\u306e\u7d44\u307f\u8fbc\u307f\u306e\u30d5\u30a3\u30eb\u30bf\u30fc\u304c \u30d7\u30ed\u30d5\u30a1\u30a4\u30eb\u7d50\u679c\u3092\u30d5\u30a1\u30a4\u30eb\u306b\u51fa\u529b\u3057\u305f\u3044\u5834\u5408\u306f wsgi_lineprof \u3067\u5b9f\u884c\u6642\u9593\u3092\u53d6\u5f97\u3059\u308b\u90e8\u5206\u306f line_profiler \u3092\u53c2\u8003\u306b Cython \u3067\u5b9f\u88c5\u3057\u3066\u3044\u307e\u3059. \u5177\u4f53\u7684\u306b\u306f, C API \u306e \u307e\u305f wsgi_lineprof \u3067\u306f, \u578b\u30d2\u30f3\u30c8\u3092\u7a4d\u6975\u7684\u306b\u8a18\u8ff0\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059. PyCharm \u3084 mypy \u306a\u3069\u3067, \u9759\u7684\u578b\u691c\u67fb\u306e\u30e1\u30ea\u30c3\u30c8\u3092\u4eab\u53d7\u3067\u304d\u308b\u306f\u305a\u3067\u3059.<\/p>\n \u3053\u306e\u8a18\u4e8b\u3067\u306f WSGI \u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3068\u3057\u3066\u5229\u7528\u3067\u304d\u308b\u65b0\u3057\u3044\u30e9\u30a4\u30f3\u30d7\u30ed\u30d5\u30a1\u30a4\u30e9 wsgi_lineprof \u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u307e\u3057\u305f. \u3053\u306e\u30d7\u30ed\u30d5\u30a1\u30a4\u30e9\u304c Web \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30fb\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306e\u958b\u767a\u3084 ISUCON \u7b49\u306e\u30b3\u30f3\u30c6\u30b9\u30c8\u306b\u5c11\u3057\u3067\u3082\u5f79\u7acb\u3066\u3070\u5e78\u3044\u3067\u3059.<\/p>\n wsgi_lineprof \u306f\u4eca\u5f8c\u3082\u5c11\u3057\u305a\u3064\u6539\u5584\u3057\u3066\u3044\u304f\u4e88\u5b9a\u3067\u3059. \u30d0\u30b0\u4fee\u6b63\u3084\u6539\u5584\u7b49\u306e PR \u306f GitHub<\/a> \u3067\u53d7\u3051\u4ed8\u3051\u3066\u3044\u307e\u3059. \u30ea\u30dd\u30b8\u30c8\u30ea\u3078\u306e star<\/a> \u3082\u304a\u5f85\u3061\u3057\u3066\u307e\u3059!<\/p>\n CAMPHOR- Advent Calendar 2016<\/a>\u00a02\u65e5\u76ee\u306e\u62c5\u5f53\u306f @ytmatsuge<\/a> \u3067\u3059. \u304a\u697d\u3057\u307f\u306b!!<\/p>\n","protected":false},"excerpt":{"rendered":" \u3053\u306e\u8a18\u4e8b\u306f CAMPHOR- Advent Calendar 2016 \u306e1\u65e5\u76ee\u306e\u8a18\u4e8b\u3067\u3059. Python \u306e WSGI \u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3068\u3057\u3066\u4f7f\u3048\u308b\u30e9\u30a4\u30f3\u30d7\u30ed\u30d5\u30a1\u30a4\u30e9 wsgi_lineprof \u3092\u4f5c\u6210\u3057\u307e\u3057\u305f. wsgi […]<\/p>\n","protected":false},"author":2,"featured_media":1630,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,3],"tags":[100,101,15],"_links":{"self":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts\/1591"}],"collection":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/comments?post=1591"}],"version-history":[{"count":36,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts\/1591\/revisions"}],"predecessor-version":[{"id":1631,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts\/1591\/revisions\/1631"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/media\/1630"}],"wp:attachment":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/media?parent=1591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/categories?post=1591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/tags?post=1591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}\u80cc\u666f<\/h2>\n
\u6982\u8981<\/h2>\n
\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0<\/h2>\n
app.py<\/code> \u3068\u3057\u3066\u4fdd\u5b58\u3057\u307e\u3059:<\/p>\n
import time\r\nimport bottle\r\n\r\napp = bottle.default_app()\r\n\r\ndef get_title():\r\n # DB \u30a2\u30af\u30bb\u30b9\u7b49\u306e\u4ee3\u308f\u308a\u306b1\u79d2\u5f85\u3064\r\n time.sleep(1)\r\n return \"Monty Python\"\r\n\r\ndef fact(n):\r\n if n < 2:\r\n return 1\r\n return n * fact(n - 1)\r\n\r\n@app.route('\/')\r\ndef index():\r\n title = get_title()\r\n number = 500\r\n return \"Title: {}\\n{}! = {}\".format(title, number, fact(number))\r\n\r\nif __name__ == \"__main__\":\r\n bottle.run(app=app)<\/code><\/pre>\n
python app.py<\/code> \u3068\u3057\u3066\u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3057, http:\/\/localhost:8080 \u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u6b21\u306e\u3088\u3046\u306a\u30ec\u30b9\u30dd\u30f3\u30b9\u304c\u8fd4\u3063\u3066\u304d\u307e\u3059.<\/p>\n
Title: Monty Python\r\n500! = 1220136825991110068701238785423046926253574342803192842192413588385845373153881997605496447 (\u7701\u7565)<\/code><\/pre>\n
wsgi_lineprof \u306e\u4f7f\u3044\u65b9<\/h2>\n
pip install\u00a0wsgi_lineprof<\/code> \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u6642\u306b Cython \u306b\u3088\u308b\u62e1\u5f35\u307e\u305f\u306f C \u306b\u3088\u308b\u62e1\u5f35\u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u3059\u308b\u306e\u3067,\u00a0GCC \u7b49\u306e\u30b3\u30f3\u30d1\u30a4\u30e9\u304c\u5165\u3063\u3066\u3044\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059. (\u4eca\u5f8c wheel \u7b49\u3067\u306e\u914d\u5e03\u3092\u5145\u5b9f\u3055\u305b\u3066\u3044\u304f\u4e88\u5b9a\u3067\u3059.)<\/p>\n
app.py<\/code> \u306e
app<\/code> \u306b wsgi_lineprof \u3092\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3068\u3057\u3066\u8ffd\u52a0\u3057\u307e\u3059:<\/p>\n
from wsgi_lineprof.middleware import LineProfilerMiddleware\r\n\r\n(\u4e2d\u7565)\r\n\r\nif __name__ == \"__main__\":\r\n app = LineProfilerMiddleware(app)\r\n bottle.run(app=app)<\/code><\/pre>\n
python app.py<\/code> \u3068\u3057\u3066\u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3057, http:\/\/localhost:8080 \u306b\u30a2\u30af\u30bb\u30b9\u3057\u307e\u3059. \u3059\u308b\u3068, \u6a19\u6e96\u51fa\u529b\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30d7\u30ed\u30d5\u30a1\u30a4\u30ea\u30f3\u30b0\u306e\u7d50\u679c\u304c\u51fa\u529b\u3055\u308c\u307e\u3059:<\/p>\n
Bottle v0.12.10 server starting up (using WSGIRefServer())...\r\nListening on http:\/\/127.0.0.1:8080\/\r\nHit Ctrl-C to quit.\r\n\r\nTime unit: 1e-06 [sec]\r\n\r\nFile: \/Users\/yusuke\/.virtualenvs\/wsgi-lineprof\/lib\/python3.5\/site-packages\/bottle.py\r\nName: __init__\r\nTotal time: 5e-06 [sec]\r\n Line Hits Time Code\r\n===================================\r\n 1929 def __init__(self, *a, **ka):\r\n 1930 1 4 self.dict = {}\r\n 1931 1 1 if a or ka: self.update(*a, **ka)\r\n\r\nFile: \/Users\/yusuke\/.virtualenvs\/wsgi-lineprof\/lib\/python3.5\/site-packages\/bottle.py\r\nName: fset\r\nTotal time: 5e-06 [sec]\r\n Line Hits Time Code\r\n===================================\r\n 1656 6 5 def fset(self, value): ls.var = value\r\n\r\nFile: .\/app.py\r\nName: fact\r\nTotal time: 0.001151 [sec]\r\n Line Hits Time Code\r\n===================================\r\n 16 def fact(n):\r\n 17 500 306 if n < 2:\r\n 18 1 0 return 1\r\n 19 499 845 return n * fact(n - 1)\r\n\r\n(\u4ee5\u4e0b\u7701\u7565)<\/code><\/pre>\n
Time unit: 1e-06 [sec]<\/code><\/pre>\n
app.py<\/code> \u306e
fact<\/code> \u95a2\u6570\u306e\u30d7\u30ed\u30d5\u30a1\u30a4\u30eb\u7d50\u679c\u304c\u5f97\u3089\u308c\u307e\u3059. \u95a2\u6570\u5168\u4f53\u306e\u5b9f\u884c\u6642\u9593\u306f\u00a00.001151 \u79d2\u3067, \u305d\u308c\u305e\u308c\u306e\u884c\u304c\u5b9f\u884c\u3055\u308c\u305f\u56de\u6570\u3068, \u304b\u304b\u3063\u305f\u7dcf\u6642\u9593 (\u4f8b: 17 \u884c\u76ee\u306f500\u56de\u5b9f\u884c\u3055\u308c, 500\u56de\u306e\u5b9f\u884c\u306b\u304b\u304b\u3063\u305f\u6642\u9593\u306f306\u03bcs) \u304c\u5206\u304b\u308a\u307e\u3059.<\/p>\n
File: .\/app.py\r\nName: fact\r\nTotal time: 0.001151 [sec]\r\n Line Hits Time Code\r\n===================================\r\n 16 def fact(n):\r\n 17 500 306 if n < 2:\r\n 18 1 0 return 1\r\n 19 499 845 return n * fact(n - 1)<\/code><\/pre>\n
\u30d5\u30a3\u30eb\u30bf\u30fc<\/h2>\n
wsgi_lineprof.filters.FilenameFilter<\/code> \u306f\u7279\u5b9a\u306e\u30d5\u30a1\u30a4\u30eb\u540d\u306e\u3082\u306e\u306e\u307f\u306e\u7d5e\u308a\u8fbc\u307f,\u00a0
wsgi_lineprof.filters.TotalTimeSorter<\/code> \u3067\u306f total time \u306e\u9577\u3044\u9806\u306b\u30bd\u30fc\u30c8\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059. \u30d5\u30a3\u30eb\u30bf\u30fc\u306f\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092\u8a2d\u5b9a\u3059\u308b\u969b\u306b\u4e00\u7dd2\u306b\u8a2d\u5b9a\u3057\u307e\u3059:<\/p>\n
from wsgi_lineprof.filters import FilenameFilter, TotalTimeSorter\r\n\r\n(\u4e2d\u7565)\r\n\r\nif __name__ == \"__main__\":\r\n filters = [\r\n FilenameFilter(\"app.py\"),\r\n TotalTimeSorter()\r\n ]\r\n app = LineProfilerMiddleware(app, filters=filters)\r\n bottle.run(app=app)<\/code><\/pre>\n
Bottle v0.12.10 server starting up (using WSGIRefServer())...\r\nListening on http:\/\/127.0.0.1:8080\/\r\nHit Ctrl-C to quit.\r\n\r\nTime unit: 1e-06 [sec]\r\n\r\nFile: .\/app.py\r\nName: index\r\nTotal time: 1.00402 [sec]\r\n Line Hits Time Code\r\n===================================\r\n 18 @app.route('\/')\r\n 19 def index():\r\n 20 1 1001447 title = get_title()\r\n 21 1 1 number = 500\r\n 22 1 2576 return \"Title: {}\\n{}! = {}\".format(title, number, fact(number))\r\n\r\nFile: .\/app.py\r\nName: get_title\r\nTotal time: 1.00141 [sec]\r\n Line Hits Time Code\r\n===================================\r\n 8 def get_title():\r\n 9 # DB \u30a2\u30af\u30bb\u30b9\u7b49\u306e\u4ee3\u308f\u308a\u306b1\u79d2\u5f85\u3064\r\n 10 1 1001409 time.sleep(1)\r\n 11 1 4 return \"Monty Python\"\r\n\r\nFile: .\/app.py\r\nName: fact\r\nTotal time: 0.001369 [sec]\r\n Line Hits Time Code\r\n===================================\r\n 13 def fact(n):\r\n 14 500 337 if n < 2:\r\n 15 1 1 return 1\r\n 16 499 1031 return n * fact(n - 1)\r\n\r\n127.0.0.1 - - [30\/Nov\/2016 22:08:20] \"GET \/ HTTP\/1.1\" 200 1162<\/code><\/pre>\n
wsgi_lineprof.filters<\/code> \u306b\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u4ed6\u306b, \u30e9\u30e0\u30c0\u5f0f (
Iterable[wsgi_lineprof.stat.LineProfilerStat]<\/code> \u3092\u3068\u3063\u3066
Iterable[wsgi_lineprof.stat.LineProfilerStat]<\/code> \u3092\u8fd4\u3059\u3082\u306e) \u3092\u7528\u3044\u3066\u7c21\u5358\u306b\u30e6\u30fc\u30b6\u30fc\u5b9a\u7fa9\u306e\u30d5\u30a3\u30eb\u30bf\u30fc\u3092\u5229\u7528\u3067\u304d\u307e\u3059. \u4f8b\u3048\u3070 total time \u304c 0.001 \u79d2\u4ee5\u4e0a\u306e\u7d50\u679c\u306e\u307f\u3092\u8868\u793a\u3059\u308b\u306b\u306f, \u6b21\u306e\u3088\u3046\u306b\u3057\u307e\u3059:<\/p>\n
if __name__ == \"__main__\":\r\n filters = [\r\n lambda stats: filter(lambda stat: stat.total_time > 0.001, stats),\r\n ]\r\n app = LineProfilerMiddleware(app, filters=filters)\r\n bottle.run(app=app)<\/code><\/pre>\n
\u30d5\u30a1\u30a4\u30eb\u3078\u306e\u51fa\u529b<\/h2>\n
stream<\/code> \u5f15\u6570\u3092\u5229\u7528\u3057\u307e\u3059. \u6b21\u306e\u4f8b\u3067\u306f
lineprof.log<\/code> \u306b\u30d7\u30ed\u30d5\u30a1\u30a4\u30eb\u7d50\u679c\u3092\u51fa\u529b\u3057\u307e\u3059.<\/p>\n
if __name__ == \"__main__\":\r\n with open(\"lineprof.log\", \"w\") as f:\r\n app = LineProfilerMiddleware(app, stream=f)\r\n bottle.run(app=app)<\/code><\/pre>\n
\u305d\u306e\u4ed6<\/h2>\n
PyEval_SetTrace<\/code><\/a> \u3092\u901a\u3058\u3066\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u3066\u3044\u307e\u3059.<\/p>\n
\u307e\u3068\u3081<\/h2>\n