heartbeats_simple_sys/
hbs_acc_pow_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_acc_pow_window_complete = Option<extern "C" fn(*const heartbeat_acc_pow_context)>;
8
9/// A heartbeat record with current rates (performance and accuracy).
10#[repr(C)]
11pub struct heartbeat_acc_pow_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    pub accuracy: uint64_t,
23    pub ad: heartbeat_udata,
24    pub acc: heartbeat_rates,
25
26    pub start_energy: uint64_t,
27    pub end_energy: uint64_t,
28    pub ed: heartbeat_udata,
29    pub pwr: heartbeat_rates,
30}
31
32/// A `heartbeat_acc_pow_context` is used for tracking performance/accuracy of recurring jobs.
33#[repr(C)]
34pub struct heartbeat_acc_pow_context {
35    pub ws: heartbeat_window_state,
36    pub window_buffer: *mut heartbeat_acc_pow_record,
37    pub counter: uint64_t,
38    pub lock: c_int,
39    pub hwc_callback: heartbeat_acc_pow_window_complete,
40
41    pub td: heartbeat_udata,
42    pub wd: heartbeat_udata,
43    pub ad: heartbeat_udata,
44    pub ed: heartbeat_udata,
45}
46
47extern "C" {
48    // Core functions
49
50    pub fn heartbeat_acc_pow_init(hb: *mut heartbeat_acc_pow_context,
51                                  window_size: uint64_t,
52                                  window_buffer: *mut heartbeat_acc_pow_record,
53                                  log_fd: c_int,
54                                  hwc_callback: heartbeat_acc_pow_window_complete) -> c_int;
55
56    pub fn heartbeat_acc_pow(hb: *mut heartbeat_acc_pow_context,
57                             user_tag: uint64_t,
58                             work: uint64_t,
59                             start_time: uint64_t,
60                             end_time: uint64_t,
61                             accuracy: uint64_t,
62                             start_energy: uint64_t,
63                             end_energy: uint64_t);
64
65    pub fn hb_acc_pow_log_header(fd: c_int) -> c_int;
66
67    pub fn hb_acc_pow_log_window_buffer(hb: *const heartbeat_acc_pow_context,
68                                        fd: c_int) -> c_int;
69
70    // Utility functions
71
72    pub fn hb_acc_pow_get_window_size(hb: *const heartbeat_acc_pow_context) -> uint64_t;
73    pub fn hb_acc_pow_get_log_fd(hb: *const heartbeat_acc_pow_context) -> c_int;
74
75    pub fn hb_acc_pow_get_user_tag(hb: *const heartbeat_acc_pow_context) -> uint64_t;
76
77    pub fn hb_acc_pow_get_global_time(hb: *const heartbeat_acc_pow_context) -> uint64_t;
78    pub fn hb_acc_pow_get_window_time(hb: *const heartbeat_acc_pow_context) -> uint64_t;
79    pub fn hb_acc_pow_get_global_work(hb: *const heartbeat_acc_pow_context) -> uint64_t;
80    pub fn hb_acc_pow_get_window_work(hb: *const heartbeat_acc_pow_context) -> uint64_t;
81
82    pub fn hb_acc_pow_get_global_perf(hb: *const heartbeat_acc_pow_context) -> c_double;
83    pub fn hb_acc_pow_get_window_perf(hb: *const heartbeat_acc_pow_context) -> c_double;
84    pub fn hb_acc_pow_get_instant_perf(hb: *const heartbeat_acc_pow_context) -> c_double;
85
86    pub fn hb_acc_pow_get_global_accuracy(hb: *const heartbeat_acc_pow_context) -> uint64_t;
87    pub fn hb_acc_pow_get_window_accuracy(hb: *const heartbeat_acc_pow_context) -> uint64_t;
88
89    pub fn hb_acc_pow_get_global_accuracy_rate(hb: *const heartbeat_acc_pow_context) -> c_double;
90    pub fn hb_acc_pow_get_window_accuracy_rate(hb: *const heartbeat_acc_pow_context) -> c_double;
91    pub fn hb_acc_pow_get_instant_accuracy_rate(hb: *const heartbeat_acc_pow_context) -> c_double;
92
93    pub fn hb_acc_pow_get_global_energy(hb: *const heartbeat_acc_pow_context) -> uint64_t;
94    pub fn hb_acc_pow_get_window_energy(hb: *const heartbeat_acc_pow_context) -> uint64_t;
95
96    pub fn hb_acc_pow_get_global_power(hb: *const heartbeat_acc_pow_context) -> c_double;
97    pub fn hb_acc_pow_get_window_power(hb: *const heartbeat_acc_pow_context) -> c_double;
98    pub fn hb_acc_pow_get_instant_power(hb: *const heartbeat_acc_pow_context) -> c_double;
99}