Converted perf function to be a macro. Utilized the perf macro within the polars plugin. (#13224)

In this pull request, I converted the `perf` function within `nu_utils`
to a macro. This change facilitates easier usage within plugins by
allowing the use of `env_logger` and setting `RUST_LOG=nu_plugin_polars`
(or another plugin). Without this conversion, the `RUST_LOG` variable
would need to be set to `RUST_LOG=nu_utils::utils`, which is less
intuitive and impossible to narrow the perf results to one plugin.
This commit is contained in:
Jack Wright
2024-06-27 16:56:56 -07:00
committed by GitHub
parent 0d79b63711
commit 1f1f581357
12 changed files with 154 additions and 524 deletions

View File

@ -13,7 +13,9 @@ use nu_plugin::{EngineInterface, PluginCommand};
use nu_protocol::{LabeledError, ShellError, Span};
use uuid::Uuid;
use crate::{plugin_debug, values::PolarsPluginObject, EngineWrapper, PolarsPlugin};
use crate::{values::PolarsPluginObject, EngineWrapper, PolarsPlugin};
use log::debug;
#[derive(Debug, Clone)]
pub struct CacheValue {
@ -60,22 +62,16 @@ impl Cache {
let removed = if force || reference_count.unwrap_or_default() < 1 {
let removed = lock.remove(key);
plugin_debug!(
engine,
"PolarsPlugin: removing {key} from cache: {removed:?}"
);
debug!("PolarsPlugin: removing {key} from cache: {removed:?}");
removed
} else {
plugin_debug!(
engine,
"PolarsPlugin: decrementing reference count for {key}"
);
debug!("PolarsPlugin: decrementing reference count for {key}");
None
};
// Once there are no more entries in the cache
// we can turn plugin gc back on
plugin_debug!(engine, "PolarsPlugin: Cache is empty enabling GC");
debug!("PolarsPlugin: Cache is empty enabling GC");
engine.set_gc_disabled(false).map_err(LabeledError::from)?;
drop(lock);
Ok(removed)
@ -91,14 +87,11 @@ impl Cache {
span: Span,
) -> Result<Option<CacheValue>, ShellError> {
let mut lock = self.lock()?;
plugin_debug!(
engine,
"PolarsPlugin: Inserting {uuid} into cache: {value:?}"
);
debug!("PolarsPlugin: Inserting {uuid} into cache: {value:?}");
// turn off plugin gc the first time an entry is added to the cache
// as we don't want the plugin to be garbage collected if there
// is any live data
plugin_debug!(engine, "PolarsPlugin: Cache has values disabling GC");
debug!("PolarsPlugin: Cache has values disabling GC");
engine.set_gc_disabled(true).map_err(LabeledError::from)?;
let cache_value = CacheValue {
uuid,