mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 18:15:04 +02:00
Finish removing profile
command and related data (#10807)
This commit is contained in:
@ -55,36 +55,30 @@ impl Command for Metadata {
|
||||
let origin = stack.get_var_with_origin(*var_id, *span)?;
|
||||
|
||||
Ok(
|
||||
build_metadata_record(&origin, input.metadata().as_deref(), head)
|
||||
build_metadata_record(&origin, input.metadata().as_ref(), head)
|
||||
.into_pipeline_data(),
|
||||
)
|
||||
}
|
||||
_ => {
|
||||
let val: Value = call.req(engine_state, stack, 0)?;
|
||||
Ok(
|
||||
build_metadata_record(&val, input.metadata().as_deref(), head)
|
||||
.into_pipeline_data(),
|
||||
)
|
||||
Ok(build_metadata_record(&val, input.metadata().as_ref(), head)
|
||||
.into_pipeline_data())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let val: Value = call.req(engine_state, stack, 0)?;
|
||||
Ok(
|
||||
build_metadata_record(&val, input.metadata().as_deref(), head)
|
||||
.into_pipeline_data(),
|
||||
)
|
||||
Ok(build_metadata_record(&val, input.metadata().as_ref(), head)
|
||||
.into_pipeline_data())
|
||||
}
|
||||
}
|
||||
Some(_) => {
|
||||
let val: Value = call.req(engine_state, stack, 0)?;
|
||||
Ok(
|
||||
build_metadata_record(&val, input.metadata().as_deref(), head)
|
||||
.into_pipeline_data(),
|
||||
)
|
||||
Ok(build_metadata_record(&val, input.metadata().as_ref(), head)
|
||||
.into_pipeline_data())
|
||||
}
|
||||
None => {
|
||||
let mut record = Record::new();
|
||||
if let Some(x) = input.metadata().as_deref() {
|
||||
if let Some(x) = input.metadata().as_ref() {
|
||||
match x {
|
||||
PipelineMetadata {
|
||||
data_source: DataSource::Ls,
|
||||
@ -92,9 +86,6 @@ impl Command for Metadata {
|
||||
PipelineMetadata {
|
||||
data_source: DataSource::HtmlThemes,
|
||||
} => record.push("source", Value::string("into html --list", head)),
|
||||
PipelineMetadata {
|
||||
data_source: DataSource::Profiling(values),
|
||||
} => record.push("profiling", Value::list(values.clone(), head)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,9 +133,6 @@ fn build_metadata_record(arg: &Value, metadata: Option<&PipelineMetadata>, head:
|
||||
PipelineMetadata {
|
||||
data_source: DataSource::HtmlThemes,
|
||||
} => record.push("source", Value::string("into html --list", head)),
|
||||
PipelineMetadata {
|
||||
data_source: DataSource::Profiling(values),
|
||||
} => record.push("profiling", Value::list(values.clone(), head)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ mod info;
|
||||
mod inspect;
|
||||
mod inspect_table;
|
||||
mod metadata;
|
||||
mod profile;
|
||||
mod timeit;
|
||||
mod view;
|
||||
mod view_files;
|
||||
@ -19,7 +18,6 @@ pub use info::DebugInfo;
|
||||
pub use inspect::Inspect;
|
||||
pub use inspect_table::build_table;
|
||||
pub use metadata::Metadata;
|
||||
pub use profile::Profile;
|
||||
pub use timeit::TimeIt;
|
||||
pub use view::View;
|
||||
pub use view_files::ViewFiles;
|
||||
|
@ -1,102 +0,0 @@
|
||||
use nu_engine::{eval_block, CallExt};
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Closure, Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, DataSource, Example, IntoPipelineData, PipelineData, PipelineMetadata, Signature,
|
||||
Spanned, SyntaxShape, Type, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Profile;
|
||||
|
||||
impl Command for Profile {
|
||||
fn name(&self) -> &str {
|
||||
"profile"
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Profile each pipeline element in a closure."
|
||||
}
|
||||
|
||||
fn extra_usage(&self) -> &str {
|
||||
r#"The command collects run time of every pipeline element, recursively stepping into child closures
|
||||
until a maximum depth. Optionally, it also collects the source code and intermediate values.
|
||||
|
||||
Current known limitations are:
|
||||
* profiling data from subexpressions is not tracked
|
||||
* it does not step into loop iterations"#
|
||||
}
|
||||
|
||||
fn signature(&self) -> nu_protocol::Signature {
|
||||
Signature::build("profile")
|
||||
.required(
|
||||
"closure",
|
||||
SyntaxShape::Closure(Some(vec![SyntaxShape::Any])),
|
||||
"the closure to run",
|
||||
)
|
||||
.switch("source", "Collect source code in the report", Some('s'))
|
||||
.switch("values", "Collect values in the report", Some('v'))
|
||||
.named(
|
||||
"max-depth",
|
||||
SyntaxShape::Int,
|
||||
"How many levels of blocks to step into (default: 1)",
|
||||
Some('d'),
|
||||
)
|
||||
.input_output_types(vec![(Type::Any, Type::Table(vec![]))])
|
||||
.allow_variants_without_examples(true)
|
||||
.category(Category::Debug)
|
||||
}
|
||||
|
||||
fn run(
|
||||
&self,
|
||||
engine_state: &EngineState,
|
||||
stack: &mut Stack,
|
||||
call: &Call,
|
||||
input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
let capture_block: Spanned<Closure> = call.req(engine_state, stack, 0)?;
|
||||
let block = engine_state.get_block(capture_block.item.block_id);
|
||||
|
||||
let redirect_stdout = call.redirect_stdout;
|
||||
let redirect_stderr = call.redirect_stderr;
|
||||
|
||||
let mut stack = stack.captures_to_stack(&capture_block.item.captures);
|
||||
|
||||
let input_val = input.into_value(call.head);
|
||||
|
||||
if let Some(var) = block.signature.get_positional(0) {
|
||||
if let Some(var_id) = &var.var_id {
|
||||
stack.add_var(*var_id, input_val.clone());
|
||||
}
|
||||
}
|
||||
|
||||
let result = if let Some(PipelineMetadata {
|
||||
data_source: DataSource::Profiling(values),
|
||||
}) = eval_block(
|
||||
engine_state,
|
||||
&mut stack,
|
||||
block,
|
||||
input_val.into_pipeline_data(),
|
||||
redirect_stdout,
|
||||
redirect_stderr,
|
||||
)?
|
||||
.metadata()
|
||||
.map(|m| *m)
|
||||
{
|
||||
Value::list(values, call.head)
|
||||
} else {
|
||||
Value::nothing(call.head)
|
||||
};
|
||||
|
||||
Ok(result.into_pipeline_data())
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![Example {
|
||||
description:
|
||||
"Profile some code, stepping into the `spam` command and collecting source.",
|
||||
example: r#"def spam [] { "spam" }; profile {|| spam | str length } --max-depth 2 --source"#,
|
||||
result: None,
|
||||
}]
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user