Skip to content
This repository has been archived by the owner on May 29, 2022. It is now read-only.

Golang profiler #6

Open
wass88 opened this issue Aug 30, 2020 · 13 comments
Open

Golang profiler #6

wass88 opened this issue Aug 30, 2020 · 13 comments

Comments

@wass88
Copy link
Contributor

wass88 commented Aug 30, 2020

https://gist.github.com/catatsuy/e627aaf118fbe001f2e7c665fda48146

@wass88
Copy link
Contributor Author

wass88 commented Aug 30, 2020

image
便利そう

import "github.com/pkg/profile"
defer profile.Start(profile.ProfilePath("/home/isucon/profile")).Stop()

@wass88
Copy link
Contributor Author

wass88 commented Aug 30, 2020

@wass88
Copy link
Contributor Author

wass88 commented Aug 30, 2020

X-Ra SDK for Go そんなに大変じゃなさそう
https://docs.aws.amazon.com/ja_jp/xray/latest/devguide/xray-sdk-go-configuration.html

設定の例:

{
  "version": 2,
  "rules": [
    {
      "description": "Player moves.",
      "host": "*",
      "http_method": "*",
      "url_path": "/api/move/*",
      "fixed_target": 0,
      "rate": 0.05
    }
  ],
  "default": {
    "fixed_target": 1,
    "rate": 0.1
  }
}

@wass88
Copy link
Contributor Author

wass88 commented Aug 30, 2020

発行されたSQLをstdoutにproxy
https://github.com/shogo82148/go-sql-proxy
実行時間も出る

@utgwkk
Copy link
Collaborator

utgwkk commented Aug 30, 2020

SQLのcaller埋め込む君をaerealさんが書いてたの思い出した
go-sql-caller-annotation: GoでSQLに呼び出し元の情報をコメントとして埋め込む - Sexually Knowing

@wass88
Copy link
Contributor Author

wass88 commented Aug 30, 2020

err漏れとかclose漏れとかの検出器ほしいな

@wass88
Copy link
Contributor Author

wass88 commented Aug 30, 2020

resp.Body.close忘れるとTCPのstructが再利用されないらしいので気をつけたい

@utgwkk
Copy link
Collaborator

utgwkk commented Aug 30, 2020

VSCodeで手元でwebappを動かしてブレークポイント仕掛けてコールスタック眺めるなどことができた
Image from Gyazo

@utgwkk
Copy link
Collaborator

utgwkk commented Aug 30, 2020

pprofだいたいこの記事を読んだら使い方がわかった http://blog.livedoor.jp/sonots/archives/39879160.html

@wass88
Copy link
Contributor Author

wass88 commented Aug 30, 2020

image
https://blog.golang.org/pprof
lineprofはlistコマンドでできる

@wass88
Copy link
Contributor Author

wass88 commented Aug 30, 2020

X of Y やlistの初め2カラムは

  • その関数自体の処理時間/単位時間
  • その関数から呼び出された関数を含めた処理時間/単位時間

@wass88
Copy link
Contributor Author

wass88 commented Aug 30, 2020

  • go tool pprof --nodefraction=0.1 でノードを削れる

@wass88
Copy link
Contributor Author

wass88 commented Sep 11, 2020

	profilePath := fmt.Sprintf("./profile/%s/", time.Now().Format("20060102150405"))
	defer profile.Start(profile.ProfilePath(profilePath)).Stop()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants