Giter Site home page Giter Site logo

sf-go-profiler's Introduction

sf-go-profiler

sf-apm-profiler enables collecting supported profiles types by golang along with runtime metrics and sends them to snappyflow-apm for further visualization and analysis.

supported profiles: cpu, heap, block, mutex, goroutine, threadcreate

cpu and heap profiles are enabled always other types can be enabled as required.

getting started

  • pre-requisite

    • install and configure snappyflow agent on vm or as a sidecar in the container, as it is required to send data to snappyflow-apm

    • run below command to download or update sf-go-profiler package in your current project.

      go get -u -v github.com/snappyflow/sf-go-profiler/profiler
  • simple example

import "github.com/snappyflow/sf-go-profiler/profiler"

main(){
    profile := profiler.NewProfilerConfig("server")
    profile.Start()
    defer profile.Stop()
    // rest of the application code
}
  • profiling can conditionally enabled when required using golang flags
import (
    "github.com/snappyflow/sf-go-profiler/profiler"
    "flag"
)

main(){
    enableprofile := flag.Bool("profile",false,"enable profiler")
    if *enableprofile {
        profile := profiler.NewProfilerConfig("server")
        // below line disables collection of go runtime metrics
        // profile.DisableRuntimeMetrics()
        // below line disables profiling
        // profile.DisableProfiles()
        profile.Start()
        defer profile.Stop()
    }
    // rest of the application code
}
  • runtime metrics can be disable by calling DisableRuntimeMetrics() similarly profiling can be disabled by calling DisableProfiles() on profile config object.
    profile := profiler.NewProfilerConfig("server")
    // below line disables collection of go runtime metrics
    profile.DisableRuntimeMetrics()
    // below line disables profiling
    profile.DisableProfiles()
    profile.Start()
    defer profile.Stop()
  • enable other supported profiles as required
    // enable block profile and set given block profile rate
    profile.EnableBlockProfile(100)
    // enable mutex profile and set given mutex profile fraction
    profile.EnableMutexProfile(1000)
    // enable goroutine profile
    profile.EnableGoRoutineProfile()
    // enable threadcreate profile
    profile.EnableThreadCreateProfile()
  • since only heap and cpu profiles are enabled by default, all supported profiles can be enabled by call to function EnableAllProfiles(), this sets block profile rate to DefaultBlockProfileRate and mutex profile fraction to DefaultMutexProfileFraction
    // enable all supported profiles
    profile.EnableAllProfiles()

sample runtime metrics collected

{
  "alloc_mb": 8.4275,
  "frees": 28575,
  "gc_cpu_fraction": 0.0001,
  "go_version": "go1.16.4",
  "interval": 60,
  "last_gc": 1631099627396,
  "live_objects": 27146,
  "mallocs": 27361,
  "max_pause_gc_ms": 0.1033,
  "min_pause_gc_ms": 0.0366,
  "num_cpu": 2,
  "num_gc": 2,
  "num_goroutines": 23,
  "pid": 23201,
  "sys_mb": 71.5791,
  "time": 1631099686505,
  "total_alloc_mb": 8.8994,
  "total_pause_gc_ms": 0.14,
}

sf-go-profiler's People

Contributors

gnmahanth avatar

Watchers

Upendra Sahu avatar

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.