https://github.com/chronolaw/lua-resty-gperftools
Lua API for ngx_google_perftools_profiler_module
https://github.com/chronolaw/lua-resty-gperftools
lua-resty nginx openresty perftools
Last synced: 2 months ago
JSON representation
Lua API for ngx_google_perftools_profiler_module
- Host: GitHub
- URL: https://github.com/chronolaw/lua-resty-gperftools
- Owner: chronolaw
- License: bsd-2-clause
- Created: 2018-06-28T09:05:26.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-29T02:35:47.000Z (almost 8 years ago)
- Last Synced: 2025-07-05T19:14:55.676Z (12 months ago)
- Topics: lua-resty, nginx, openresty, perftools
- Language: Lua
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lua-resty-gperftools
Lua API for [`ngx_google_perftools_profiler_module`](https://github.com/chronolaw/ngx_google_perftools_profiler_module)
Before use these tools, you must compile nginx/openresty with
[`ngx_google_perftools_profiler_module`](https://github.com/chronolaw/ngx_google_perftools_profiler_module)
## Installation
Please use `opm`, such as :
```lua
opm get chronolaw/lua-resty-gperftools
```
## Usage
Some simple examples:
```nginx
location /gperftools {
content_by_lua_block {
local gperftools = require "resty.gperftools"
local profiler = ngx.var.arg_profiler
local action = ngx.var.arg_action
local name = ngx.var.arg_name
gperftools[profiler][action](name)
-- or profiler in 10 seconds
-- gperftools[profiler][action](name, 10)
ngx.say("OK")
}
}
```
Then you can start/stop gperftools with `curl` like below:
```shell
curl 'http://127.0.0.1/gperftools?profiler=cpu&action=start&name=/tmp/ngx_prof'
... # ab/http_load/wrk and so on
curl 'http://127.0.0.1/gperftools?profiler=cpu&action=stop'
```
## API
### ok, err = gperftools.cpu.start(name, *during*)
Start cpu profiler, infomations stores in `name`.
If `during` is given, the profiler will STOP after `during` seconds.
Notice: It will NOT add pid suffix for the name.
### gperftools.cpu.stop()
Stop cpu profiler.
### gperftools.heap.start(name, *n*, *during*)
Start heap profiler, infomations stores in `name`, dump for every `n` seconds.
If `during` is given, the profiler will STOP after `during` seconds.
Notice: It will NOT add pid suffix for the name.
### gperftools.heap.dump(s)
Dump heap profiler infomations, `s` for the reason.
### gperftools.heap.stop()
Stop heap profiler.