Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit fca1a29

Browse files
author
alexkar598
committed
Adds profiler logging support
1 parent 858e560 commit fca1a29

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

dmsrc/influxdb2.dm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
#define rustg_influxdb2_publish(data, endpoint, token) RUSTG_CALL(RUST_G, "influxdb2_publish")(data, endpoint, token)
2+
#define rustg_influxdb2_publish_profile(data, endpoint, token, round_id) RUSTG_CALL(RUST_G, "influxdb2_publish_profile")(data, endpoint, token, round_id)

src/influxdb2.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use serde::{Deserialize, Serialize};
12
use serde_json::Value;
23

34
use crate::error::Error;
@@ -57,3 +58,54 @@ byond_fn!(
5758
}))
5859
}
5960
);
61+
62+
#[derive(Serialize, Deserialize)]
63+
struct ProfileProcEntry {
64+
name: String,
65+
#[serde(rename = "self")]
66+
self_: f32,
67+
total: f32,
68+
real: f32,
69+
over: f32,
70+
calls: f32,
71+
}
72+
byond_fn!(
73+
fn influxdb2_publish_profile(data, endpoint, token, round_id) {
74+
let data = data.to_owned();
75+
let endpoint = endpoint.to_owned();
76+
let token = token.to_owned();
77+
let round_id = round_id.to_owned();
78+
Some(jobs::start(move || {
79+
fn handle(data: &str, endpoint: &str, token: &str, round_id: &str) -> Result<RequestPrep, Error> {
80+
let mut lines = vec!();
81+
82+
let data: Vec<ProfileProcEntry> = serde_json::from_str(data)?;
83+
let timestamp = std::time::SystemTime::now()
84+
.duration_since(std::time::UNIX_EPOCH)
85+
.unwrap()
86+
.as_secs()
87+
.to_string();
88+
for entry in data {
89+
lines.push(concat_string!("profile,proc=", entry.name, " self=", entry.self_.to_string(), ",total=", entry.total.to_string(), ",real=", entry.real.to_string(), ",over=", entry.over.to_string(), ",calls=", entry.calls.to_string(), ",round_id=", round_id.to_string(), " ", timestamp));
90+
}
91+
92+
construct_request(
93+
"post",
94+
endpoint,
95+
lines.join("\n").as_str(),
96+
concat_string!("{\"Authorization\":\"Token ", token ,"\"}").as_str(),
97+
""
98+
)
99+
}
100+
101+
let req = match handle(data.as_str(), endpoint.as_str(), token.as_str(), round_id.as_str()) {
102+
Ok(r) => r,
103+
Err(e) => return e.to_string()
104+
};
105+
match submit_request(req) {
106+
Ok(r) => r,
107+
Err(e) => e.to_string()
108+
}
109+
}))
110+
}
111+
);

0 commit comments

Comments
 (0)