Giter Site home page Giter Site logo

mgartner / pg_flame Goto Github PK

View Code? Open in Web Editor NEW
1.6K 20.0 37.0 73 KB

A flamegraph generator for Postgres EXPLAIN ANALYZE output.

License: Apache License 2.0

Go 99.16% Dockerfile 0.84%
flamegraph postgres performance performance-visualization postgresql postgresql-tool database

pg_flame's Introduction

pg_flame Version Build Status

A flamegraph generator for Postgres EXPLAIN ANALYZE output.

Demo

Try the demo here.

Installation

Homebrew

You can install via Homebrew with the follow command:

$ brew install mgartner/tap/pg_flame

Download pre-compiled binary

Download one of the compiled binaries in the releases tab. Once downloaded, move pg_flame into your $PATH.

Docker

Alternatively, if you'd like to use Docker to build the program, you can.

$ docker pull mgartner/pg_flame

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+.

$ git clone https://github.com/mgartner/pg_flame.git
$ cd pg_flame
$ go build

A pg_flame binary will be created that you can place in your $PATH.

Usage

The pg_flame program reads a JSON query plan from standard input and writes the flamegraph HTML to standard ouput. Therefore you can pipe and direct input and output however you desire.

Example: One-step

$ psql dbname -qAtc 'EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON) SELECT id FROM users' \
    | pg_flame \
    > flamegraph.html \
    && open flamegraph.html

Example: Multi-step with 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.

$ psql dbname -qAtf query.sql > plan.json

Finally, generate the flamegraph HTML.

$ cat plan.json | pg_flame > flamegraph.html

Example: Docker

If you've followed the Docker installation steps above, you can pipe query plan JSON to a container and save the output HTML.

$ psql dbname -qAtc 'EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON) SELECT id FROM users' \
    | docker run -i pg_flame \
    > flamegraph.html

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.