From 70f13618c91de6d1b903b496a53946da4e4cb3c0 Mon Sep 17 00:00:00 2001 From: vivi Date: Sat, 25 Dec 2021 20:36:30 +0800 Subject: [PATCH 1/3] readme --- README.md | 91 +++++++++++++++++++++++++------------------------------ 1 file changed, 41 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index af71d68..553bee8 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,14 @@ ## `profiler` 基于 `pprof` 与 `go trace` 持续性能剖析工具 -- 根据配置文件收集目标服务的样本, 收集程序会监听配置文件变化实时更新收集目标 +- 根据配置文件收集目标服务的样本, 收集程序会监听配置文件的变化,即时应用变化后的配置文件 - 支持的样本 `trace` `fgprof` `profile` `mutex` `heap` `goroutine` `allocs` `block` `threadcreate` -- 提供图表观测服务性能指标的趋势,找出性能问题的时间点 -- 点击图标中的气泡跳转到 `pprof` 与 `trace` 的详细页面进行进一步详细的分析 +- 提供 `chart` 观测服务性能指标的趋势,找出性能问题的时间点 +- 点击 `chart` 中的气泡跳转到 `pprof` 与 `trace` 的详细页面进行进一步详细的分析 - + @@ -23,7 +23,7 @@ - + @@ -57,7 +57,9 @@ docker run -d -p 80:80 -v ~/profiler/data/:/profiler/data/ -v ~/profiler/config/ ## 抓取配置 -需要被收集分析的 `golang` 程序,需要提供 `net/http/pprof` 端点,并配置在 `./collector.yaml` 配置文件中 +需要被收集分析的 `golang` 程序,需要提供 `net/http/pprof` 端点,并配置在 `./collector.yaml` 配置文件中。 + +配置文件可以在线更新,收集程序会监听配置文件的变化,即时应用变化后的配置文件。 ### `collector.yaml` @@ -65,17 +67,17 @@ docker run -d -p 80:80 -v ~/profiler/data/:/profiler/data/ -v ~/profiler/config/ collector: targetConfigs: - profiler-server: # 服务名称 + profiler-server: # 目标名称 interval: 15s # 抓取间隔 expiration: 0 # 无过期时间 host: localhost:9000 # 目标服务host - profileConfigs: # 默认抓取 (trace, profile, fgprof, mutex, heap, goroutine, allocs, block, threadcreate) + profileConfigs: # 使用默认配置 server2: interval: 10s expiration: 168h # 过期时间7天 host: localhost:9000 - profileConfigs: # 覆盖默认配置(trace,fgprof,profile,heap)的部分字段 + profileConfigs: # 覆盖部分默认配置字段 trace: enable: false fgprof: @@ -89,45 +91,34 @@ collector: ``` ### `profileConfigs` 默认配置 -```go -func defaultProfileConfigs() map[string]ProfileConfig { - return map[string]ProfileConfig{ - "profile": { - Path: "/debug/pprof/profile?seconds=10", - Enable: utils.BoolPtr(true), - }, - "fgprof": { - Path: "/debug/fgprof?seconds=10", - Enable: utils.BoolPtr(true), - }, - "trace": { - Path: "/debug/pprof/trace?seconds=10", - Enable: utils.BoolPtr(true), - }, - "mutex": { - Path: "/debug/pprof/mutex", - Enable: utils.BoolPtr(true), - }, - "heap": { - Path: "/debug/pprof/heap", - Enable: utils.BoolPtr(true), - }, - "goroutine": { - Path: "/debug/pprof/goroutine", - Enable: utils.BoolPtr(true), - }, - "allocs": { - Path: "/debug/pprof/allocs", - Enable: utils.BoolPtr(true), - }, - "block": { - Path: "/debug/pprof/block", - Enable: utils.BoolPtr(true), - }, - "threadcreate": { - Path: "/debug/pprof/threadcreate", - Enable: utils.BoolPtr(true), - }, - } -} + +```yaml +profileConfigs: + profile: + Path: "/debug/pprof/profile?seconds=10" + Enable: true + fgprof: + Path: "/debug/fgprof?seconds=10" + Enable: true + trace: + Path: "/debug/pprof/trace?seconds=10" + Enable: true + mutex: + Path: "/debug/pprof/mutex" + Enable: true + heap: + Path: "/debug/pprof/heap" + Enable: true + goroutine: + Path: "/debug/pprof/goroutine" + Enable: true + allocs: + Path: "/debug/pprof/allocs" + Enable: true + block: + Path: "/debug/pprof/block" + Enable: true + threadcreate: + Path: "/debug/pprof/threadcreate" + Enable: true ``` \ No newline at end of file From 1b9e8d2fea94358743f86d9c010385306e4d0ced Mon Sep 17 00:00:00 2001 From: vivi Date: Sat, 25 Dec 2021 22:11:48 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=9A=82=E6=97=B6=E4=B8=8D=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E8=BD=AC=E6=8D=A2trace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/collector/collector.go | 10 +++++----- pkg/storage/badger/store.go | 5 ++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/collector/collector.go b/pkg/collector/collector.go index de2c675..8c07865 100644 --- a/pkg/collector/collector.go +++ b/pkg/collector/collector.go @@ -12,7 +12,6 @@ import ( "github.com/google/pprof/profile" "github.com/sirupsen/logrus" - "github.com/xyctruth/profiler/pkg/internal/v1175/trace" "github.com/xyctruth/profiler/pkg/storage" ) @@ -213,10 +212,11 @@ func (collector *Collector) analysis(profileType string, profileBytes []byte) er func (collector *Collector) analysisTrace(profileType string, profileBytes []byte) error { buf := &bytes.Buffer{} buf.Write(profileBytes) - _, err := trace.Parse(buf, collector.TargetName) - if err != nil { - return err - } + + //_, err := trace.Parse(buf, collector.TargetName) + //if err != nil { + // return err + //} profileID, err := collector.store.SaveProfile(profileBytes, collector.Expiration) if err != nil { diff --git a/pkg/storage/badger/store.go b/pkg/storage/badger/store.go index 0b646fb..5bae783 100644 --- a/pkg/storage/badger/store.go +++ b/pkg/storage/badger/store.go @@ -16,7 +16,10 @@ type store struct { } func NewStore(path string) storage.Store { - db, err := badger.Open(badger.DefaultOptions(path).WithLoggingLevel(3).WithBypassLockGuard(true)) + db, err := badger.Open( + badger.DefaultOptions(path). + WithLoggingLevel(3). + WithBypassLockGuard(true)) if err != nil { panic(err) } From e850e5d4721143e6277dcdca820ff00057a3efb7 Mon Sep 17 00:00:00 2001 From: vivi Date: Sat, 25 Dec 2021 23:24:38 +0800 Subject: [PATCH 3/3] lint --- pkg/storage/badger/store.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/storage/badger/store.go b/pkg/storage/badger/store.go index 5bae783..1a1ddf6 100644 --- a/pkg/storage/badger/store.go +++ b/pkg/storage/badger/store.go @@ -18,8 +18,9 @@ type store struct { func NewStore(path string) storage.Store { db, err := badger.Open( badger.DefaultOptions(path). - WithLoggingLevel(3). - WithBypassLockGuard(true)) + WithLoggingLevel(3). + WithBypassLockGuard(true)) + if err != nil { panic(err) }
pprof图表pprof chart 点击气泡跳转pprof详情
trace图表trace chart 点击气泡跳转trace详情