2021-08-24 16:14:15 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2021 Fluence Labs Limited
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-11-24 17:57:14 +03:00
|
|
|
use super::GlobalStreamGens;
|
|
|
|
use super::RestrictedStreamGens;
|
2022-12-26 15:45:14 +07:00
|
|
|
use crate::cid_store::CidStore;
|
2023-01-09 13:22:57 +07:00
|
|
|
use crate::CanonCidAggregate;
|
2022-06-10 08:29:56 +03:00
|
|
|
use crate::ExecutionTrace;
|
2022-12-26 15:45:14 +07:00
|
|
|
use crate::JValue;
|
|
|
|
|
`air-trace` util for measuring AquaVM performance with tracing crate.
`air-trace run` subcommand allows to run AquaVM on any data, it allows to define most AquaVM inputs, providing defaults for most of them, and sets up either human-readable or JSON tracing output, the latter can be later processed by `air-trace stats`.
Anomaly data input is also supported, that is useful for slow data investigation.
Native execution mode can be used for native profiling. Please note, however, that current version cannot be built natively on Apple Sillicon processor yet, as invariably depends on the `avm-server` because of leaking types that should be refactored or hidden. The `--repeat` option can repeat the execution several times for the execution to dominate on input data reading and output.
High-level or rare calls have "info" trace level, instructions are "debug", and sub-instruction calls are "tracing". Over-detailed tracing can induce overhead that spoils timing data.
2022-07-07 14:44:58 +03:00
|
|
|
use air_utils::measure;
|
2023-01-09 13:22:57 +07:00
|
|
|
use polyplets::SecurityTetraplet;
|
`air-trace` util for measuring AquaVM performance with tracing crate.
`air-trace run` subcommand allows to run AquaVM on any data, it allows to define most AquaVM inputs, providing defaults for most of them, and sets up either human-readable or JSON tracing output, the latter can be later processed by `air-trace stats`.
Anomaly data input is also supported, that is useful for slow data investigation.
Native execution mode can be used for native profiling. Please note, however, that current version cannot be built natively on Apple Sillicon processor yet, as invariably depends on the `avm-server` because of leaking types that should be refactored or hidden. The `--repeat` option can repeat the execution several times for the execution to dominate on input data reading and output.
High-level or rare calls have "info" trace level, instructions are "debug", and sub-instruction calls are "tracing". Over-detailed tracing can induce overhead that spoils timing data.
2022-07-07 14:44:58 +03:00
|
|
|
|
2021-08-24 16:14:15 +03:00
|
|
|
use serde::Deserialize;
|
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
/// The AIR interpreter could be considered as a function
|
|
|
|
/// f(prev_data: InterpreterData, current_data: InterpreterData, ... ) -> (result_data: InterpreterData, ...).
|
|
|
|
/// This function receives prev and current data and produces a result data. All these data
|
|
|
|
/// have the following format.
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
pub struct InterpreterData {
|
2022-04-15 22:25:03 +03:00
|
|
|
/// Trace of AIR execution, which contains executed call, par, fold, and ap states.
|
2021-08-24 16:14:15 +03:00
|
|
|
pub trace: ExecutionTrace,
|
|
|
|
|
2021-11-24 17:57:14 +03:00
|
|
|
/// Contains maximum generation for each global stream. This info will be used while merging
|
|
|
|
/// values in streams. This field is also needed for backward compatibility with
|
|
|
|
/// <= 0.2.1 versions.
|
|
|
|
#[serde(rename = "streams")] // for compatibility with versions <= 0.2.1
|
|
|
|
pub global_streams: GlobalStreamGens,
|
2021-08-24 16:14:15 +03:00
|
|
|
|
|
|
|
/// Version of this data format.
|
|
|
|
pub version: semver::Version,
|
2021-10-04 10:58:00 +03:00
|
|
|
|
|
|
|
/// Last exposed to a peer call request id. All next call request ids will be bigger than this.
|
|
|
|
#[serde(default)]
|
|
|
|
#[serde(rename = "lcid")]
|
|
|
|
pub last_call_request_id: u32,
|
2021-11-24 17:57:14 +03:00
|
|
|
|
|
|
|
/// Contains maximum generation for each private stream. This info will be used while merging
|
|
|
|
/// values in streams.
|
|
|
|
#[serde(default)]
|
|
|
|
#[serde(rename = "r_streams")]
|
|
|
|
pub restricted_streams: RestrictedStreamGens,
|
2022-10-13 12:50:32 +03:00
|
|
|
|
|
|
|
/// Version of interpreter produced this data.
|
|
|
|
pub interpreter_version: semver::Version,
|
2022-12-26 15:45:14 +07:00
|
|
|
|
2023-01-09 13:22:57 +07:00
|
|
|
/// CID-to-somethings mappings.
|
|
|
|
pub cid_info: CidInfo,
|
2021-08-24 16:14:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl InterpreterData {
|
2022-10-13 12:50:32 +03:00
|
|
|
pub fn new(interpreter_version: semver::Version) -> Self {
|
2021-08-24 16:14:15 +03:00
|
|
|
Self {
|
2022-10-13 12:50:32 +03:00
|
|
|
trace: ExecutionTrace::default(),
|
|
|
|
global_streams: GlobalStreamGens::new(),
|
|
|
|
version: crate::data_version().clone(),
|
2021-10-04 10:58:00 +03:00
|
|
|
last_call_request_id: 0,
|
2022-10-13 12:50:32 +03:00
|
|
|
restricted_streams: RestrictedStreamGens::new(),
|
|
|
|
interpreter_version,
|
2023-01-09 13:22:57 +07:00
|
|
|
cid_info: <_>::default(),
|
2021-08-24 16:14:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-09 13:22:57 +07:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2021-10-04 10:58:00 +03:00
|
|
|
pub fn from_execution_result(
|
|
|
|
trace: ExecutionTrace,
|
2021-11-24 17:57:14 +03:00
|
|
|
streams: GlobalStreamGens,
|
|
|
|
restricted_streams: RestrictedStreamGens,
|
2023-01-09 13:22:57 +07:00
|
|
|
cid_info: CidInfo,
|
2021-10-04 10:58:00 +03:00
|
|
|
last_call_request_id: u32,
|
2022-10-13 12:50:32 +03:00
|
|
|
interpreter_version: semver::Version,
|
2021-10-04 10:58:00 +03:00
|
|
|
) -> Self {
|
2021-08-24 16:14:15 +03:00
|
|
|
Self {
|
|
|
|
trace,
|
2021-11-24 17:57:14 +03:00
|
|
|
global_streams: streams,
|
2022-10-13 12:50:32 +03:00
|
|
|
version: crate::data_version().clone(),
|
2021-10-04 10:58:00 +03:00
|
|
|
last_call_request_id,
|
2021-11-24 17:57:14 +03:00
|
|
|
restricted_streams,
|
2022-10-13 12:50:32 +03:00
|
|
|
interpreter_version,
|
2023-01-09 13:22:57 +07:00
|
|
|
cid_info,
|
2021-08-24 16:14:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Tries to de InterpreterData from slice according to the data version.
|
2022-10-13 12:50:32 +03:00
|
|
|
pub fn try_from_slice(
|
|
|
|
slice: &[u8],
|
|
|
|
min_support_version: &semver::Version,
|
|
|
|
) -> Result<Self, serde_json::Error> {
|
2021-08-24 16:14:15 +03:00
|
|
|
// treat empty slice as an empty interpreter data allows abstracting from
|
|
|
|
// the internal format for empty data.
|
|
|
|
if slice.is_empty() {
|
2022-10-13 12:50:32 +03:00
|
|
|
return Ok(Self::new(min_support_version.clone()));
|
2021-08-24 16:14:15 +03:00
|
|
|
}
|
|
|
|
|
`air-trace` util for measuring AquaVM performance with tracing crate.
`air-trace run` subcommand allows to run AquaVM on any data, it allows to define most AquaVM inputs, providing defaults for most of them, and sets up either human-readable or JSON tracing output, the latter can be later processed by `air-trace stats`.
Anomaly data input is also supported, that is useful for slow data investigation.
Native execution mode can be used for native profiling. Please note, however, that current version cannot be built natively on Apple Sillicon processor yet, as invariably depends on the `avm-server` because of leaking types that should be refactored or hidden. The `--repeat` option can repeat the execution several times for the execution to dominate on input data reading and output.
High-level or rare calls have "info" trace level, instructions are "debug", and sub-instruction calls are "tracing". Over-detailed tracing can induce overhead that spoils timing data.
2022-07-07 14:44:58 +03:00
|
|
|
measure!(
|
|
|
|
serde_json::from_slice(slice),
|
|
|
|
tracing::Level::INFO,
|
|
|
|
"serde_json::from_slice"
|
|
|
|
)
|
2021-08-24 16:14:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-09 13:22:57 +07:00
|
|
|
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
|
|
|
|
pub struct CidInfo {
|
|
|
|
/// Map CID to value
|
|
|
|
pub value_store: CidStore<JValue>,
|
|
|
|
|
|
|
|
/// Map CID to a tetraplet
|
|
|
|
pub tetraplet_store: CidStore<SecurityTetraplet>,
|
|
|
|
|
|
|
|
/// Map CID to a canon value
|
|
|
|
pub canon_store: CidStore<CanonCidAggregate>,
|
|
|
|
}
|
|
|
|
|
2021-10-04 10:58:00 +03:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
use serde::Deserialize;
|
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
#[test]
|
2022-10-13 12:50:32 +03:00
|
|
|
#[ignore] // TODO: fix tests
|
2021-10-04 10:58:00 +03:00
|
|
|
fn compatible_with_0_2_0_version() {
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
struct InterpreterData0_2_0 {
|
|
|
|
pub trace: ExecutionTrace,
|
2021-11-24 17:57:14 +03:00
|
|
|
pub streams: GlobalStreamGens,
|
2021-10-04 10:58:00 +03:00
|
|
|
pub version: semver::Version,
|
|
|
|
}
|
|
|
|
|
2021-11-24 17:57:14 +03:00
|
|
|
// test 0.2.0 to 0.2.2 conversion
|
2021-10-04 10:58:00 +03:00
|
|
|
let data_0_2_0 = InterpreterData0_2_0 {
|
|
|
|
trace: ExecutionTrace::default(),
|
2021-11-24 17:57:14 +03:00
|
|
|
streams: GlobalStreamGens::default(),
|
2021-10-04 10:58:00 +03:00
|
|
|
version: semver::Version::new(0, 2, 0),
|
|
|
|
};
|
|
|
|
|
|
|
|
let data_0_2_0_se = serde_json::to_vec(&data_0_2_0).unwrap();
|
|
|
|
let data_0_2_1 = serde_json::from_slice::<InterpreterData>(&data_0_2_0_se);
|
|
|
|
assert!(data_0_2_1.is_ok());
|
|
|
|
|
2021-11-24 17:57:14 +03:00
|
|
|
// test 0.2.2 to 0.2.0 conversion
|
2022-10-13 12:50:32 +03:00
|
|
|
let data_0_2_2 = InterpreterData::new(semver::Version::new(1, 1, 1));
|
2021-11-24 17:57:14 +03:00
|
|
|
let data_0_2_2_se = serde_json::to_vec(&data_0_2_2).unwrap();
|
|
|
|
let data_0_2_0 = serde_json::from_slice::<InterpreterData0_2_0>(&data_0_2_2_se);
|
|
|
|
assert!(data_0_2_0.is_ok());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-10-13 12:50:32 +03:00
|
|
|
#[ignore] // TODO: fix tests
|
2021-11-24 17:57:14 +03:00
|
|
|
fn compatible_with_0_2_1_version() {
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
struct InterpreterData0_2_1 {
|
|
|
|
pub trace: ExecutionTrace,
|
|
|
|
pub streams: GlobalStreamGens,
|
|
|
|
pub version: semver::Version,
|
|
|
|
#[serde(default)]
|
|
|
|
#[serde(rename = "lcid")]
|
|
|
|
pub last_call_request_id: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
// test 0.2.1 to 0.2.2 conversion
|
|
|
|
let data_0_2_1 = InterpreterData0_2_1 {
|
|
|
|
trace: ExecutionTrace::default(),
|
|
|
|
streams: GlobalStreamGens::default(),
|
|
|
|
version: semver::Version::new(0, 2, 1),
|
|
|
|
last_call_request_id: 1,
|
|
|
|
};
|
|
|
|
|
2021-10-04 10:58:00 +03:00
|
|
|
let data_0_2_1_se = serde_json::to_vec(&data_0_2_1).unwrap();
|
2021-11-24 17:57:14 +03:00
|
|
|
let data_0_2_2 = serde_json::from_slice::<InterpreterData>(&data_0_2_1_se);
|
|
|
|
assert!(data_0_2_2.is_ok());
|
|
|
|
|
|
|
|
// test 0.2.2 to 0.2.1 conversion
|
2022-10-13 12:50:32 +03:00
|
|
|
let data_0_2_2 = InterpreterData::new(semver::Version::new(1, 1, 1));
|
2021-11-24 17:57:14 +03:00
|
|
|
let data_0_2_2_se = serde_json::to_vec(&data_0_2_2).unwrap();
|
|
|
|
let data_0_2_0 = serde_json::from_slice::<InterpreterData0_2_1>(&data_0_2_2_se);
|
2021-10-04 10:58:00 +03:00
|
|
|
assert!(data_0_2_0.is_ok());
|
|
|
|
}
|
|
|
|
}
|