pg_flame

command module
v0.0.0-...-7936e40 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

README

pg_flame

A flamegraph generator for Postgres EXPLAIN ANALYZE output.

A almost rewrite version,

  • static.go is generated with zipdata from static directory.
  • Support offline.
  • Use webview to automatically open created html.
  • Support DATABASE_URL enviroment variable.

Demo

Try the demo here.

Installation

Build from source

If you'd like to build a binary from the source code, run the following commands. Note that compiling requires Go version 1.13+.

$ go get -u github.com/alitrack/pg_flame

A pg_flame binary will be created that you can place in your $GOPATH/bin.

Usage

usage: pg_flame [<flags>]

A flamegraph generator for Postgres EXPLAIN ANALYZE output.

Flags:
      --help                    Show context-sensitive help (also try --help-long and --help-man).
  -U, --username="steven"       database user name
  -h, --host="localhost"        database server host or socket directory
  -p, --port=5432               database server port
      --sslmode="disable"       database server sslmode
      --password=PASSWORD       database server password
      --dbname="postgres"       database name
  -o, --output="pg_flame.html"  output html file
  -c, --command=COMMAND         run only single command (SQL)
  -f, --file=FILE               execute commands from file
  -s, --show_browser            Launch browser if successful
      --version                 Show application version.
Example: from sql command
$ pg_flame -c  'EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON) SELECT id FROM users'
Example: from sql file

Create a SQL file with the EXPLAIN ANALYZE query.

-- query.sql
EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON)
SELECT id
FROM users

Then run the query and save the JSON to a file.

$ pg_flame -f query.sql

Background

Flamegraphs were invented by Brendan Gregg to visualize CPU consumption per code-path of profiled software. They are useful visualization tools in many types of performance investigations. Flamegraphs have been used to visualize Oracle database query plans and query executions , proving useful for debugging slow database queries.

Pg_flame is in extension of that work for Postgres query plans. It generates a visual hierarchy of query plans. This visualization identifies the relative time of each part of a query plan.

This tool relies on the spiermar/d3-flame-graph plugin to generate the flamegraph.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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