Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace tracing #4017

Merged
merged 11 commits into from Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 21 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/gui/config/src/lib.rs
Expand Up @@ -69,5 +69,6 @@ ensogl::read_args! {
skip_min_version_check : bool,
preferred_engine_version : semver::Version,
enable_new_component_browser : bool,
emit_user_timing_measurements : bool,
}
}
2 changes: 1 addition & 1 deletion app/gui/src/controller/searcher/component/group.rs
Expand Up @@ -187,7 +187,7 @@ impl Group {
fn restore_initial_order(&self) {
let mut entries = self.entries.borrow_mut();
if entries.len() != self.initial_entries_order.len() {
tracing::error!(
error!(
"Tried to restore initial order in group where \
`initial_entries_order` is not initialized or up-to-date. Will keep the \
old order."
Expand Down
3 changes: 3 additions & 0 deletions app/gui/src/ide/initializer.rs
Expand Up @@ -75,6 +75,9 @@ impl Initializer {
config::InitialView::Project => view.switch_view_to_project(),
}

if enso_config::ARGS.emit_user_timing_measurements.unwrap_or_default() {
ensogl_app.display.connect_profiler_to_user_timing();
}
let status_bar = view.status_bar().clone_ref();
ensogl_app.display.add_child(&view);
// TODO [mwu] Once IDE gets some well-defined mechanism of reporting
Expand Down
4 changes: 2 additions & 2 deletions app/gui/src/presenter/graph.rs
Expand Up @@ -667,7 +667,7 @@ impl Graph {
let graph_notifications = self.model.controller.subscribe();
let weak = Rc::downgrade(&self.model);
spawn_stream_handler(weak, graph_notifications, move |notification, _model| {
tracing::debug!("Received controller notification {notification:?}");
debug!("Received controller notification {notification:?}");
match notification {
executed::Notification::Graph(graph) => match graph {
Notification::Invalidate => update_view.emit(()),
Expand Down Expand Up @@ -709,7 +709,7 @@ impl Graph {
/// content of a node. For example, the searcher uses this to allow the edit field to have a
/// preview that is different from the actual node AST.
pub fn allow_expression_auto_updates(&self, id: AstNodeId, allow: bool) {
tracing::debug!("Setting auto updates for {id:?} to {allow}");
debug!("Setting auto updates for {id:?} to {allow}");
self.model.state.allow_expression_auto_updates(id, allow);
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/gui/src/presenter/project.rs
Expand Up @@ -137,10 +137,10 @@ impl Model {
self.graph.allow_expression_auto_updates(node, true);
searcher.abort_editing();
} else {
tracing::warn!("When porting editing the AST node of the node view {input_node_view} could not be found.");
warn!("When porting editing the AST node of the node view {input_node_view} could not be found.");
}
} else {
tracing::warn!("Editing aborted without searcher controller.");
warn!("Editing aborted without searcher controller.");
}
}

Expand Down
22 changes: 9 additions & 13 deletions app/gui/src/presenter/searcher.rs
Expand Up @@ -101,7 +101,7 @@ impl Model {
#[profile(Debug)]
fn input_changed(&self, new_input: &str) {
if let Err(err) = self.controller.set_input(new_input.to_owned()) {
tracing::error!("Error while setting new searcher input: {err}.");
error!("Error while setting new searcher input: {err}.");
}
}

Expand All @@ -116,7 +116,7 @@ impl Model {
Some((self.input_view, new_code_and_trees))
}
Err(err) => {
tracing::error!("Error while applying suggestion: {err}.");
error!("Error while applying suggestion: {err}.");
None
}
}
Expand All @@ -126,7 +126,7 @@ impl Model {
/// API.
fn entry_selected_as_suggestion(&self, entry_id: view::searcher::entry::Id) {
if let Err(error) = self.controller.preview_entry_as_suggestion(entry_id) {
tracing::warn!("Failed to preview entry {entry_id:?} because of error: {error:?}.");
warn!("Failed to preview entry {entry_id:?} because of error: {error:?}.");
}
}

Expand All @@ -136,7 +136,7 @@ impl Model {
None => self.controller.commit_node().map(Some),
};
result.unwrap_or_else(|err| {
tracing::error!("Error while executing action: {err}.");
error!("Error while executing action: {err}.");
None
})
}
Expand Down Expand Up @@ -166,11 +166,9 @@ impl Model {
match self.suggestion_for_entry_id(entry_id) {
Ok(suggestion) =>
if let Err(error) = self.controller.preview_suggestion(suggestion) {
tracing::warn!(
"Failed to preview suggestion {entry_id:?} because of error: {error:?}."
);
warn!("Failed to preview suggestion {entry_id:?} because of error: {error:?}.");
},
Err(err) => tracing::warn!("Error while previewing suggestion: {err}."),
Err(err) => warn!("Error while previewing suggestion: {err}."),
}
}

Expand All @@ -196,7 +194,7 @@ impl Model {
Some((self.input_view, new_code_and_trees))
}
Err(err) => {
tracing::error!("Error while applying suggestion: {err}.");
error!("Error while applying suggestion: {err}.");
None
}
}
Expand Down Expand Up @@ -262,7 +260,7 @@ impl Model {
self.suggestion_accepted(entry_id);
}
self.controller.commit_node().map(Some).unwrap_or_else(|err| {
tracing::error!("Error while committing node expression: {err}.");
error!("Error while committing node expression: {err}.");
None
})
}
Expand Down Expand Up @@ -518,9 +516,7 @@ impl Searcher {
if let Mode::NewNode { source_node, .. } = mode {
if source_node.is_none() {
if let Err(e) = searcher_controller.set_input("".to_string()) {
tracing::error!(
"Failed to clear input when creating searcher for a new node: {e:?}."
);
error!("Failed to clear input when creating searcher for a new node: {e:?}.");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/gui/src/profile_workflow.rs
Expand Up @@ -30,7 +30,7 @@ pub async fn main() {
});

// Emit profile and exit.
debug_api::save_profile(&profiler::internal::take_log());
debug_api::save_profile(&profiler::internal::get_log());
debug_api::LifecycleController::new().expect("Workflows run in Electron").quit();
}

Expand Down
Expand Up @@ -261,7 +261,7 @@ impl Model {
let text: &ImString = entry.as_ref();
entry::Model::Text(text.clone_ref())
} else {
tracing::error!("Requested entry is missing in the breadcrumbs ({col})");
error!("Requested entry is missing in the breadcrumbs ({col})");
entry::Model::default()
}
}
Expand Down
6 changes: 6 additions & 0 deletions app/ide-desktop/lib/client/src/index.js
Expand Up @@ -256,6 +256,11 @@ optParser.options('skip-min-version-check', {
type: 'boolean',
})

optParser.options('emit-user-timing-measurements', {
describe: 'Forward profiler data to the User Timing web API.',
type: 'boolean',
})

// === Parsing ===

let args = optParser.parse()
Expand Down Expand Up @@ -574,6 +579,7 @@ function createWindow() {
data_gathering: args.dataGathering,
preferred_engine_version: args.preferredEngineVersion,
enable_new_component_browser: args.enableNewComponentBrowser,
emit_user_timing_measurements: args.emitUserTimingMeasurements,
node_labels: args.nodeLabels,
verbose: args.verbose,
}
Expand Down
1 change: 1 addition & 0 deletions app/ide-desktop/lib/content/src/index.ts
Expand Up @@ -774,6 +774,7 @@ class Config {
public skip_min_version_check: boolean = Versions.isDevVersion()
public preferred_engine_version: SemVer = Versions.ideVersion
public enable_new_component_browser: boolean = true
public emit_user_timing_measurements: boolean = false

updateFromObject(other: any) {
if (!ok(other)) {
Expand Down
42 changes: 34 additions & 8 deletions build/build/src/project/wasm.rs
Expand Up @@ -59,6 +59,17 @@ pub enum ProfilingLevel {
Debug,
}

#[derive(Clone, Copy, Debug, Default, strum::Display, strum::EnumString, PartialEq, Eq)]
#[strum(serialize_all = "kebab-case")]
pub enum LogLevel {
Error,
#[default]
Warn,
Info,
Debug,
Trace,
}

#[derive(clap::ArgEnum, Clone, Copy, Debug, PartialEq, Eq, strum::Display, strum::AsRefStr)]
#[strum(serialize_all = "kebab-case")]
pub enum Profile {
Expand Down Expand Up @@ -112,13 +123,15 @@ impl Profile {
#[derivative(Debug)]
pub struct BuildInput {
/// Path to the crate to be compiled to WAM. Relative to the repository root.
pub crate_path: PathBuf,
pub wasm_opt_options: Vec<String>,
pub skip_wasm_opt: bool,
pub extra_cargo_options: Vec<String>,
pub profile: Profile,
pub profiling_level: Option<ProfilingLevel>,
pub wasm_size_limit: Option<byte_unit::Byte>,
pub crate_path: PathBuf,
pub wasm_opt_options: Vec<String>,
pub skip_wasm_opt: bool,
pub extra_cargo_options: Vec<String>,
pub profile: Profile,
pub profiling_level: Option<ProfilingLevel>,
pub log_level: Option<LogLevel>,
pub uncollapsed_log_level: Option<LogLevel>,
pub wasm_size_limit: Option<byte_unit::Byte>,
}

impl BuildInput {
Expand Down Expand Up @@ -191,6 +204,8 @@ impl IsTarget for Wasm {
extra_cargo_options,
profile,
profiling_level,
log_level,
uncollapsed_log_level,
wasm_size_limit: _wasm_size_limit,
} = &inner;

Expand All @@ -206,7 +221,6 @@ impl IsTarget for Wasm {
.current_dir(&repo_root)
.kill_on_drop(true)
.env_remove(ide_ci::programs::rustup::env::RUSTUP_TOOLCHAIN.name())
.set_env(env::ENSO_ENABLE_PROC_MACRO_SPAN, &true)?
.build()
.arg(wasm_pack::Profile::from(*profile))
.target(wasm_pack::Target::Web)
Expand All @@ -220,6 +234,11 @@ impl IsTarget for Wasm {
if let Some(profiling_level) = profiling_level {
command.set_env(env::ENSO_MAX_PROFILING_LEVEL, &profiling_level)?;
}
command.set_env(env::ENSO_MAX_LOG_LEVEL, &log_level.unwrap_or_default())?;
command.set_env(
env::ENSO_MAX_UNCOLLAPSED_LOG_LEVEL,
&uncollapsed_log_level.unwrap_or_default(),
)?;
command.run_ok().await?;

Self::finalize_wasm(wasm_opt_options, *skip_wasm_opt, *profile, &temp_dist).await?;
Expand Down Expand Up @@ -280,6 +299,8 @@ impl IsWatchable for Wasm {
extra_cargo_options,
profile,
profiling_level,
log_level,
uncollapsed_log_level,
wasm_size_limit,
} = inner;

Expand Down Expand Up @@ -322,6 +343,11 @@ impl IsWatchable for Wasm {
if let Some(profiling_level) = profiling_level {
watch_cmd.args(["--profiling-level", profiling_level.to_string().as_str()]);
}
watch_cmd.args(["--log-level", log_level.unwrap_or_default().to_string().as_str()]);
watch_cmd.args([
"--uncollapsed-log-level",
uncollapsed_log_level.unwrap_or_default().to_string().as_str(),
]);
for wasm_opt_option in wasm_opt_options {
watch_cmd.args(["--wasm-opt-option", &wasm_opt_option]);
}
Expand Down
30 changes: 7 additions & 23 deletions build/build/src/project/wasm/env.rs
@@ -1,38 +1,22 @@
//! Environment variables used by the GUI's Rust part build.

use crate::project::wasm::LogLevel;
use crate::project::wasm::ProfilingLevel;



ide_ci::define_env_var! {
/// Enable a Rust unstable feature that the `#[profile]` macro uses to obtain source-file
/// and line number information to include in generated profile files.
///
/// The IntelliJ Rust plugin does not support the `proc_macro_span` Rust feature; using it
/// causes JetBrains IDEs to become entirely unaware of the items produced by `#[profile]`.
/// (See: https://github.com/intellij-rust/intellij-rust/issues/8655)
///
/// In order to have line number information in actual usage, but keep everything
/// understandable by JetBrains IDEs, we need IntelliJ/CLion to build crates differently
/// from how they are built for the application to be run. This is accomplished by gating
/// the use of the unstable functionality by a `cfg` flag. A `cfg` flag is disabled by
/// default, so when a Rust IDE builds crates internally in order to determine macro
/// expansions, it will do so without line numbers. When this script is used to build the
/// application, it is not for the purpose of IDE macro expansion, so we can safely enable
/// line numbers.
///
/// The reason we don't use a Cargo feature for this is because this script can build
/// different crates, and we'd like to enable this feature when building any crate that
/// depends on the `profiler` crates. We cannot do something like
/// '--feature=enso_profiler/line-numbers' without causing build to fail when building a
/// crate that doesn't have `enso_profiler` in its dependency tree.
ENSO_ENABLE_PROC_MACRO_SPAN, bool;

/// Use the environment-variable API provided by the `enso_profiler_macros` library to
/// implement the public interface to profiling-level configuration (see:
/// https://github.com/enso-org/design/blob/main/epics/profiling/implementation.md)
ENSO_MAX_PROFILING_LEVEL, ProfilingLevel;

/// Set the level of logging detail that will be enabled at compile-time.
ENSO_MAX_LOG_LEVEL, LogLevel;
/// Set the level of logging detail that will be displayed initially-open in hierarchical views,
/// such as the Web Console.
ENSO_MAX_UNCOLLAPSED_LOG_LEVEL, LogLevel;

/// The timeout for `wasm-bindgen-test-runner` in seconds.
WASM_BINDGEN_TEST_TIMEOUT, u64;
}