pprof

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2022 License: BSD-3-Clause Imports: 5 Imported by: 0

README

pprof GoDoc

Usage

local pprof = require("pprof")
local http = require("http")
local time = require("time")

local client = http.client()
local pp = pprof.register(":1234")

pp:enable()
time.sleep(1)

local req, err = http.request("GET", "http://127.0.0.1:1234/debug/pprof/goroutine")
if err then error(err) end
local resp, err = client:do_request(req)
if err then error(err) end
if not(resp.code == 200) then error("resp code") end

pp:disable()
time.sleep(5)

local resp, err = client:do_request(req)
if not(err) then error("must be error") end

Documentation

Overview

Package pprof implements golang package pprof functionality.

Example (Package)

pprof:register(), pprof_ud:enable(), pprof_ud:disable()

package main

import (
	"log"

	lua_http "github.com/alexjx/gopher-lua-libs/http"
	lua_pprof "github.com/alexjx/gopher-lua-libs/pprof"

	lua_time "github.com/alexjx/gopher-lua-libs/time"

	lua "github.com/yuin/gopher-lua"
)

func main() {
	state := lua.NewState()
	lua_pprof.Preload(state)
	lua_http.Preload(state)
	lua_time.Preload(state)
	source := `
local pprof = require("pprof")
local http = require("http")
local time = require("time")

local client = http.client()
local pp = pprof.register(":1234")

pp:enable()
time.sleep(1)

local req, err = http.request("GET", "http://127.0.0.1:1234/debug/pprof/goroutine")
if err then error(err) end
local resp, err = client:do_request(req)
if err then error(err) end
if not(resp.code == 200) then error("resp code") end
print(resp.code)

pp:disable()
time.sleep(5)

local resp, err = client:do_request(req)
if not(err) then error("must be error") end
        `
	if err := state.DoString(source); err != nil {
		log.Fatal(err.Error())
	}
}
Output:

200

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Disable

func Disable(L *lua.LState) int

Disable pprof stop

func Enable

func Enable(L *lua.LState) int

Enable start pprof

func Loader

func Loader(L *lua.LState) int

Loader is the module loader function.

func Preload

func Preload(L *lua.LState)

Preload adds pprof to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:

local pprof = require("pprof")

func Register

func Register(L *lua.LState) int

Register(string): return (pprof_ud, err)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL