diff --git a/vm/src/dictdatatype.rs b/vm/src/dictdatatype.rs index 4fdb5ce30..58cb54b54 100644 --- a/vm/src/dictdatatype.rs +++ b/vm/src/dictdatatype.rs @@ -110,6 +110,7 @@ impl Dict { } /// Retrieve a key + #[cfg_attr(feature = "flame-it", flame("Dict"))] pub fn get(&self, vm: &VirtualMachine, key: &PyObjectRef) -> PyResult> { if let LookupResult::Existing(index) = self.lookup(vm, key)? { Ok(Some(self.unchecked_get(index))) @@ -197,6 +198,7 @@ impl Dict { } /// Lookup the index for the given key. + #[cfg_attr(feature = "flame-it", flame("Dict"))] fn lookup(&self, vm: &VirtualMachine, key: &PyObjectRef) -> PyResult { let hash_value = collection_hash(vm, key)?; let perturb = hash_value; @@ -271,6 +273,7 @@ enum LookupResult { Existing(EntryIndex), // Existing record, index into entries } +#[cfg_attr(feature = "flame-it", flame("collection_hash"))] fn collection_hash(vm: &VirtualMachine, object: &PyObjectRef) -> PyResult { let raw_hash = vm._hash(object)?; let mut hasher = DefaultHasher::new(); diff --git a/vm/src/frame.rs b/vm/src/frame.rs index 5e16cdd05..93b2ff3cd 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -57,6 +57,7 @@ impl RcList { } } + #[cfg_attr(feature = "flame-it", flame("RcList"))] pub fn iter(&self) -> Iter { Iter { next: self.head.as_ref().map(|node| &**node), @@ -67,6 +68,7 @@ impl RcList { impl<'a, T> Iterator for Iter<'a, T> { type Item = &'a T; + #[cfg_attr(feature = "flame-it", flame("Iter"))] fn next(&mut self) -> Option { self.next.map(|node| { self.next = node.next.as_ref().map(|node| &**node); @@ -145,6 +147,7 @@ pub trait NameProtocol { } impl NameProtocol for Scope { + #[cfg_attr(feature = "flame-it", flame("Scope"))] fn load_name(&self, vm: &VirtualMachine, name: &str) -> Option { for dict in self.locals.iter() { if let Some(value) = dict.get_item_option(name, vm).unwrap() { @@ -159,6 +162,7 @@ impl NameProtocol for Scope { vm.get_attribute(vm.builtins.clone(), name).ok() } + #[cfg_attr(feature = "flame-it", flame("Scope"))] fn load_cell(&self, vm: &VirtualMachine, name: &str) -> Option { for dict in self.locals.iter().skip(1) { if let Some(value) = dict.get_item_option(name, vm).unwrap() { @@ -185,6 +189,7 @@ impl NameProtocol for Scope { self.get_locals().del_item(key, vm) } + #[cfg_attr(feature = "flame-it", flame("Scope"))] fn load_global(&self, vm: &VirtualMachine, name: &str) -> Option { self.globals.get_item_option(name, vm).unwrap() } diff --git a/vm/src/obj/objdict.rs b/vm/src/obj/objdict.rs index e80e3ffd1..267678b20 100644 --- a/vm/src/obj/objdict.rs +++ b/vm/src/obj/objdict.rs @@ -202,6 +202,7 @@ impl PyDictRef { self.entries.borrow_mut().insert(vm, &key, value) } + #[cfg_attr(feature = "flame-it", flame("PyDictRef"))] fn inner_getitem(self, key: PyObjectRef, vm: &VirtualMachine) -> PyResult { if let Some(value) = self.entries.borrow().get(vm, &key)? { return Ok(value); diff --git a/vm/src/obj/objtype.rs b/vm/src/obj/objtype.rs index a0692ff64..2cc65d670 100644 --- a/vm/src/obj/objtype.rs +++ b/vm/src/obj/objtype.rs @@ -228,6 +228,7 @@ fn _mro(cls: &PyClassRef) -> Vec { /// Determines if `obj` actually an instance of `cls`, this doesn't call __instancecheck__, so only /// use this if `cls` is known to have not overridden the base __instancecheck__ magic method. +#[cfg_attr(feature = "flame-it", flame("objtype"))] pub fn isinstance(obj: &PyObjectRef, cls: &PyClassRef) -> bool { issubclass(&obj.class(), &cls) } diff --git a/vm/src/pyobject.rs b/vm/src/pyobject.rs index 74f5b2e66..3d3463a4d 100644 --- a/vm/src/pyobject.rs +++ b/vm/src/pyobject.rs @@ -1021,6 +1021,8 @@ pub trait ItemProtocol { vm: &VirtualMachine, ) -> PyResult; fn del_item(&self, key: T, vm: &VirtualMachine) -> PyResult; + + #[cfg_attr(feature = "flame-it", flame("ItemProtocol"))] fn get_item_option( &self, key: T, diff --git a/vm/src/vm.rs b/vm/src/vm.rs index 4c0ea1678..01ea2d2ac 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -243,6 +243,7 @@ impl VirtualMachine { self.ctx.new_bool(b) } + #[cfg_attr(feature = "flame-it", flame("VirtualMachine"))] fn new_exception_obj(&self, exc_type: PyClassRef, args: Vec) -> PyResult { // TODO: add repr of args into logging? vm_trace!("New exception created: {}", exc_type.name); @@ -476,6 +477,7 @@ impl VirtualMachine { } } + #[cfg_attr(feature = "flame-it", flame("VirtualMachine"))] fn _invoke(&self, func_ref: PyObjectRef, args: PyFuncArgs) -> PyResult { vm_trace!("Invoke: {:?} {:?}", func_ref, args); @@ -744,6 +746,7 @@ impl VirtualMachine { } // get_attribute should be used for full attribute access (usually from user code). + #[cfg_attr(feature = "flame-it", flame("VirtualMachine"))] pub fn get_attribute(&self, obj: PyObjectRef, attr_name: T) -> PyResult where T: TryIntoRef,