Skip to content

Commit 77d17d7

Browse files
prashksSebastien Roy
authored and
Sebastien Roy
committed
Merge estat with main repo (#4)
1 parent 787d8f5 commit 77d17d7

27 files changed

+1173
-1810
lines changed

Diff for: estat/README.md renamed to README_estat.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
`estat` - extensible performance observability tool for Delphix Dynamic Data Platform.
44

5-
This tool mainly uses `eBPF` programs with `BCC` front-end to collect and output performance statistics from kernel via `kprobes`.
5+
This tool mainly uses `eBPF` programs with a `BCC` front-end to collect and output performance statistics from the kernel via `kprobes`.
66
It is made up of the following components:
77

88
- `cmd/estat`
@@ -16,7 +16,7 @@ It is made up of the following components:
1616

1717
## Installation
1818

19-
`estat` is provided as an archive package of its components.
19+
`estat` is already installed on the Delphix Dynamic Data Platform.
2020

2121
## Usage
2222

Diff for: bpf/estat/backend-io.c

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2019 Delphix. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: GPL-2.0-or-later
5+
*/
6+
7+
#include <uapi/linux/ptrace.h>
8+
#include <linux/bpf_common.h>
9+
#include <linux/blkdev.h>
10+
#include <linux/blk_types.h>
11+
#include <uapi/linux/bpf.h>
12+
13+
14+
// Definitions for this script
15+
#define READ_STR "read "
16+
#define WRITE_STR "write "
17+
#define OP_NAME_LEN 7
18+
#define DEV_NAME_LEN 8
19+
#define NAME_LENGTH (OP_NAME_LEN + 1)
20+
#define AXIS_LENGTH (DEV_NAME_LEN + 1)
21+
22+
// Structure to hold thread local data
23+
typedef struct {
24+
u64 ts;
25+
unsigned int size;
26+
unsigned int cmd_flags;
27+
u32 err;
28+
char device[DEV_NAME_LEN];
29+
} io_data_t;
30+
31+
BPF_HASH(io_base_data, u64, io_data_t);
32+
33+
// @@ kprobe|blk_start_request|disk_io_start
34+
// @@ kprobe|blk_mq_start_request|disk_io_start
35+
int
36+
disk_io_start(struct pt_regs *ctx, struct request *reqp)
37+
{
38+
io_data_t data = {};
39+
struct gendisk *diskp = reqp->rq_disk;
40+
data.ts = bpf_ktime_get_ns();
41+
data.cmd_flags = reqp->cmd_flags;
42+
data.size = reqp->__data_len;
43+
__builtin_memcpy(&data.device, diskp->disk_name, DEV_NAME_LEN);
44+
io_base_data.update((u64 *) &reqp, &data);
45+
return (0);
46+
}
47+
48+
// @@ kprobe|blk_account_io_completion|disk_io_done
49+
int
50+
disk_io_done(struct pt_regs *ctx, struct request *reqp)
51+
{
52+
u64 ts = bpf_ktime_get_ns();
53+
io_data_t *data = io_base_data.lookup((u64 *) &reqp);
54+
struct bio *bp = reqp->bio;
55+
56+
if (data == 0) {
57+
return (0); // missed issue
58+
}
59+
60+
u64 delta = ts - data->ts;
61+
char name[NAME_LENGTH] = "";
62+
char axis[AXIS_LENGTH] = "";
63+
64+
data->err = (bp->bi_status == BLK_STS_OK) ? 0 : 1;
65+
66+
if ((data->cmd_flags & REQ_OP_MASK) == REQ_OP_WRITE) {
67+
__builtin_memcpy(&name, WRITE_STR, OP_NAME_LEN);
68+
} else {
69+
__builtin_memcpy(&name, READ_STR, OP_NAME_LEN);
70+
}
71+
72+
#ifdef OPTARG
73+
if ((sizeof (OPTARG) == 4) && (OPTARG[0] == 'l') &&
74+
(OPTARG[1] == 'u') && (OPTARG[2] == 'n')) {
75+
__builtin_memcpy(&axis, data->device, AXIS_LENGTH);
76+
}
77+
#endif
78+
79+
// Perform aggregations
80+
AGGREGATE_DATA(name, axis, delta, data->size);
81+
io_base_data.delete((u64 *) &reqp);
82+
return (0);
83+
}

Diff for: bpf/estat/iscsi.c

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2019 Delphix. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: GPL-2.0-or-later
5+
*/
6+
7+
#include <uapi/linux/ptrace.h>
8+
#include <linux/bpf_common.h>
9+
#include <uapi/linux/bpf.h>
10+
#include "target/iscsi/iscsi_target_core.h"
11+
12+
13+
// Definitions for this script
14+
#define READ_STR "read"
15+
#define WRITE_STR "write"
16+
17+
#define OP_NAME_LEN 6
18+
#define NAME_LENGTH (OP_NAME_LEN + 1)
19+
20+
typedef struct {
21+
u64 ts;
22+
u64 flags;
23+
u64 size;
24+
} iscsi_data_t;
25+
26+
27+
BPF_HASH(iscsi_base_data, u64, iscsi_data_t);
28+
29+
// @@ kprobe|iscsit_process_scsi_cmd|iscsi_target_start
30+
int
31+
iscsi_target_start(struct pt_regs *ctx, struct iscsi_conn *conn,
32+
struct iscsi_cmd *cmd, struct iscsi_scsi_req *hdr)
33+
{
34+
iscsi_data_t data = {};
35+
data.ts = bpf_ktime_get_ns();
36+
data.flags = hdr->flags;
37+
data.size = hdr->data_length;
38+
iscsi_base_data.update((u64 *) &cmd, &data);
39+
40+
return (0);
41+
}
42+
43+
static int
44+
aggregate_data(iscsi_data_t *data, u64 ts, char *opstr)
45+
{
46+
u64 delta;
47+
char name[NAME_LENGTH] = "";
48+
char axis = 0;
49+
50+
delta = ts - data->ts;
51+
__builtin_memcpy(&name, opstr, OP_NAME_LEN);
52+
53+
// Perform aggregations
54+
AGGREGATE_DATA(name, &axis, delta, data->size);
55+
return (0);
56+
}
57+
58+
// @@ kprobe|iscsit_build_rsp_pdu|iscsi_target_end
59+
int
60+
iscsi_target_end(struct pt_regs *ctx, struct iscsi_cmd *cmd)
61+
{
62+
u64 ts = bpf_ktime_get_ns();
63+
iscsi_data_t *data = iscsi_base_data.lookup((u64 *) &cmd);
64+
u64 delta;
65+
66+
if (data == 0) {
67+
return (0); // missed issue
68+
}
69+
70+
if (data->flags & ISCSI_FLAG_CMD_READ) {
71+
aggregate_data(data, ts, READ_STR);
72+
} else if (data->flags & ISCSI_FLAG_CMD_WRITE) {
73+
aggregate_data(data, ts, WRITE_STR);
74+
}
75+
iscsi_base_data.delete((u64 *) &cmd);
76+
77+
return (0);
78+
}

0 commit comments

Comments
 (0)