• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env bcc-lua
2--[[
3Copyright 2016 Marek Vavrusa <mvavrusa@cloudflare.com>
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16]]
17-- Simple tracing example that executes a program on
18-- return from sys_write() and tracks the number of hits
19local ffi = require('ffi')
20local bpf = require('bpf')
21local S = require('syscall')
22
23-- Shared part of the program
24local map = bpf.map('array', 1)
25-- Kernel-space part of the program
26local probe = bpf.kprobe('myprobe:sys_write', function (ptregs)
27   xadd(map[0], 1)
28end, true)
29-- User-space part of the program
30pcall(function()
31	for _ = 1, 10 do
32	   print('hits: ', tonumber(map[0]))
33	   S.sleep(1)
34	end
35end)
36