Skip to content

Commit 33507cb

Browse files
committed
feat: work on experimetnal ct rr worker support: setup, communication
1 parent fd96f5b commit 33507cb

File tree

13 files changed

+183
-43
lines changed

13 files changed

+183
-43
lines changed

justfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ stop:
263263
killall -9 virtualization-layers db-backend node .electron-wrapped || true
264264
killall -9 electron || true
265265
killall -9 backend-manager || true
266+
killall -9 ct-rr-worker || true
266267

267268
reset-config:
268269
rm --force ~/.config/codetracer/.config.yaml && \

src/common/config.nim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type
1111
path*: string
1212
ctPaths*: string
1313
debugInfoToolPath*: string
14+
ctRRWorkerExe*: string
1415

1516
FlowConfigObjWrapper* = object
1617
enabled*: bool
@@ -63,7 +64,8 @@ type
6364
enabled: false,
6465
path: "",
6566
ctPaths: "",
66-
debugInfoToolPath: ""
67+
debugInfoToolPath: "",
68+
ctRRWorkerExe: "",
6769
).}: RRBackendConfig
6870
skipInstall: bool
6971

src/config/default_config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ rrBackend:
116116
path: ""
117117
ctPaths: ""
118118
debugInfoToolPath: ""
119+
ctRRWorkerExe: ""
119120

120121
skipInstall: true
121122

src/db-backend/src/bin/virtualization-layers.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ extern crate db_backend;
2121
use db_backend::core::Core;
2222
use db_backend::db::Db;
2323
use db_backend::handler::{Handler, TraceKind};
24+
use db_backend::rr_dispatcher::CtRRArgs;
2425
// use db_backend::receiver::Receiver;
2526
// use db_backend::response::Response;
2627

