{"id":13398132,"url":"https://github.com/brendangregg/FlameGraph","last_synced_at":"2025-03-14T02:30:36.477Z","repository":{"id":2054204,"uuid":"2992074","full_name":"brendangregg/FlameGraph","owner":"brendangregg","description":"Stack trace visualizer","archived":false,"fork":false,"pushed_at":"2024-10-20T21:48:45.000Z","size":1914,"stargazers_count":17224,"open_issues_count":163,"forks_count":1963,"subscribers_count":481,"default_branch":"master","last_synced_at":"2024-10-21T02:12:38.102Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.brendangregg.com/flamegraphs.html","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"J7mbo/twitter-api-php","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brendangregg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-12-16T02:20:53.000Z","updated_at":"2024-10-20T21:48:52.000Z","dependencies_parsed_at":"2023-11-08T05:42:28.948Z","dependency_job_id":"dd807c11-2790-4089-af2c-4f297b104daf","html_url":"https://github.com/brendangregg/FlameGraph","commit_stats":{"total_commits":270,"total_committers":74,"mean_commits":"3.6486486486486487","dds":0.6851851851851851,"last_synced_commit":"7991019ca55b8e7d35de1fae9fe8a84b54dda75f"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brendangregg%2FFlameGraph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brendangregg%2FFlameGraph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brendangregg%2FFlameGraph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brendangregg%2FFlameGraph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brendangregg","download_url":"https://codeload.github.com/brendangregg/FlameGraph/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242961691,"owners_count":20213316,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T19:00:17.809Z","updated_at":"2025-03-14T02:30:35.986Z","avatar_url":"https://github.com/brendangregg.png","language":"Perl","funding_links":[],"categories":["Behavior","HarmonyOS","Perl","Misc","Profiling","others","Development Environment","Libraries","其他","Software","System","HTML"],"sub_categories":["Windows Manager","Procfile","Debugging and Tracing","网络服务_其他","Visualization"],"readme":"# Flame Graphs visualize profiled code\n\nMain Website: http://www.brendangregg.com/flamegraphs.html\n\nExample (click to zoom):\n\n[![Example](http://www.brendangregg.com/FlameGraphs/cpu-bash-flamegraph.svg)](http://www.brendangregg.com/FlameGraphs/cpu-bash-flamegraph.svg)\n\nClick a box to zoom the Flame Graph to this stack frame only.\nTo search and highlight all stack frames matching a regular expression, click the _search_ button in the upper right corner or press Ctrl-F.\nBy default, search is case sensitive, but this can be toggled by pressing Ctrl-I or by clicking the _ic_ button in the upper right corner.\n\nOther sites:\n- The Flame Graph article in ACMQ and CACM: http://queue.acm.org/detail.cfm?id=2927301 http://cacm.acm.org/magazines/2016/6/202665-the-flame-graph/abstract\n- CPU profiling using Linux perf\\_events, DTrace, SystemTap, or ktap: http://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html\n- CPU profiling using XCode Instruments: http://schani.wordpress.com/2012/11/16/flame-graphs-for-instruments/  \n- CPU profiling using Xperf.exe: http://randomascii.wordpress.com/2013/03/26/summarizing-xperf-cpu-usage-with-flame-graphs/  \n- Memory profiling: http://www.brendangregg.com/FlameGraphs/memoryflamegraphs.html  \n- Other examples, updates, and news: http://www.brendangregg.com/flamegraphs.html#Updates\n\nFlame graphs can be created in three steps:\n\n1. Capture stacks\n2. Fold stacks\n3. flamegraph.pl\n\n1\\. Capture stacks\n=================\nStack samples can be captured using Linux perf\\_events, FreeBSD pmcstat (hwpmc), DTrace, SystemTap, and many other profilers. See the stackcollapse-\\* converters.\n\n### Linux perf\\_events\n\nUsing Linux perf\\_events (aka \"perf\") to capture 60 seconds of 99 Hertz stack samples, both user- and kernel-level stacks, all processes:\n\n```\n# perf record -F 99 -a -g -- sleep 60\n# perf script \u003e out.perf\n```\n\nNow only capturing PID 181:\n\n```\n# perf record -F 99 -p 181 -g -- sleep 60\n# perf script \u003e out.perf\n```\n\n### DTrace\n\nUsing DTrace to capture 60 seconds of kernel stacks at 997 Hertz:\n\n```\n# dtrace -x stackframes=100 -n 'profile-997 /arg0/ { @[stack()] = count(); } tick-60s { exit(0); }' -o out.kern_stacks\n```\n\nUsing DTrace to capture 60 seconds of user-level stacks for PID 12345 at 97 Hertz:\n\n```\n# dtrace -x ustackframes=100 -n 'profile-97 /pid == 12345 \u0026\u0026 arg1/ { @[ustack()] = count(); } tick-60s { exit(0); }' -o out.user_stacks\n```\n\n60 seconds of user-level stacks, including time spent in-kernel, for PID 12345 at 97 Hertz:\n\n```\n# dtrace -x ustackframes=100 -n 'profile-97 /pid == 12345/ { @[ustack()] = count(); } tick-60s { exit(0); }' -o out.user_stacks\n```\n\nSwitch `ustack()` for `jstack()` if the application has a ustack helper to include translated frames (eg, node.js frames; see: http://dtrace.org/blogs/dap/2012/01/05/where-does-your-node-program-spend-its-time/).  The rate for user-level stack collection is deliberately slower than kernel, which is especially important when using `jstack()` as it performs additional work to translate frames.\n\n2\\. Fold stacks\n==============\nUse the stackcollapse programs to fold stack samples into single lines.  The programs provided are:\n\n- `stackcollapse.pl`: for DTrace stacks\n- `stackcollapse-perf.pl`: for Linux perf_events \"perf script\" output\n- `stackcollapse-pmc.pl`: for FreeBSD pmcstat -G stacks\n- `stackcollapse-stap.pl`: for SystemTap stacks\n- `stackcollapse-instruments.pl`: for XCode Instruments\n- `stackcollapse-vtune.pl`: for Intel VTune profiles\n- `stackcollapse-ljp.awk`: for Lightweight Java Profiler\n- `stackcollapse-jstack.pl`: for Java jstack(1) output\n- `stackcollapse-gdb.pl`: for gdb(1) stacks\n- `stackcollapse-go.pl`: for Golang pprof stacks\n- `stackcollapse-vsprof.pl`: for Microsoft Visual Studio profiles\n- `stackcollapse-wcp.pl`: for wallClockProfiler output\n\nUsage example:\n\n```\nFor perf_events:\n$ ./stackcollapse-perf.pl out.perf \u003e out.folded\n\nFor DTrace:\n$ ./stackcollapse.pl out.kern_stacks \u003e out.kern_folded\n```\n\nThe output looks like this:\n\n```\nunix`_sys_sysenter_post_swapgs 1401\nunix`_sys_sysenter_post_swapgs;genunix`close 5\nunix`_sys_sysenter_post_swapgs;genunix`close;genunix`closeandsetf 85\nunix`_sys_sysenter_post_swapgs;genunix`close;genunix`closeandsetf;c2audit`audit_closef 26\nunix`_sys_sysenter_post_swapgs;genunix`close;genunix`closeandsetf;c2audit`audit_setf 5\nunix`_sys_sysenter_post_swapgs;genunix`close;genunix`closeandsetf;genunix`audit_getstate 6\nunix`_sys_sysenter_post_swapgs;genunix`close;genunix`closeandsetf;genunix`audit_unfalloc 2\nunix`_sys_sysenter_post_swapgs;genunix`close;genunix`closeandsetf;genunix`closef 48\n[...]\n```\n\n3\\. flamegraph.pl\n================\nUse flamegraph.pl to render a SVG.\n\n```\n$ ./flamegraph.pl out.kern_folded \u003e kernel.svg\n```\n\nAn advantage of having the folded input file (and why this is separate to flamegraph.pl) is that you can use grep for functions of interest. Eg:\n\n```\n$ grep cpuid out.kern_folded | ./flamegraph.pl \u003e cpuid.svg\n```\n\nProvided Examples\n=================\n\n### Linux perf\\_events\n\nAn example output from Linux \"perf script\" is included, gzip'd, as example-perf-stacks.txt.gz. The resulting flame graph is example-perf.svg:\n\n[![Example](http://www.brendangregg.com/FlameGraphs/example-perf.svg)](http://www.brendangregg.com/FlameGraphs/example-perf.svg)\n\nYou can create this using:\n\n```\n$ gunzip -c example-perf-stacks.txt.gz | ./stackcollapse-perf.pl --all | ./flamegraph.pl --color=java --hash \u003e example-perf.svg\n```\n\nThis shows my typical workflow: I'll gzip profiles on the target, then copy them to my laptop for analysis. Since I have hundreds of profiles, I leave them gzip'd!\n\nSince this profile included Java, I used the flamegraph.pl --color=java palette. I've also used stackcollapse-perf.pl --all, which includes all annotations that help flamegraph.pl use separate colors for kernel and user level code. The resulting flame graph uses: green == Java, yellow == C++, red == user-mode native, orange == kernel.\n\nThis profile was from an analysis of vert.x performance. The benchmark client, wrk, is also visible in the flame graph.\n\n### DTrace\n\nAn example output from DTrace is also included, example-dtrace-stacks.txt, and the resulting flame graph, example-dtrace.svg:\n\n[![Example](http://www.brendangregg.com/FlameGraphs/example-dtrace.svg)](http://www.brendangregg.com/FlameGraphs/example-dtrace.svg)\n\nYou can generate this using:\n\n```\n$ ./stackcollapse.pl example-stacks.txt | ./flamegraph.pl \u003e example.svg\n```\n\nThis was from a particular performance investigation: the Flame Graph identified that CPU time was spent in the lofs module, and quantified that time.\n\n\nOptions\n=======\nSee the USAGE message (--help) for options:\n\nUSAGE: ./flamegraph.pl [options] infile \u003e outfile.svg\n\n\t--title TEXT     # change title text\n\t--subtitle TEXT  # second level title (optional)\n\t--width NUM      # width of image (default 1200)\n\t--height NUM     # height of each frame (default 16)\n\t--minwidth NUM   # omit smaller functions. In pixels or use \"%\" for \n\t                 # percentage of time (default 0.1 pixels)\n\t--fonttype FONT  # font type (default \"Verdana\")\n\t--fontsize NUM   # font size (default 12)\n\t--countname TEXT # count type label (default \"samples\")\n\t--nametype TEXT  # name type label (default \"Function:\")\n\t--colors PALETTE # set color palette. choices are: hot (default), mem,\n\t                 # io, wakeup, chain, java, js, perl, red, green, blue,\n\t                 # aqua, yellow, purple, orange\n\t--bgcolors COLOR # set background colors. gradient choices are yellow\n\t                 # (default), blue, green, grey; flat colors use \"#rrggbb\"\n\t--hash           # colors are keyed by function name hash\n\t--cp             # use consistent palette (palette.map)\n\t--reverse        # generate stack-reversed flame graph\n\t--inverted       # icicle graph\n\t--flamechart     # produce a flame chart (sort by time, do not merge stacks)\n\t--negate         # switch differential hues (blue\u003c-\u003ered)\n\t--notes TEXT     # add notes comment in SVG (for debugging)\n\t--help           # this message\n\n\teg,\n\t./flamegraph.pl --title=\"Flame Graph: malloc()\" trace.txt \u003e graph.svg\n\nAs suggested in the example, flame graphs can process traces of any event,\nsuch as malloc()s, provided stack traces are gathered.\n\n\nConsistent Palette\n==================\nIf you use the `--cp` option, it will use the $colors selection and randomly\ngenerate the palette like normal. Any future flamegraphs created using the `--cp`\noption will use the same palette map. Any new symbols from future flamegraphs\nwill have their colors randomly generated using the $colors selection.\n\nIf you don't like the palette, just delete the palette.map file.\n\nThis allows your to change your colorscheme between flamegraphs to make the\ndifferences REALLY stand out.\n\nExample:\n\nSay we have 2 captures, one with a problem, and one when it was working\n(whatever \"it\" is):\n\n```\ncat working.folded | ./flamegraph.pl --cp \u003e working.svg\n# this generates a palette.map, as per the normal random generated look.\n\ncat broken.folded | ./flamegraph.pl --cp --colors mem \u003e broken.svg\n# this svg will use the same palette.map for the same events, but a very\n# different colorscheme for any new events.\n```\n\nTake a look at the demo directory for an example:\n\npalette-example-working.svg  \npalette-example-broken.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrendangregg%2FFlameGraph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrendangregg%2FFlameGraph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrendangregg%2FFlameGraph/lists"}