try some stuff to get to the value of a parameter passed to a function (I think I found a way, but it's not working yet)

This commit is contained in:
OMGeeky
2023-07-01 23:12:13 +02:00
parent e21ba0f650
commit 85735ec25f
2 changed files with 52 additions and 19 deletions

View File

@@ -6,8 +6,12 @@ use std::path::{Path, PathBuf};
use std::sync::Mutex; use std::sync::Mutex;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::{Event, Id, Subscriber}; use tracing::field::Field;
use tracing::span::{Attributes, Record};
use tracing::{Event, Id, Instrument, Subscriber};
use tracing_subscriber::field::Visit;
use tracing_subscriber::layer::Context; use tracing_subscriber::layer::Context;
use tracing_subscriber::registry::LookupSpan;
use tracing_subscriber::Layer; use tracing_subscriber::Layer;
use crate::appmap_definition::*; use crate::appmap_definition::*;
@@ -82,7 +86,7 @@ impl AppMap {
}); });
let existing_node = self.find_in_class_map(&class, &method); let existing_node = self.find_in_class_map(&class, &method);
if existing_node.is_none() { if existing_node.is_none() {
println!("node not found: {} ; {}", class, method); // println!("node not found: {} ; {}", class, method);
self.add_func_to_hierarchy( self.add_func_to_hierarchy(
class, class,
method, method,
@@ -90,10 +94,10 @@ impl AppMap {
.flatten(), .flatten(),
); );
} else { } else {
println!( // println!(
"node already existing: {} ; {} => {:?}", // "node already existing: {} ; {} => {:?}",
class, method, existing_node // class, method, existing_node
); // );
} }
} }
fn add_func_to_hierarchy(&mut self, class: String, method: String, path: Option<String>) { fn add_func_to_hierarchy(&mut self, class: String, method: String, path: Option<String>) {
@@ -120,7 +124,7 @@ impl AppMap {
} }
fn add_class_to_hierarchy(&mut self, class: &str) { fn add_class_to_hierarchy(&mut self, class: &str) {
println!("class_map: {:?}", self.data.class_map); // println!("class_map: {:?}", self.data.class_map);
let class_parts = class.split_once("::"); let class_parts = class.split_once("::");
if let Some((base, name)) = class_parts { if let Some((base, name)) = class_parts {
//class is a subclass. Check if the parent of the class exists already //class is a subclass. Check if the parent of the class exists already
@@ -138,14 +142,14 @@ impl AppMap {
.expect("Could not find or create the parent class") .expect("Could not find or create the parent class")
.children .children
.push_or_create(class_node); .push_or_create(class_node);
println!( // println!(
"added sub class: {} under {} => {:?}", // "added sub class: {} under {} => {:?}",
name, base, self.data.class_map // name, base, self.data.class_map
); // );
return; return;
} }
//could not split so the class should be a top level class //could not split so the class should be a top level class
println!("got add request for top level class: {}", class); // println!("got add request for top level class: {}", class);
let top_level_class = self.find_class_in_class_map_mut(class); let top_level_class = self.find_class_in_class_map_mut(class);
if top_level_class.is_some() { if top_level_class.is_some() {
@@ -158,7 +162,7 @@ impl AppMap {
let classes: &mut Vec<_> = &mut self.data.class_map; let classes: &mut Vec<_> = &mut self.data.class_map;
classes.push(class_node); classes.push(class_node);
println!("Added top level class: {} => {:?}", class, classes); // println!("Added top level class: {} => {:?}", class, classes);
} }
} }
@@ -220,9 +224,7 @@ impl AppMap {
} }
} }
impl<S: Subscriber + Debug + for<'lookup> tracing_subscriber::registry::LookupSpan<'lookup>> impl<S: Subscriber + Debug + for<'lookup> LookupSpan<'lookup>> Layer<S> for AppMapLayer {
Layer<S> for AppMapLayer
{
fn on_event(&self, event: &Event<'_>, ctx: Context<'_, S>) { fn on_event(&self, event: &Event<'_>, ctx: Context<'_, S>) {
println!("event: {:?}; ctx: {:?}", event, ctx); println!("event: {:?}; ctx: {:?}", event, ctx);
} }
@@ -232,8 +234,18 @@ impl<S: Subscriber + Debug + for<'lookup> tracing_subscriber::registry::LookupSp
if let Some(metadata) = metadata { if let Some(metadata) = metadata {
let parameters = metadata.fields(); let parameters = metadata.fields();
println!("parameters: {:?}", parameters); println!("parameters: {:?}", parameters);
let x = metadata.module_path().unwrap() == metadata.target(); for field in parameters {
println!("some test data: {:?}", x); println!("field: {:?}", field);
// let x = field.value();
// println!("field value: {:?}", x);
}
let x: Option<Field> = parameters.field("x");
let x2 = self.in_current_span();
println!("some test data: (1) {:?}", x);
let x = x2.span().field("x");
// let x = metadata.callsite();
println!("some test data: (2) {:?}", x);
self.test.lock().unwrap().add_function_call_event( self.test.lock().unwrap().add_function_call_event(
9999, 9999,
@@ -249,6 +261,27 @@ impl<S: Subscriber + Debug + for<'lookup> tracing_subscriber::registry::LookupSp
fn on_close(&self, id: Id, ctx: Context<'_, S>) { fn on_close(&self, id: Id, ctx: Context<'_, S>) {
println!("on_close=> id: {:?}; ctx: {:?}", id, ctx); println!("on_close=> id: {:?}; ctx: {:?}", id, ctx);
} }
fn on_new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>) {
println!(
"on_new_span(self: {{...}}, attrs: {:?}, id: {:?}, ctx: {:?}",
attrs, id, ctx
);
println!("values: {:?}", attrs.values());
}
fn on_record(&self, _span: &Id, _values: &Record<'_>, _ctx: Context<'_, S>) {
println!("span: {:?}, values: {:?}, ctx: {:?}", _span, _values, _ctx);
}
} }
// #[derive(Debug, Clone)]
// pub struct AppMapFnVisitor {}
// impl Visit for AppMapFnVisitor {
// fn record_debug(&mut self, field: &Field, value: &dyn Debug) {
// println!(
// "record_debug(self:{:?}, field: {:?}, value: {:?} ",
// self, field, value
// );
// }
// }
mod extensions; mod extensions;
mod node_functions; mod node_functions;

View File

@@ -45,7 +45,7 @@ pub fn find_class_in_tree_mut<'a>(
node: &'a mut CodeObjectType, node: &'a mut CodeObjectType,
class: &str, class: &str,
) -> Option<&'a mut ClassCodeObject> { ) -> Option<&'a mut ClassCodeObject> {
println!("trying to find class: {} in node: {:?}", class, node); // println!("trying to find class: {} in node: {:?}", class, node);
let children = match node { let children = match node {
CodeObjectType::Class(c) => { CodeObjectType::Class(c) => {
if class.ends_with(&c.name) { if class.ends_with(&c.name) {