Skip to content

Commit 6088830

Browse files
author
Pavel Sedlacek
committed
Versioned output
This commit adds proper versioning to the output files and aggregates all code related to the structure of the output file in a single place.
1 parent ea34db8 commit 6088830

11 files changed

Lines changed: 378 additions & 222 deletions

File tree

‎README.md‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ information from the trace.
5959
Usage: Ros2TraceAnalyzer [OPTIONS] <COMMAND>
6060
6161
Commands:
62-
analyze Analyze a ROS 2 trace and generate graphs, JSON or bundle outputs
62+
analyze Analyze a ROS 2 trace and store the result either as a binary bundle or separate files. See the extract subcommand for how to work with the binary bundle
6363
chart Render a chart of a specific property of a ROS 2 interface
6464
viewer Start a .dot viewer capable of generating charts on demand
65-
extract Retreive data from bundled analysis results file into JSON format
65+
extract Retrieve data from binary bundle produced by the analysis
6666
help Print this message or the help of the given subcommand(s)
6767
6868
Options:
@@ -76,7 +76,7 @@ This command analyzes the traces and saves relevant information for later use in
7676

7777
<!-- `$ cargo run analyze --help` -->
7878
```
79-
Analyze a ROS 2 trace and generate graphs, JSON or bundle outputs
79+
Analyze a ROS 2 trace and store the result either as a binary bundle or separate files. See the extract subcommand for how to work with the binary bundle
8080
8181
Usage: Ros2TraceAnalyzer analyze [OPTIONS] <TRACE_PATHS>...
8282
@@ -140,7 +140,7 @@ Options:
140140
When analysis output filename is specified and it is not an absolute path, it is resolved relative to `OUT_DIR`.
141141
142142
--legacy-output
143-
Flag whether to bundle all outputs into a single file or export each analysis as a separate file
143+
Store the results into multiple files rather than to the binary bundle
144144
145145
--quantiles <QUANTILES>
146146
Quantiles to compute for the latency and duration analysis.
@@ -294,16 +294,16 @@ Options:
294294
-v, --verbose...
295295
Increase logging verbosity
296296
297-
-i, --input-path <FILENAME>
297+
-i, --input <FILENAME>
298298
Path to the r2ta_results.sqlite file from which to retreive the data
299299
300300
[default: r2ta_results.sqlite]
301301
302302
-q, --quiet...
303303
Decrease logging verbosity
304304
305-
-o, --output-path <FILENAME>
306-
305+
-o, --output <FILENAME>
306+
Store the chart data to the given file
307307
308308
-c, --clean
309309
Indicates whether the chart should be rendered from scratch.
@@ -369,7 +369,7 @@ This command retrieves various data from the "binary bundle" produced by the ana
369369

370370
<!-- `$ cargo run extract --help` -->
371371
```
372-
Retreive data from bundled analysis results file into JSON format
372+
Retrieve data from binary bundle produced by the analysis
373373
374374
Usage: Ros2TraceAnalyzer extract [OPTIONS] <COMMAND>
375375
@@ -379,11 +379,11 @@ Commands:
379379
help Print this message or the help of the given subcommand(s)
380380
381381
Options:
382-
-i, --input-path <FILENAME> Path to the r2ta_results.sqlite file from which to retreive the data [default: r2ta_results.sqlite]
383-
-v, --verbose... Increase logging verbosity
384-
-o, --output-path <FILENAME> File to extract the data to, if not present the data is written to stdout
385-
-q, --quiet... Decrease logging verbosity
386-
-h, --help Print help
382+
-i, --input <FILENAME> Path to the r2ta_results.sqlite file from which to retreive the data [default: r2ta_results.sqlite]
383+
-v, --verbose... Increase logging verbosity
384+
-o, --output <FILENAME> File to extract the data to, if not present the data is written to stdout
385+
-q, --quiet... Decrease logging verbosity
386+
-h, --help Print help
387387
```
388388

389389
[`ros2trace`]: https://index.ros.org/p/ros2trace/

‎src/analyses/mod.rs‎

Lines changed: 20 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use crate::analyses::analysis::AnalysisOutputExt;
77
use crate::analyses::event_iterator::get_buf_writer_for_path;
88
use crate::argsv2::analysis_args::AnalysisArgs;
99
use crate::argsv2::extract_args::AnalysisProperty;
10-
use crate::utils::binary_sql_store::BinarySQLStore;
10+
use crate::utils::binary_sql_store::BinarySqlStore;
11+
use crate::utils::binary_sql_store::v1::{BinarySqlStoreV1, BinarySqlStoreV1Table};
1112

1213
pub mod analysis;
1314
pub mod event_iterator;
@@ -99,32 +100,18 @@ impl Analyses {
99100
if args.bundle_output()
100101
&& let Some(path) = args.binary_bundle_path()
101102
{
102-
let mut store = BinarySQLStore::new(&path)?;
103+
let mut store = BinarySqlStoreV1::from_file(&path, true)?;
103104

104105
if let Some(a) = &self.dependency_graph {
105106
let dot_graph = a.display_as_dot(false, false, 1.0);
106107

107-
store.define_table("metadata", &["version int", "graph text"])?;
108-
store.write_into(
109-
"metadata",
110-
"(version, graph)",
111-
[(1, dot_graph.to_string())].into_iter(),
112-
2,
108+
store.insert(
109+
BinarySqlStoreV1Table::Graphs,
110+
[("dependency_graph", dot_graph.to_string())].into_iter(),
113111
)?;
114112

115-
store.define_table(
116-
AnalysisProperty::MessageLatencies.table_name(),
117-
&[
118-
"id int",
119-
"source_node text",
120-
"destination_node text",
121-
"topic text",
122-
"data blob",
123-
],
124-
)?;
125-
store.write_into(
126-
AnalysisProperty::MessageLatencies.table_name(),
127-
"(id, source_node, destination_node, topic, data)",
113+
store.insert(
114+
BinarySqlStoreV1Table::Property(AnalysisProperty::MessageLatencies),
128115
a.message_latencies(&dot_graph).iter().map(|m| {
129116
(
130117
m.id,
@@ -134,16 +121,10 @@ impl Analyses {
134121
postcard::to_allocvec(&m.messages_latencies).unwrap(),
135122
)
136123
}),
137-
5,
138124
)?;
139125

140-
store.define_table(
141-
AnalysisProperty::ActivationDelays.table_name(),
142-
&["id int", "node text", "interface text", "data blob"],
143-
)?;
144-
store.write_into(
145-
AnalysisProperty::ActivationDelays.table_name(),
146-
"(id, node, interface, data)",
126+
store.insert(
127+
BinarySqlStoreV1Table::Property(AnalysisProperty::ActivationDelays),
147128
a.activation_delays(&dot_graph).iter().map(|m| {
148129
(
149130
m.id,
@@ -152,16 +133,10 @@ impl Analyses {
152133
postcard::to_allocvec(&m.activation_delays).unwrap(),
153134
)
154135
}),
155-
4,
156136
)?;
157137

158-
store.define_table(
159-
AnalysisProperty::PublicationDelays.table_name(),
160-
&["id int", "node text", "interface text", "data blob"],
161-
)?;
162-
store.write_into(
163-
AnalysisProperty::PublicationDelays.table_name(),
164-
"(id, node, interface, data)",
138+
store.insert(
139+
BinarySqlStoreV1Table::Property(AnalysisProperty::PublicationDelays),
165140
a.publication_delays(&dot_graph).iter().map(|m| {
166141
(
167142
m.id,
@@ -170,43 +145,30 @@ impl Analyses {
170145
postcard::to_allocvec(&m.publication_delays).unwrap(),
171146
)
172147
}),
173-
4,
174148
)?;
175149

176-
store.define_table(
177-
AnalysisProperty::MessageDelays.table_name(),
178-
&["id int", "node text", "interface text", "data blob"],
179-
)?;
180-
store.write_into(
181-
AnalysisProperty::MessageDelays.table_name(),
182-
"(id, node, interface, data)",
183-
a.message_delays(&dot_graph).iter().map(|m| {
150+
store.insert(
151+
BinarySqlStoreV1Table::Property(AnalysisProperty::CallbackDurations),
152+
a.callback_durations(&dot_graph).iter().map(|m| {
184153
(
185154
m.id,
186155
&m.name.node,
187156
&m.name.interface,
188-
postcard::to_allocvec(&m.messages_delays).unwrap(),
157+
postcard::to_allocvec(&m.callback_durations).unwrap(),
189158
)
190159
}),
191-
4,
192160
)?;
193161

194-
store.define_table(
195-
AnalysisProperty::CallbackDurations.table_name(),
196-
&["id int", "node text", "interface text", "data blob"],
197-
)?;
198-
store.write_into(
199-
AnalysisProperty::CallbackDurations.table_name(),
200-
"(id, node, interface, data)",
201-
a.callback_durations(&dot_graph).iter().map(|m| {
162+
store.insert(
163+
BinarySqlStoreV1Table::Property(AnalysisProperty::MessageDelays),
164+
a.message_delays(&dot_graph).iter().map(|m| {
202165
(
203166
m.id,
204167
&m.name.node,
205168
&m.name.interface,
206-
postcard::to_allocvec(&m.callback_durations).unwrap(),
169+
postcard::to_allocvec(&m.messages_delays).unwrap(),
207170
)
208171
}),
209-
4,
210172
)?;
211173
}
212174
} else {

‎src/argsv2/analysis_args.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub struct AnalysisArgs {
9292
#[arg(long, short = 'o', value_hint = ValueHint::DirPath)]
9393
out_dir: Option<PathBuf>,
9494

95-
/// Flag whether to bundle all outputs into a single file or export each analysis as a separate file
95+
/// Store the results into multiple files rather than to the binary bundle
9696
#[arg(long)]
9797
legacy_output: bool,
9898

‎src/argsv2/chart_args.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ pub struct ChartArgs {
1515
#[clap(long, short = 'i', value_name = "FILENAME", value_hint = ValueHint::FilePath, default_value = analysis_args::filenames::BINARY_BUNDLE)]
1616
input: Option<PathBuf>,
1717

18+
/// Store the chart data to the given file
1819
#[clap(long, short = 'o', value_name = "FILENAME", value_hint = ValueHint::AnyPath)]
19-
output_path: Option<PathBuf>,
20+
output: Option<PathBuf>,
2021

2122
/// Indicates whether the chart should be rendered from scratch.
2223
///
@@ -38,7 +39,7 @@ impl ChartArgs {
3839
}
3940

4041
pub fn output_path(&self) -> Option<&Path> {
41-
self.output_path.as_deref()
42+
self.output.as_deref()
4243
}
4344

4445
pub fn clean(&self) -> bool {

‎src/argsv2/extract_args.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct ExtractArgs {
1313

1414
/// File to extract the data to, if not present the data is written to stdout
1515
#[clap(long, short = 'o', value_name = "FILENAME", value_hint = ValueHint::FilePath)]
16-
output_path: Option<PathBuf>,
16+
output: Option<PathBuf>,
1717

1818
#[clap(subcommand)]
1919
extract_content: ExtractContentArgs,
@@ -36,7 +36,7 @@ impl ExtractArgs {
3636
}
3737

3838
pub fn output_path(&self) -> Option<&Path> {
39-
self.output_path.as_deref()
39+
self.output.as_deref()
4040
}
4141

4242
pub fn content(&self) -> &ExtractContentArgs {
@@ -74,7 +74,7 @@ impl ExtractPropertyArgs {
7474
}
7575
}
7676

77-
#[derive(Debug, Display, ValueEnum, Clone)]
77+
#[derive(Debug, Display, ValueEnum, Clone, PartialEq, Eq, Hash)]
7878
pub enum AnalysisProperty {
7979
/// Callback execution durations
8080
#[display("Callback execution time")]
@@ -99,7 +99,7 @@ pub enum AnalysisProperty {
9999

100100
impl AnalysisProperty {
101101
/// Table name in the binary data blob for this property
102-
pub fn table_name(&self) -> &'static str {
102+
pub const fn table_name(&self) -> &'static str {
103103
match self {
104104
AnalysisProperty::CallbackDurations => "callback_duration",
105105
AnalysisProperty::ActivationDelays => "activations_delay",

‎src/argsv2/mod.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ impl Args {
5252

5353
#[derive(Debug, Subcommand, Clone, derive_more::Display)]
5454
pub enum TracerCommand {
55-
/// Analyze a ROS 2 trace and generate graphs, JSON or bundle outputs
55+
/// Analyze a ROS 2 trace and store the result either as a binary bundle
56+
/// or separate files. See the extract subcommand for how to work with the
57+
/// binary bundle.
5658
#[display("analyze")]
5759
Analyze(Box<analysis_args::AnalysisArgs>),
5860

@@ -64,7 +66,7 @@ pub enum TracerCommand {
6466
#[display("viewer")]
6567
Viewer(viewer_args::ViewerArgs),
6668

67-
/// Retreive data from bundled analysis results file into JSON format
69+
/// Retrieve data from binary bundle produced by the analysis
6870
#[display("extract")]
6971
Extract(#[clap(subcommand)] extract_args::ExtractArgs),
7072
}

0 commit comments

Comments
 (0)