-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lua Tools for BCC #457
Lua Tools for BCC #457
Conversation
print("%-9s %-6d %s" % {os.date("%H:%M:%S"), tonumber(event.pid), ffi.string(event.str)}) | ||
end | ||
|
||
b:get_table("events"):open_perf_buffer(print_readline, "struct { uint64_t pid; char str[80]; }") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is (obviously) a port of the existing bashreadline.py
, and I'm particularly happy with it. Very little code, and it shows how you can pass a literal C definition for the structure we're getting out of the perf_buffer
, and have the binding JIT compile it to native code, so the callback receives an event
struct instead of a void pointer.
I think it's a clear win over the Python API!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great. was worried that this struct {pid, char str[80];} copy-paste will be an issue, but looks like other examples get fields into lua dynamically.
Will look through this in more detail, but first: where are the test(s)? :) Would be good to have at least one with the initial checkin to test the sanity of things like dependencies, file placement, etc. |
Good point, hehe. I'm afraid most of the tests are ad-hoc scripts, so I guess my next thing in the TODO list is writing a more-or-less comprehensive suite in Lua that we can put on this PR. I'll get to it sometime this week. |
Amazing work! bashreadline does make for a nice short example. BTW memleak.py is actually Sasha's, not mine. |
First shot at running the example didn't work following the README. I'm sure I'll be able to get it working but probably some updates to the doc will be needed. Running from src/lua: $ sudo ./bcc-probe ../../examples/lua/task_switch.lua
luajit: ./bcc-probe:31: module '../../examples/lua/task_switch' not found:
no field package.preload['../../examples/lua/task_switch']
no file './//////examples/lua/task_switch/init.lua'
no file './//////examples/lua/task_switch.lua'
no file '/usr/share/luajit-2.0.4///////examples/lua/task_switch.lua'
no file '/usr/local/share/lua/5.1///////examples/lua/task_switch.lua'
no file '/usr/local/share/lua/5.1///////examples/lua/task_switch/init.lua'
no file '/usr/share/lua/5.1///////examples/lua/task_switch.lua'
no file '/usr/share/lua/5.1///////examples/lua/task_switch/init.lua'
no file './//////examples/lua/task_switch.so'
no file '/usr/local/lib/lua/5.1///////examples/lua/task_switch.so'
no file '/usr/lib/lua/5.1///////examples/lua/task_switch.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file './.so'
no file '/usr/local/lib/lua/5.1/.so'
no file '/usr/lib/lua/5.1/.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'require'
./bcc-probe:31: in main chunk
[C]: at 0x00404750 and switching to the examples directory: $ sudo ../../src/lua/bcc-probe bashreadline.lua
luajit: ../../src/lua/bcc-probe:19: module 'bcc' not found:
no field package.preload['bcc']
no file './bcc/init.lua'
no file './bcc.lua'
no file '/usr/share/luajit-2.0.4/bcc.lua'
no file '/usr/local/share/lua/5.1/bcc.lua'
no file '/usr/local/share/lua/5.1/bcc/init.lua'
no file '/usr/share/lua/5.1/bcc.lua'
no file '/usr/share/lua/5.1/bcc/init.lua'
no file './bcc.so'
no file '/usr/local/lib/lua/5.1/bcc.so'
no file '/usr/lib/lua/5.1/bcc.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'require'
../../src/lua/bcc-probe:19: in main chunk
[C]: at 0x00404750 |
@drzaeus77: Actually, there's an issue with the examples because the Let me fix this for you. :) |
@drzaeus77: Fixed. Sorry for wasting your time. Our original deployment had our custom tools as modules. You should now be able to call Gonna get started with these tests because they're obviously necessary. |
Thank you! I'd swear I saw |
This is very impressive. I am barely conversational in Lua, but I can definitely understand the desire to use a JIT-compiled language. I wonder how we are going to move forward, though, with shared functionality such as the USDT* and Tracepoint classes. Is there a way for users of one language to benefit from shared code developed in the other language? |
n = n + 1 | ||
end | ||
|
||
assert(n == kprobe_count, "wtf") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meaningful error please
overall looks great. Would be even more awesome to have a static tool that can be built out of luajit-devel and libbcc libraries. Installing libbcc.so and python often gets in the way in production systems. If we can have standalone binary (with only external dependency on kernel headers) then it will go long way. |
local ffi = require("ffi") | ||
|
||
return function(BPF) | ||
local b = BPF:new{src_file="bashreadline.c", debug=true} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two things:
- We've found that inlining the C source contents (which you do in memleak.lua) is more portable. I would suggest adding relative path support or inlining everything, since a user needs to be in the same directory to be able to find bashreadline.c here.
- debug is not a bool, but rather a set of flags. See Minor endian and debug enhancement #456
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking aloud here...if we do truly share the .c file implementation, then duplicating that code in the different bindings could become a bad thing. We should weigh that duplication against tool portability.
Possible solutions to a problem that only just barely exists yet: cmake prepocessing, .c implementation moving to libbcc, git precommit hook to detect out-of-sync files, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found the section on relative include later on in the code, so this is partially answered. If anyone else thinks we should worry about code duplication, let's discuss.
Hey all! I've pushed a small batch of tests (ported straight from the Python counterparts) and implemented a bunch of features which were missing to pass those tests. :) Answering your questions now:
Thank you! 😍 I'm afraid I don't have a good answer regarding code reuse -- beside the obvious that really important features should be written in C/C++ and available in
Thanks for the pointer. I'll try to get this right in both Python and Lua tomorrow. 👌
Totally doable. I've done this plenty of times before for deployments. The resulting binary is rather fat but only depends on ...Except I gotta port the Makefile rule to CMake. [sweats profusely]
Tests are in place. Now I just gotta learn how to wire them up so they run on CI. Let me tinker with this... |
OK, I've added the tests to CMake, but they will not run unless I'm afraid I don't have access to the buildbot to install |
@@ -0,0 +1,6 @@ | |||
find_program(LUAJIT luajit) | |||
|
|||
if(LUAJIT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@drzaeus77 can you install luajit on buildbots and re-trigger ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
installed on ubuntu:
Setting up libluajit-5.1-common (2.0.2+dfsg-1) ...
Setting up luajit (2.0.2+dfsg-1) ...
installed on fedora:
luajit.x86_64 2.0.3-4.fc22
FYI, sudo is definitely installed on the box, we use and depend on it in On Wed, Mar 30, 2016 at 10:48 AM, 4ast notifications@github.com wrote:
|
💥 Green in Ubuntu and Fedora. I've also added some uprobe and dumping tests. I'm working on a standalone build for the lua tools. It's coming along nicely. Anything else you'd like to see from this first PR before merging? :) |
the last two commits could have been squashed, but ok for the history |
🎉 🎉 🎉 Exciting! Thanks for the feedback and support! |
As promised in #455.
This is a code dump of a Lua(JIT) wrapper that we've developed internally at GitHub. Some notes:
src/lua
, so it sits next to thesrc/python
wrapper and the actual implementation.examples/lua
.memleak.lua
. It's a full port of @brendangregg'smemleak.py
and should have identical behavior.I'm aware this is a lot of code to go through. I'm not sure what else can I do to help you approve the binding and get it merged on the tree (or whether you trust my dubious Lua expertise, hehe), but I'm here to answer all your questions.
Thanks!