Giter VIP home page Giter VIP logo

lfsampler's Introduction

Lua 5.1-5.4 LuaJIT luarocks

LFSampler

LFSampler is a sample profiler, for Lua 5.1-5.4 or LuaJIT. It uses the jit profiler, if available, or the debug library. It can display the data in various formats.

Content

Showcase

LFSampler can be used to generate several types of performance reports. Below you'll find a few examples you may run on some custom code:

Interactive Flamegraphs

Flame-Graph

How it works:

First dump collected stacktraces:

local lfsampler = require "lfsampler"
local formatter = require "lfsampler.formatter"

lfsampler.start()
-- Some code
lfsampler.stop()

local file = io.open("output.cap", "w")
file:write(formatter.flamegraph(lfsampler.popResults(), "graph", formatters.granularityFunc))
file:close()

Now use FlameGraph, to convert the dumped file into a interactive Flame Graph .svg:

<flamegraph> output.cap > output.svg

Flamegraphs are awesome, I highly recommend checking out this video.

Source annotations

Source-Code

How it works:

local lfsampler = require "lfsampler"
local formatter = require "lfsampler.formatter"

lfsampler.start()
-- Some code
lfsampler.stop()

local sources = formatter.annotateSource(lfsampler.popResults())
for name, data in pairs(sources) do
	local file = io.open(name:gsub("%.lua", ".tlua"):gsub("/", "."), "w")
	file:write(data)
	file:close()
end

Getting started

Installing

LFsampler is available via luarocks:

luarocks install lfsampler

An alternative way of installing is to clone or download and extract the source code of this project and add it to your package.path or drop the lfsampler folder into your package.path.

That's it! Once lfsampler is installed, it can be run on your code as shown below:

local lfsampler = require "lfsampler"
local formatter = require "lfsampler.formatter"

lfsampler.start()
-- Some code
lfsampler.stop()

local file = io.open("output.cap", "w")
file:write(formatter.formatReport(lfsampler.popResults()))
file:close()

would produce:

Basic-Report

Documentation

Debugger priority at startup

  1. JIT
  2. debug
  3. dummy

In code documentation available via Lua Language Server.

For detailed infos, see API Reference.

Anything missing?

"If you find any structure or function to be undocumented it was most likely intended for internal use inside the profiler. If you feel like something vital is missing, do not hesitate to open an issue.

lfsampler's People

Contributors

sewbacca avatar

Stargazers

 avatar  avatar Jefferson Martines avatar Jarrian Gojar avatar

Watchers

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