hbs_sys/
lib.rs

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