@@ -78,7 +79,7 @@ fn main() -> Result<(), Box<dyn Error>> {
7879
let db = Db::new(&PathBuf::from(""));
7980
// receiver.setup_for_virtualization_layers(&cli.socket_path, cli.caller_process_pid)?;
8081

81-
let mut _handler = Handler::construct(TraceKind::DB, Box::new(db), true);
82+
let mut _handler = Handler::construct(TraceKind::DB, CtRRArgs::default(), Box::new(db), true);
8283

8384
// receiver.receive_loop(&mut handler)?;
8485

src/db-backend/src/dap.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub struct LaunchRequestArguments {
3737
pub trace_file: Option<PathBuf>,
3838
#[serde(rename = "rawDiffIndex", skip_serializing_if = "Option::is_none")]
3939
pub raw_diff_index: Option<String>,
40+
#[serde(rename = "ctRRWorkerExe", skip_serializing_if = "Option::is_none")]
41+
pub ct_rr_worker_exe: Option<PathBuf>,
4042
#[serde(skip_serializing_if = "Option::is_none")]
4143
pub pid: Option<u64>,
4244
#[serde(skip_serializing_if = "Option::is_none")]

src/db-backend/src/dap_server.rs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::dap_types::{self, Breakpoint, SetBreakpointsArguments, SetBreakpoints
44
use crate::db::Db;
55
use crate::handler::{Handler, TraceKind};
66
use crate::paths::CODETRACER_PATHS;
7+
use crate::rr_dispatcher::CtRRArgs;
78
use crate::task::{
89
gen_task_id, Action, CallSearchArg, CalltraceLoadArgs, CollapseCallsArgs, CtLoadFlowArguments,
910
CtLoadLocalsArguments, FunctionLocation, LoadHistoryArg, LocalStepJump, Location, ProgramEvent, RunTracepointsArg,
@@ -17,7 +18,7 @@ use crate::transport::DapTransport;
1718
#[cfg(feature = "browser-transport")]
1819
use crate::transport::{DapResult, WorkerTransport};
1920

20-
use log::info;
21+
use log::{info, warn};
2122
use serde_json::json;
2223
use std::collections::{HashMap, HashSet};
2324
use std::error::Error;
@@ -86,8 +87,13 @@ pub fn run(socket_path: &PathBuf) -> Result<(), Box<dyn Error>> {
8687
handle_client(&mut reader, &mut writer)
8788
}
8889

89-
fn launch(trace_folder: &Path, trace_file: &Path, raw_diff_index: Option<String>, seq: i64) -> Result<Handler, Box<dyn Error>> {
90-
// TODO: log this when logging logic is properly abstracted
90+
fn launch(
91+
trace_folder: &Path,
92+
trace_file: &Path,
93+
raw_diff_index: Option<String>,
94+
ct_rr_worker_exe: &Path,
95+
seq: i64,
96+
) -> Result<Handler, Box<dyn Error>> {
9197
info!("run launch() for {:?}", trace_folder);
9298
let trace_file_format = if trace_file.extension() == Some(std::ffi::OsStr::new("json")) {
9399
runtime_tracing::TraceEventsFileFormat::Json
@@ -106,18 +112,23 @@ fn launch(trace_folder: &Path, trace_file: &Path, raw_diff_index: Option<String>
106112
let mut proc = TraceProcessor::new(&mut db);
107113
proc.postprocess(&trace)?;
108114

109-
let mut handler = Handler::new(TraceKind::DB, Box::new(db));
115+
let mut handler = Handler::new(TraceKind::DB, CtRRArgs::default(), Box::new(db));
110116
handler.dap_client.seq = seq;
111117
handler.raw_diff_index = raw_diff_index;
112118
handler.run_to_entry(dap::Request::default())?;
113119
Ok(handler)
114120
} else {
115121
warn!("problem with reading metadata or path trace files: try rr?");
116-
let path = trace_folder.join("rr");
122+
let path = trace_folder.join("rr").join("latest-trace");
117123
if path.exists() {
118-
let db = Db::new(&PathBuf::from(""));
119-
let mut handler = Handler::new(TraceKind::RR, Box::new(db));
124+
let db = Db::new(&PathBuf::from(""));
125+
let ct_rr_args = CtRRArgs {
126+
worker_exe: PathBuf::from(ct_rr_worker_exe),
127+
rr_trace_folder: path,
128+
};
129+
let mut handler = Handler::new(TraceKind::RR, ct_rr_args, Box::new(db));
120130
handler.dap_client.seq = seq;
131+
handler.raw_diff_index = raw_diff_index;
121132
handler.run_to_entry(dap::Request::default())?;
122133
Ok(handler)
123134
} else {
@@ -245,6 +256,7 @@ pub struct Ctx {
245256
pub launch_trace_folder: PathBuf,
246257
pub launch_trace_file: PathBuf,
247258
pub launch_raw_diff_index: Option<String>,
259+
pub ct_rr_worker_exe: PathBuf,
248260
pub received_configuration_done: bool,
249261
}
250262

@@ -258,6 +270,7 @@ impl Default for Ctx {
258270
launch_trace_folder: PathBuf::from(""),
259271
launch_trace_file: PathBuf::from(""),
260272
launch_raw_diff_index: None,
273+
ct_rr_worker_exe: PathBuf::from(""),
261274
received_configuration_done: false,
262275
}
263276
}
@@ -406,9 +419,15 @@ pub fn handle_message<T: DapTransport>(
406419
//info!("stored launch trace folder: {0:?}", ctx.launch_trace_folder)
407420

408421
ctx.launch_raw_diff_index = args.raw_diff_index.clone();
422+
ctx.ct_rr_worker_exe = args.ct_rr_worker_exe.unwrap_or(PathBuf::from(""));
409423

410424
if ctx.received_configuration_done {
411-
ctx.handler = Some(launch(&ctx.launch_trace_folder, &ctx.launch_trace_file, ctx.launch_raw_diff_index.clone(), ctx.seq)?);
425+
ctx.handler = Some(launch(
426+
&ctx.launch_trace_folder,
427+
&ctx.launch_trace_file,
428+
ctx.launch_raw_diff_index.clone(),
429+
&ctx.ct_rr_worker_exe,
430+
ctx.seq)?);
412431
if let Some(h) = ctx.handler.as_mut() {
413432
write_dap_messages(transport, h, &mut ctx.seq)?;
414433
}
@@ -457,7 +476,12 @@ pub fn handle_message<T: DapTransport>(
457476
// ctx.received_launch
458477
// );
459478
if ctx.received_launch {
460-
ctx.handler = Some(launch(&ctx.launch_trace_folder, &ctx.launch_trace_file, ctx.launch_raw_diff_index.clone(), ctx.seq)?);
479+
ctx.handler = Some(launch(
480+
&ctx.launch_trace_folder,
481+
&ctx.launch_trace_file,
482+
ctx.launch_raw_diff_index.clone(),
483+
&ctx.ct_rr_worker_exe,
484+
ctx.seq)?);
461485
if let Some(h) = ctx.handler.as_mut() {
462486
write_dap_messages(transport, h, &mut ctx.seq)?;
463487
}

src/db-backend/src/handler.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::event_db::{EventDb, SingleTableId};
1515
use crate::expr_loader::ExprLoader;
1616
use crate::flow_preloader::FlowPreloader;
1717
use crate::program_search_tool::ProgramSearchTool;
18-
use crate::rr_dispatcher::{RRDispatcher};
18+
use crate::rr_dispatcher::{CtRRArgs, RRDispatcher};
1919
// use crate::response::{};
2020
use crate::dap_types;
2121
// use crate::dap_types::Source;
@@ -60,10 +60,9 @@ pub struct Handler {
6060
#[derive(Debug, Clone)]
6161
pub enum TraceKind {
6262
DB,
63-
RR
63+
RR,
6464
}
6565

66-
6766
#[derive(Debug, Clone, Serialize, Deserialize)]
6867
pub struct BreakpointRecord {
6968
pub is_active: bool,
@@ -90,11 +89,11 @@ type LineTraceMap = HashMap<usize, Vec<(usize, String)>>;
9089
// sender.
9190

9291
impl Handler {
93-
pub fn new(trace_kind: TraceKind, db: Box<Db>) -> Handler {
94-
Self::construct(trace_kind, db, false)
92+
pub fn new(trace_kind: TraceKind, ct_rr_args: CtRRArgs, db: Box<Db>) -> Handler {
93+
Self::construct(trace_kind, ct_rr_args, db, false)
9594
}
9695

97-
pub fn construct(trace_kind: TraceKind, db: Box<Db>, indirect_send: bool) -> Handler {
96+
pub fn construct(trace_kind: TraceKind, ct_rr_args: CtRRArgs, db: Box<Db>, indirect_send: bool) -> Handler {
9897
let calltrace = Calltrace::new(&db);
9998
let trace = CoreTrace::default();
10099
let mut expr_loader = ExprLoader::new(trace.clone());
@@ -118,7 +117,7 @@ impl Handler {
118117
step_lines_loader,
119118
dap_client: DapClient::default(),
120119
previous_step_id: StepId(0),
121-
rr: RRDispatcher::new(),
120+
rr: RRDispatcher::new(ct_rr_args),
122121
resulting_dap_messages: vec![],
123122
raw_diff_index: None,
124123
}
@@ -288,10 +287,10 @@ impl Handler {
288287
match self.trace_kind {
289288
TraceKind::DB => {
290289
self.step_id_jump(StepId(0));
291-
},
290+
}
292291
TraceKind::RR => {
293292
self.rr.run_to_entry()?;
294-
},
293+
}
295294
}
296295
self.complete_move(true)?;
297296
Ok(())

src/db-backend/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ pub mod dap_error;
3030
pub mod dap_server;
3131
pub mod dap_types;
3232
pub mod db;
33-
pub mod distinct_vec;
3433
pub mod diff;
34+
pub mod distinct_vec;
3535
pub mod event_db;
3636
pub mod expr_loader;
3737
pub mod flow_preloader;
3838
pub mod handler;
3939
pub mod lang;
4040
pub mod paths;
4141
pub mod program_search_tool;
42+
pub mod query;
4243
pub mod rr_dispatcher;
4344
pub mod step_lines_loader;
4445
pub mod task;

src/db-backend/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ mod handler;
3838
mod lang;
3939
mod paths;
4040
mod program_search_tool;
41+
mod query;
4142
mod rr_dispatcher;
4243
mod step_lines_loader;
4344
mod task;

src/db-backend/src/query.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
#[derive(Debug, Clone, Serialize, Deserialize)]
4+
#[serde(tag = "kind")]
5+
pub enum CtRRQuery {
6+
RunToEntry,
7+
}

0 commit comments

Comments
 (0)