1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// if the probe is disabled, then the variables won't be used.
#![allow(unused_variables)]

use super::Trace;
use crate::{timer::Timestamp, units::*};
use probe::probe;

#[derive(Clone, Debug, Default)]
pub struct Usdt {
    connection_id: u64,
}

impl Trace for Usdt {
    #[inline(always)]
    fn enter_connection(&mut self, id: u64) {
        self.connection_id = id;
    }

    #[inline(never)]
    fn send(&mut self, _now: Timestamp, stream_id: u64, len: u64) {
        probe!(netbench, netbench__send, self.connection_id, stream_id, len);
    }

    #[inline(never)]
    fn send_finish(&mut self, _now: Timestamp, stream_id: u64) {
        probe!(
            netbench,
            netbench__send__finish,
            self.connection_id,
            stream_id
        );
    }

    #[inline(never)]
    fn receive(&mut self, _now: Timestamp, stream_id: u64, len: u64) {
        probe!(
            netbench,
            netbench__receive,
            self.connection_id,
            stream_id,
            len
        );
    }

    #[inline(never)]
    fn receive_finish(&mut self, _now: Timestamp, stream_id: u64) {
        probe!(
            netbench,
            netbench__receive__finish,
            self.connection_id,
            stream_id
        );
    }

    #[inline(never)]
    fn accept(&mut self, _now: Timestamp, stream_id: u64) {
        probe!(netbench, netbench__accept, self.connection_id, stream_id);
    }

    #[inline(never)]
    fn open(&mut self, _now: Timestamp, stream_id: u64) {
        probe!(netbench, netbench__open, self.connection_id, stream_id);
    }

    #[inline(never)]
    fn trace(&mut self, _now: Timestamp, id: u64) {
        probe!(netbench, netbench__trace, self.connection_id, id);
    }

    #[inline(never)]
    fn profile(&mut self, now: Timestamp, id: u64, time: Duration) {
        let time = time.as_micros() as u64;
        probe!(netbench, netbench__profile, self.connection_id, id, time);
    }

    #[inline(never)]
    fn park(&mut self, _now: Timestamp, id: u64) {
        probe!(netbench, netbench__park, self.connection_id, id);
    }

    #[inline(never)]
    fn unpark(&mut self, _now: Timestamp, id: u64) {
        probe!(netbench, netbench__unpark, self.connection_id, id);
    }

    #[inline(never)]
    fn connect(&mut self, _now: Timestamp, id: u64, time: Duration) {
        let time = time.as_micros() as u64;
        probe!(netbench, netbench__connect, self.connection_id, id, time);
    }
}