mirror of
https://github.com/fluencelabs/aquavm
synced 2024-12-04 15:20:16 +00:00
decouple instruction tracker to a separate crate (#160)
This commit is contained in:
parent
e282a93ce7
commit
4251a36842
5
Cargo.lock
generated
5
Cargo.lock
generated
@ -15,6 +15,7 @@ dependencies = [
|
|||||||
name = "air"
|
name = "air"
|
||||||
version = "0.15.0"
|
version = "0.15.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"air-execution-info-collector",
|
||||||
"air-interpreter-data",
|
"air-interpreter-data",
|
||||||
"air-interpreter-interface",
|
"air-interpreter-interface",
|
||||||
"air-log-targets",
|
"air-log-targets",
|
||||||
@ -41,6 +42,10 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "air-execution-info-collector"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "air-interpreter"
|
name = "air-interpreter"
|
||||||
version = "0.15.0"
|
version = "0.15.0"
|
||||||
|
@ -4,6 +4,7 @@ members = [
|
|||||||
"air-interpreter",
|
"air-interpreter",
|
||||||
"avm/server",
|
"avm/server",
|
||||||
"crates/air-lib/air-parser",
|
"crates/air-lib/air-parser",
|
||||||
|
"crates/air-lib/execution-info-collector",
|
||||||
"crates/air-lib/interpreter-data",
|
"crates/air-lib/interpreter-data",
|
||||||
"crates/air-lib/interpreter-interface",
|
"crates/air-lib/interpreter-interface",
|
||||||
"crates/air-lib/log-targets",
|
"crates/air-lib/log-targets",
|
||||||
|
@ -16,6 +16,7 @@ doctest = false
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
air-parser = { path = "../crates/air-lib/air-parser" }
|
air-parser = { path = "../crates/air-lib/air-parser" }
|
||||||
|
air-execution-info-collector = { path = "../crates/air-lib/execution-info-collector" }
|
||||||
air-interpreter-data = { path = "../crates/air-lib/interpreter-data" }
|
air-interpreter-data = { path = "../crates/air-lib/interpreter-data" }
|
||||||
air-interpreter-interface = { path = "../crates/air-lib/interpreter-interface" }
|
air-interpreter-interface = { path = "../crates/air-lib/interpreter-interface" }
|
||||||
air-log-targets = { path = "../crates/air-lib/log-targets" }
|
air-log-targets = { path = "../crates/air-lib/log-targets" }
|
||||||
|
@ -14,12 +14,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use super::InstrTracker;
|
|
||||||
use super::LastErrorDescriptor;
|
use super::LastErrorDescriptor;
|
||||||
use super::LastErrorWithTetraplet;
|
use super::LastErrorWithTetraplet;
|
||||||
use crate::execution_step::boxed_value::Scalar;
|
use crate::execution_step::boxed_value::Scalar;
|
||||||
use crate::execution_step::boxed_value::Stream;
|
use crate::execution_step::boxed_value::Stream;
|
||||||
|
|
||||||
|
use air_execution_info_collector::InstructionTracker;
|
||||||
use air_interpreter_interface::*;
|
use air_interpreter_interface::*;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
@ -67,7 +67,7 @@ pub(crate) struct ExecutionCtx<'i> {
|
|||||||
pub met_folds: VecDeque<&'i str>,
|
pub met_folds: VecDeque<&'i str>,
|
||||||
|
|
||||||
/// Tracker of all met instructions.
|
/// Tracker of all met instructions.
|
||||||
pub tracker: InstrTracker,
|
pub tracker: InstructionTracker,
|
||||||
|
|
||||||
/// Last call request id that was used as an id for call request in outcome.
|
/// Last call request id that was used as an id for call request in outcome.
|
||||||
pub last_call_request_id: u32,
|
pub last_call_request_id: u32,
|
||||||
|
@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) struct InstrTracker {
|
|
||||||
pub(crate) ap: ApTracker,
|
|
||||||
pub(crate) call: CallTracker,
|
|
||||||
pub(crate) fold: FoldTracker,
|
|
||||||
pub(crate) match_count: u32,
|
|
||||||
pub(crate) mismatch_count: u32,
|
|
||||||
pub(crate) next_count: u32,
|
|
||||||
pub(crate) null_count: u32,
|
|
||||||
pub(crate) par: ParTracker,
|
|
||||||
pub(crate) seq_count: u32,
|
|
||||||
pub(crate) xor_count: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) struct ApTracker {
|
|
||||||
pub(crate) seen_count: u32,
|
|
||||||
pub(crate) executed_count: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) struct CallTracker {
|
|
||||||
pub(crate) seen_count: u32,
|
|
||||||
pub(crate) executed_count: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) struct FoldTracker {
|
|
||||||
pub(crate) seen_scalar_count: u32,
|
|
||||||
pub(crate) seen_stream_count: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) struct ParTracker {
|
|
||||||
pub(crate) seen_count: u32,
|
|
||||||
pub(crate) executed_count: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl InstrTracker {
|
|
||||||
pub(crate) fn meet_call(&mut self) {
|
|
||||||
self.call.seen_count += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) fn meet_executed_call(&mut self) {
|
|
||||||
self.call.executed_count += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn meet_fold_stream(&mut self) {
|
|
||||||
self.fold.seen_stream_count += 1;
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,10 +16,8 @@
|
|||||||
|
|
||||||
mod context;
|
mod context;
|
||||||
mod error_descriptor;
|
mod error_descriptor;
|
||||||
mod instructions_tracker;
|
|
||||||
|
|
||||||
pub(crate) use context::*;
|
pub(crate) use context::*;
|
||||||
pub use error_descriptor::LastError;
|
pub use error_descriptor::LastError;
|
||||||
pub(crate) use error_descriptor::LastErrorDescriptor;
|
pub(crate) use error_descriptor::LastErrorDescriptor;
|
||||||
pub(crate) use error_descriptor::LastErrorWithTetraplet;
|
pub(crate) use error_descriptor::LastErrorWithTetraplet;
|
||||||
pub(crate) use instructions_tracker::*;
|
|
||||||
|
14
crates/air-lib/execution-info-collector/Cargo.toml
Normal file
14
crates/air-lib/execution-info-collector/Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
[package]
|
||||||
|
name = "air-execution-info-collector"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Implementation of AIR execution info collector"
|
||||||
|
authors = ["Fluence Labs"]
|
||||||
|
edition = "2018"
|
||||||
|
license = "Apache-2.0"
|
||||||
|
publish = false
|
||||||
|
keywords = ["fluence", "air", "webassembly", "programming-language"]
|
||||||
|
categories = ["wasm"]
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "air_execution_info_collector"
|
||||||
|
path = "src/lib.rs"
|
3
crates/air-lib/execution-info-collector/README.md
Normal file
3
crates/air-lib/execution-info-collector/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
## AIR execution info collector
|
||||||
|
|
||||||
|
It's important to capture some info about AIR scripts execution and then analyze it. This crate provides implementation of instruction info collector that is intended to collect various info about executed instructions.
|
@ -0,0 +1,114 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/// Intended to track a number of executed instruction of each type. For instructions that
|
||||||
|
/// have a corresponding state in data, it tracks number of executed instructions on
|
||||||
|
/// current peer (executed) and overall number (seen) of met instructions of such type.
|
||||||
|
#[derive(Default, Debug, PartialEq, Eq)]
|
||||||
|
pub struct InstructionTracker {
|
||||||
|
pub ap: ApTracker,
|
||||||
|
pub call: CallTracker,
|
||||||
|
pub fold: FoldTracker,
|
||||||
|
pub match_count: u32,
|
||||||
|
pub mismatch_count: u32,
|
||||||
|
pub next_count: u32,
|
||||||
|
pub null_count: u32,
|
||||||
|
pub par: ParTracker,
|
||||||
|
pub seq_count: u32,
|
||||||
|
pub xor_count: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Debug, PartialEq, Eq)]
|
||||||
|
pub struct ApTracker {
|
||||||
|
pub seen_count: u32,
|
||||||
|
pub executed_count: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Debug, PartialEq, Eq)]
|
||||||
|
pub struct CallTracker {
|
||||||
|
pub seen_count: u32,
|
||||||
|
pub executed_count: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Debug, PartialEq, Eq)]
|
||||||
|
pub struct FoldTracker {
|
||||||
|
pub seen_scalar_count: u32,
|
||||||
|
pub seen_stream_count: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Debug, PartialEq, Eq)]
|
||||||
|
pub struct ParTracker {
|
||||||
|
pub seen_count: u32,
|
||||||
|
pub executed_count: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl InstructionTracker {
|
||||||
|
pub fn meet_ap(&mut self) {
|
||||||
|
self.ap.seen_count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn meet_executed_ap(&mut self) {
|
||||||
|
self.ap.executed_count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn meet_call(&mut self) {
|
||||||
|
self.call.seen_count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn meet_executed_call(&mut self) {
|
||||||
|
self.call.executed_count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn meet_fold_scalar(&mut self) {
|
||||||
|
self.fold.seen_scalar_count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn meet_fold_stream(&mut self) {
|
||||||
|
self.fold.seen_stream_count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn meet_match(&mut self) {
|
||||||
|
self.match_count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn meet_mismatch(&mut self) {
|
||||||
|
self.mismatch_count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn meet_next(&mut self) {
|
||||||
|
self.next_count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn meet_null(&mut self) {
|
||||||
|
self.null_count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn meet_par(&mut self) {
|
||||||
|
self.par.seen_count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn meet_executed_par(&mut self) {
|
||||||
|
self.par.executed_count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn meet_seq(&mut self) {
|
||||||
|
self.seq_count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn meet_xor(&mut self) {
|
||||||
|
self.xor_count += 1;
|
||||||
|
}
|
||||||
|
}
|
19
crates/air-lib/execution-info-collector/src/lib.rs
Normal file
19
crates/air-lib/execution-info-collector/src/lib.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
mod instructions_tracker;
|
||||||
|
|
||||||
|
pub use instructions_tracker::*;
|
Loading…
Reference in New Issue
Block a user