heartbeats_simple_sys/
hbs_sys.rs

1#![allow(non_camel_case_types)]
2
3use libc::{uint64_t, c_double, c_int};
4use hbs_common_sys::{heartbeat_udata, heartbeat_rates, heartbeat_window_state};
5
6/// Typedef for the window completion callback function.
7pub type heartbeat_window_complete = Option<extern "C" fn(*const heartbeat_context)>;
8
9/// A heartbeat record with current rates.
10#[repr(C)]
11pub struct heartbeat_record {
12    pub id: uint64_t,
13    pub user_tag: uint64_t,
14
15    pub work: uint64_t,
16    pub wd: heartbeat_udata,
17    pub start_time: uint64_t,
18    pub end_time: uint64_t,
19    pub td: heartbeat_udata,
20    pub perf: heartbeat_rates,
21}
22
23/// A `heartbeat_context` is used for tracking performance/power of recurring jobs.
24#[repr(C)]
25pub struct heartbeat_context {
26    pub ws: heartbeat_window_state,
27    pub window_buffer: *mut heartbeat_record,
28    pub counter: uint64_t,
29    pub lock: c_int,
30    pub hwc_callback: heartbeat_window_complete,
31
32    pub td: heartbeat_udata,
33    pub wd: heartbeat_udata,
34}
35
36extern "C" {
37    // Core functions
38
39    pub fn heartbeat_init(hb: *mut heartbeat_context,
40                          window_size: uint64_t,
41                          window_buffer: *mut heartbeat_record,
42                          log_fd: c_int,
43                          hwc_callback: heartbeat_window_complete) -> c_int;
44
45    pub fn heartbeat(hb: *mut heartbeat_context,
46                     user_tag: uint64_t,
47                     work: uint64_t,
48                     start_time: uint64_t,
49                     end_time: uint64_t);
50
51    pub fn hb_log_header(fd: c_int) -> c_int;
52
53    pub fn hb_log_window_buffer(hb: *const heartbeat_context,
54                                fd: c_int) -> c_int;
55
56    // Utility functions
57
58    pub fn hb_get_window_size(hb: *const heartbeat_context) -> uint64_t;
59    pub fn hb_get_log_fd(hb: *const heartbeat_context) -> c_int;
60
61    pub fn hb_get_user_tag(hb: *const heartbeat_context) -> uint64_t;
62
63    pub fn hb_get_global_time(hb: *const heartbeat_context) -> uint64_t;
64    pub fn hb_get_window_time(hb: *const heartbeat_context) -> uint64_t;
65    pub fn hb_get_global_work(hb: *const heartbeat_context) -> uint64_t;
66    pub fn hb_get_window_work(hb: *const heartbeat_context) -> uint64_t;
67
68    pub fn hb_get_global_perf(hb: *const heartbeat_context) -> c_double;
69    pub fn hb_get_window_perf(hb: *const heartbeat_context) -> c_double;
70    pub fn hb_get_instant_perf(hb: *const heartbeat_context) -> c_double;
71}