Git Product home page Git Product logo

slowjam's Introduction

logo

NOTE: This is not an officially supported Google product

SlowJam is a two-part tool for analyzing function latency within Go programs.

  • stacklog - a library for sampling the stack of a Go program during runtime
  • slowjam - a binary for visualizing the latency from recorded stack samples

SlowJam excels at finding optimization opportunities in automation workflows, as they tend to block on command-line execution or remote resources, rather than CPU resources. This tool was created from a hackathon hosted by Google's Container DevEx team, with the goal of finding ways to reduce the start-up latency within minikube.

Features

  • Hybrid Gantt/Flamegraph visualizations
  • Automated sampling of all function calls
  • Trivial to integrate
  • Zero overhead when inactive, <1% overhead when activated

Screenshot

screenshot

See example/minikube.html for example output.

Requirements

  • Go v1.14 or higher

Usage

Recording

Add this to the main() method of your program, or within any other function you wish to record stack samples for:

s := stacklog.MustStartFromEnv("STACKLOG_PATH")
defer s.Stop()

This will invoke the stack sampler if the STACKLOG_PATH environment is set, and will write the stack samples to that location. If you prefer greater control over the configuration, you can also use:

cfg := stacklog.Config{
  Path: "out.slog",
  Poll: 100 * time.Millisecond,
	Quiet: true
}
  
s, err := stacklog.Start(cfg)
defer s.Stop()

By default, this will poll the stack every 125ms.

Visualization

Install slowjam:

go get github.com/google/slowjam/cmd/slowjam

Analyze a stacklog using the interactive webserver:

slowjam --http localhost:8080 /path/to/stack.slog

To output a Gantt/Flamegraph chart to out.html:

slowjam --html out.html /path/to/stack.slog

To output a text summary to out.txt:

slowjam --html out.txt /path/to/stack.slog

Real World Examples

  1. Integrating SlowJam with Go binary.

Here's an example PR to integrate SlowJam analysis into minikube: minikube#8329.

With this PR, anyone can generate a slowjam profile:

env STACKLOG_PATH=minikube.slog minikube start

You can then convert the data to various forms, as per the examples/ directory:

slowjam --goroutines 1 --pprof example/minikube.pprof example/minikube.slog slowjam --html example/minikube.html example/minikube.slog

What minikube contributors discovered with these results were:

  • Functions which could obviously be run in parallel were executed in serial.
  • Functions which we expected to be fast (<1s) were slow (10s). In many cases we were able to remove or rewrite these functions to do less work.

The net result was a 2.5X reduction in start-up latency: from ~66 seconds to ~26 seconds.

  1. Analyzing an integrated Go binary in kubernetes cluster.

Here's an pod config to analyze a Go binary running on a kuberenets cluster: Pod SlowJam Profile

In this Pod Config,

  1. Set the environment variable STACKLOG_PATH to to generate slowjam profile.
  2. Copy the generated stack samples to a accessible location in Container Lifecyle hooks pre-stop.

slowjam's People

Contributors

ilya-zuyev avatar medyagh avatar spowelljr avatar tejal29 avatar tstromberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

slowjam's Issues

cant install cli in windows

PS C:\Windows\system32> go get github.com/google/slowjam/cmd/slowjam

# github.com/google/slowjam/pkg/stackparse
C:\Users\medya\go\src\github.com\google\slowjam\pkg\stackparse\stackparse.go:35:11: undefined: stack.Context
C:\Users\medya\go\src\github.com\google\slowjam\pkg\stackparse\stackparse.go:65:16: undefined: stack.ParseDump
C:\Users\medya\go\src\github.com\google\slowjam\pkg\stackparse\timeline.go:248:11: c.Func.PkgName undefined (type stack.Func has no field or method PkgName)
C:\Users\medya\go\src\github.com\google\slowjam\pkg\stackparse\timeline.go:252:22: cannot call non-function c.Func.IsExported (type bool)
C:\Users\medya\go\src\github.com\google\slowjam\pkg\stackparse\timeline.go:256:6: c.IsStdlib undefined (type stack.Call has no field or method IsStdlib)
C:\Users\medya\go\src\github.com\google\slowjam\pkg\stackparse\timeline.go:256:37: c.SrcPath undefined (type stack.Call has no field or method SrcPath)
PS C:\Windows\system32>



PS C:\Windows\system32> go version
go version go1.14.7 windows/amd

also tried go install ...same

feature request: JSON output

I would like slowjam's timeline example to spit out a json, in which has function name and the duration. that way we can sort the json by top lengthy funcs.

feature request: Slowjam UI Diff

if I have two stack logs, I would like Slow jam to generate a Diff UI

so the UI would show

HEAD and a PR , either Side by Side

or if possible, Show each bar with a an additional +2 or -2 (this func is +2) slower or faster

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.