Switched from serde_json to bincode for the data.

This commit is contained in:
Filipe Rodrigues 2023-05-31 08:18:09 +01:00
parent 44db1aa708
commit bf72e0f3d0
10 changed files with 44 additions and 4 deletions

View File

@ -1,5 +1,6 @@
{
"cSpell.words": [
"bincode",
"byteorder",
"femto",
"FEMTOS",

27
Cargo.lock generated
View File

@ -74,6 +74,25 @@ dependencies = [
"num-traits",
]
[[package]]
name = "bincode"
version = "2.0.0-rc.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f11ea1a0346b94ef188834a65c068a03aec181c94896d481d7a0a40d85b0ce95"
dependencies = [
"bincode_derive",
"serde",
]
[[package]]
name = "bincode_derive"
version = "2.0.0-rc.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e30759b3b99a1b802a7a3aa21c85c3ded5c28e1c83170d82d70f08bbf7f3e4c"
dependencies = [
"virtue",
]
[[package]]
name = "bitflags"
version = "1.3.2"
@ -205,6 +224,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"average",
"bincode",
"byteorder",
"clap",
"extend",
@ -221,6 +241,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"average",
"bincode",
"clap",
"ftmemsim",
"ftmemsim-util",
@ -601,6 +622,12 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "virtue"
version = "0.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dcc60c0624df774c82a0ef104151231d37da4962957d691c011c852b2473314"
[[package]]
name = "winapi"
version = "0.3.9"

View File

@ -16,6 +16,7 @@ tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
serde = { version = "1.0.163", features = ["derive"] }
serde_json = "1.0.96"
bincode = "2.0.0-rc.3"
gnuplot = "0.0.38"
# Workspace members

View File

@ -26,7 +26,7 @@ cargo build -p ftmemsim -p ftmemsim-graphs
pids=""
for ram_capacity in $RAM_CAPACITIES; do
config_file="config/$ram_capacity.json"
output_file="output/$ram_capacity.json"
output_file="output/$ram_capacity.bin"
log_file="logs/$ram_capacity.json"
graph_migrations_file="graphs/migrations-$ram_capacity.$GRAPH_OUTPUT_FORMAT"
graph_migrations_hist_file="graphs/migrations-hist-$ram_capacity.$GRAPH_OUTPUT_FORMAT"

View File

@ -12,5 +12,6 @@ serde_json = { workspace = true }
itertools = { workspace = true }
gnuplot = { workspace = true }
average = { workspace = true }
bincode = { workspace = true }
ftmemsim = { workspace = true }
ftmemsim-util = { workspace = true }

View File

@ -31,7 +31,8 @@ fn main() -> Result<(), anyhow::Error> {
// Parse the input file
let data = {
let data_file = std::fs::File::open(args.input_file).context("Unable to open input file")?;
serde_json::from_reader::<_, ftmemsim::data::Data>(data_file).context("Unable to parse input file")?
bincode::decode_from_std_read::<ftmemsim::data::Data, _, _>(&mut &data_file, bincode::config::standard())
.context("Unable to parse input file")?
};
tracing::info!("Read data file");

View File

@ -13,4 +13,5 @@ extend = { workspace = true }
itertools = { workspace = true }
serde = { workspace = true }
tracing = { workspace = true }
bincode = { workspace = true }
ftmemsim-util = { workspace = true }

View File

@ -118,7 +118,8 @@ fn main() -> Result<(), anyhow::Error> {
};
let output_file = fs::File::create(output_path).context("Unable to create output file")?;
serde_json::to_writer(output_file, &data).context("Unable to write to output file")?;
bincode::encode_into_std_write(data, &mut &output_file, bincode::config::standard())
.context("Unable to write to output file")?;
}
Ok(())

View File

@ -6,6 +6,7 @@ use std::collections::BTreeMap;
/// Output data
#[derive(Debug)]
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(bincode::Encode, bincode::Decode)]
pub struct Data {
pub hemem: HeMemData,
}
@ -13,6 +14,7 @@ pub struct Data {
/// Hemem output data
#[derive(Debug)]
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(bincode::Encode, bincode::Decode)]
pub struct HeMemData {
pub page_accesses: PageAccesses,
pub page_migrations: PageMigrations,
@ -21,6 +23,7 @@ pub struct HeMemData {
/// Page accesses
#[derive(Debug)]
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(bincode::Encode, bincode::Decode)]
pub struct PageAccesses {
pub accesses: Vec<PageAccess>,
}
@ -28,6 +31,7 @@ pub struct PageAccesses {
/// Page access
#[derive(Debug)]
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(bincode::Encode, bincode::Decode)]
pub struct PageAccess {
pub page_ptr: u64,
pub time: u64,
@ -42,6 +46,7 @@ pub struct PageAccess {
/// Page access kind
#[derive(Debug)]
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(bincode::Encode, bincode::Decode)]
pub enum PageAccessKind {
Read,
Write,
@ -50,6 +55,7 @@ pub enum PageAccessKind {
/// Page migrations
#[derive(Debug)]
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(bincode::Encode, bincode::Decode)]
pub struct PageMigrations {
// Note: We use a `BTreeMap` to ensure the order of the migrations
// is always the same, as well as to sort it by page.
@ -61,6 +67,7 @@ pub struct PageMigrations {
/// Page migration
#[derive(Debug)]
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(bincode::Encode, bincode::Decode)]
pub struct PageMigration {
pub prev_mem_idx: Option<usize>,
pub cur_mem_idx: usize,

2
run.sh
View File

@ -13,7 +13,7 @@ PROFILE="release"
TRACE_FILE="resources/traces/bfs.g17.n100.t1.trace"
#TRACE_FILE="resources/traces/bc.g18.n100.t1.trace"
OUTPUT_FILE="resources/data/output.json"
OUTPUT_FILE="resources/data/output.bin"
CONFIG="config.json"