Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bcc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bcc
Commits
b90bbab6
Commit
b90bbab6
authored
Feb 15, 2016
by
Brendan Gregg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
inline C in /tools
parent
b712c66a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
60 additions
and
99 deletions
+60
-99
tools/pidpersec.c
tools/pidpersec.c
+0
-29
tools/pidpersec.py
tools/pidpersec.py
+17
-1
tools/vfscount.c
tools/vfscount.c
+0
-30
tools/vfscount.py
tools/vfscount.py
+18
-1
tools/vfsstat.c
tools/vfsstat.c
+0
-37
tools/vfsstat.py
tools/vfsstat.py
+25
-1
No files found.
tools/pidpersec.c
deleted
100644 → 0
View file @
b712c66a
/*
* pidpersec.c Count new processes (via fork).
* For Linux, uses BCC, eBPF. See the Python front-end.
*
* USAGE: pidpersec.py
*
* Copyright (c) 2015 Brendan Gregg.
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* 11-Aug-2015 Brendan Gregg Created this.
*/
#include <uapi/linux/ptrace.h>
enum
stat_types
{
S_COUNT
=
1
,
S_MAXSTAT
};
BPF_TABLE
(
"array"
,
int
,
u64
,
stats
,
S_MAXSTAT
+
1
);
void
stats_increment
(
int
key
)
{
u64
*
leaf
=
stats
.
lookup
(
&
key
);
if
(
leaf
)
(
*
leaf
)
++
;
}
void
do_count
(
struct
pt_regs
*
ctx
)
{
stats_increment
(
S_COUNT
);
}
tools/pidpersec.py
View file @
b90bbab6
...
...
@@ -18,7 +18,23 @@ from ctypes import c_int
from
time
import
sleep
,
strftime
# load BPF program
b
=
BPF
(
src_file
=
"pidpersec.c"
)
b
=
BPF
(
text
=
"""
#include <uapi/linux/ptrace.h>
enum stat_types {
S_COUNT = 1,
S_MAXSTAT
};
BPF_TABLE("array", int, u64, stats, S_MAXSTAT + 1);
void stats_increment(int key) {
u64 *leaf = stats.lookup(&key);
if (leaf) (*leaf)++;
}
void do_count(struct pt_regs *ctx) { stats_increment(S_COUNT); }
"""
)
b
.
attach_kprobe
(
event
=
"sched_fork"
,
fn_name
=
"do_count"
)
# stat indexes
...
...
tools/vfscount.c
deleted
100644 → 0
View file @
b712c66a
/*
* vfscount.c Count some VFS calls.
* For Linux, uses BCC, eBPF. See the Python front-end.
*
* USAGE: vfscount.py
*
* Copyright (c) 2015 Brendan Gregg.
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* 14-Aug-2015 Brendan Gregg Created this.
*/
#include <uapi/linux/ptrace.h>
struct
key_t
{
u64
ip
;
};
BPF_TABLE
(
"hash"
,
struct
key_t
,
u64
,
counts
,
256
);
int
do_count
(
struct
pt_regs
*
ctx
)
{
struct
key_t
key
=
{};
u64
zero
=
0
,
*
val
;
key
.
ip
=
ctx
->
ip
;
val
=
counts
.
lookup_or_init
(
&
key
,
&
zero
);
(
*
val
)
++
;
return
0
;
}
tools/vfscount.py
View file @
b90bbab6
...
...
@@ -16,7 +16,24 @@ from bcc import BPF
from
time
import
sleep
# load BPF program
b
=
BPF
(
src_file
=
"vfscount.c"
)
b
=
BPF
(
text
=
"""
#include <uapi/linux/ptrace.h>
struct key_t {
u64 ip;
};
BPF_TABLE("hash", struct key_t, u64, counts, 256);
int do_count(struct pt_regs *ctx) {
struct key_t key = {};
u64 zero = 0, *val;
key.ip = ctx->ip;
val = counts.lookup_or_init(&key, &zero);
(*val)++;
return 0;
}
"""
)
b
.
attach_kprobe
(
event_re
=
"^vfs_.*"
,
fn_name
=
"do_count"
)
# header
...
...
tools/vfsstat.c
deleted
100644 → 0
View file @
b712c66a
/*
* vfsstat.c Count some VFS calls.
* For Linux, uses BCC, eBPF. See the Python front-end.
*
* USAGE: vfsstat.py [interval [count]]
*
* Copyright (c) 2015 Brendan Gregg.
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* 14-Aug-2015 Brendan Gregg Created this.
*/
#include <uapi/linux/ptrace.h>
enum
stat_types
{
S_READ
=
1
,
S_WRITE
,
S_FSYNC
,
S_OPEN
,
S_CREATE
,
S_MAXSTAT
};
BPF_TABLE
(
"array"
,
int
,
u64
,
stats
,
S_MAXSTAT
+
1
);
void
stats_increment
(
int
key
)
{
u64
*
leaf
=
stats
.
lookup
(
&
key
);
if
(
leaf
)
(
*
leaf
)
++
;
}
void
do_read
(
struct
pt_regs
*
ctx
)
{
stats_increment
(
S_READ
);
}
void
do_write
(
struct
pt_regs
*
ctx
)
{
stats_increment
(
S_WRITE
);
}
void
do_fsync
(
struct
pt_regs
*
ctx
)
{
stats_increment
(
S_FSYNC
);
}
void
do_open
(
struct
pt_regs
*
ctx
)
{
stats_increment
(
S_OPEN
);
}
void
do_create
(
struct
pt_regs
*
ctx
)
{
stats_increment
(
S_CREATE
);
}
tools/vfsstat.py
View file @
b90bbab6
...
...
@@ -37,7 +37,31 @@ if len(argv) > 1:
usage
()
# load BPF program
b
=
BPF
(
src_file
=
"vfsstat.c"
)
b
=
BPF
(
text
=
"""
#include <uapi/linux/ptrace.h>
enum stat_types {
S_READ = 1,
S_WRITE,
S_FSYNC,
S_OPEN,
S_CREATE,
S_MAXSTAT
};
BPF_TABLE("array", int, u64, stats, S_MAXSTAT + 1);
void stats_increment(int key) {
u64 *leaf = stats.lookup(&key);
if (leaf) (*leaf)++;
}
void do_read(struct pt_regs *ctx) { stats_increment(S_READ); }
void do_write(struct pt_regs *ctx) { stats_increment(S_WRITE); }
void do_fsync(struct pt_regs *ctx) { stats_increment(S_FSYNC); }
void do_open(struct pt_regs *ctx) { stats_increment(S_OPEN); }
void do_create(struct pt_regs *ctx) { stats_increment(S_CREATE); }
"""
)
b
.
attach_kprobe
(
event
=
"vfs_read"
,
fn_name
=
"do_read"
)
b
.
attach_kprobe
(
event
=
"vfs_write"
,
fn_name
=
"do_write"
)
b
.
attach_kprobe
(
event
=
"vfs_fsync"
,
fn_name
=
"do_fsync"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment