Skip to content

Commit

Permalink
⚗️ 更新实验代码
Browse files Browse the repository at this point in the history
  • Loading branch information
czy-29 committed Dec 29, 2024
1 parent 0832648 commit 8d790c8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
35 changes: 16 additions & 19 deletions tracing-surreal/src/stop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,21 @@ impl<C: Connection> Stop<C> {
let formatted_timestamp = a_timestamp.format("%y%m%d-%H%M%S").to_string();
let client_name = app;
let client_role = Role::Host;
let proc_env = ProcEnv::create()?;
let msg_format = None;
let client_addr = None;
let query_map = None;
let proc_env = ProcEnv::create_async().await;

Ok(Self::handshake_internal(
&db,
&session_id,
&formatted_timestamp,
client_name,
client_role,
&proc_env,
msg_format,
client_addr,
&query_map,
&proc_env,
)
.await?)
}
Expand All @@ -139,10 +139,10 @@ impl<C: Connection> Stop<C> {
&self.formatted_timestamp,
&client_info.client_name,
client_role.into(),
&client_info.proc_env,
Some(client_info.msg_format),
Some(client_addr),
&query_map,
&client_info.proc_env,
)
.await
}
Expand All @@ -153,43 +153,40 @@ impl<C: Connection> Stop<C> {
formatted_timestamp: &str,
client_name: &str,
client_role: Role,
proc_env: &ProcEnv,
msg_format: Option<MsgFormat>,
client_addr: Option<SocketAddr>,
query_map: &Option<HashMap<String, String>>,
proc_env: &Option<ProcEnv>,
) -> surrealdb::Result<Self> {
#[derive(Serialize)]
struct ClientRecord {
a_timestamp: DateTime<Local>,
b_session_id: RecordId,
c_client_name: String,
d_client_role: Role,
e_proc_name: String,
f_proc_id: u32,
g_msg_format: Option<MsgFormat>,
h_client_addr: Option<SocketAddr>,
i_query_map: Option<HashMap<String, String>>,
e_msg_format: Option<MsgFormat>,
f_client_addr: Option<SocketAddr>,
g_query_map: Option<HashMap<String, String>>,
h_proc_env: Option<ProcEnv>,
}

let a_timestamp = Local::now();
let b_session_id = session_id.clone();
let c_client_name = client_name.into();
let d_client_role = client_role;
let e_proc_name = proc_env.proc_name.clone();
let f_proc_id = proc_env.proc_id;
let g_msg_format = msg_format;
let h_client_addr = client_addr;
let i_query_map = query_map.clone();
let e_msg_format = msg_format;
let f_client_addr = client_addr;
let g_query_map = query_map.clone();
let h_proc_env = proc_env.clone();
let record = ClientRecord {
a_timestamp,
b_session_id,
c_client_name,
d_client_role,
e_proc_name,
f_proc_id,
g_msg_format,
h_client_addr,
i_query_map,
e_msg_format,
f_client_addr,
g_query_map,
h_proc_env,
};
let rid: Option<RID> = db
.create((
Expand Down
18 changes: 11 additions & 7 deletions tracing-surreal/src/tracing_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use est::{task::TaskId, thread::ThreadId};
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use std::{num::NonZeroU64, thread};
use tokio::task;
use tokio::task::{self, spawn_blocking};

#[derive(Serialize, Deserialize, Debug, Copy, Clone, Eq, PartialEq, Hash)]
#[serde(rename_all = "lowercase")]
Expand All @@ -25,25 +25,29 @@ pub enum MsgFormat {

#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq, Hash)]
pub struct ProcEnv {
pub proc_name: String,
pub proc_id: u32,
pub proc_name: Option<String>,
}

impl ProcEnv {
// Need to gate this under `sysinfo` & `wgpu` feature flag.
pub fn create() -> std::io::Result<Self> {
let proc_name = current_exe_name()?;
// Need to gate this under `proc-env` & `sysinfo` & `wgpu` feature flag.
pub fn create() -> Self {
let proc_id = std::process::id();
let proc_name = current_exe_name().ok();

Ok(Self { proc_name, proc_id })
Self { proc_id, proc_name }
}

pub async fn create_async() -> Option<Self> {
spawn_blocking(Self::create).await.ok()
}
}

#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq, Hash)]
pub struct Handshake {
pub client_name: String,
pub msg_format: MsgFormat,
pub proc_env: ProcEnv,
pub proc_env: Option<ProcEnv>,
}

#[derive(Debug, Display, Serialize, Deserialize, Copy, Clone, Eq, PartialEq, Hash)]
Expand Down

0 comments on commit 8d790c8

Please sign in to comment.