mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Add some extra profiling trace points.
This commit is contained in:
@@ -110,6 +110,7 @@ impl<T: Clone> Dict<T> {
|
||||
}
|
||||
|
||||
/// Retrieve a key
|
||||
#[cfg_attr(feature = "flame-it", flame("Dict"))]
|
||||
pub fn get(&self, vm: &VirtualMachine, key: &PyObjectRef) -> PyResult<Option<T>> {
|
||||
if let LookupResult::Existing(index) = self.lookup(vm, key)? {
|
||||
Ok(Some(self.unchecked_get(index)))
|
||||
@@ -197,6 +198,7 @@ impl<T: Clone> Dict<T> {
|
||||
}
|
||||
|
||||
/// Lookup the index for the given key.
|
||||
#[cfg_attr(feature = "flame-it", flame("Dict"))]
|
||||
fn lookup(&self, vm: &VirtualMachine, key: &PyObjectRef) -> PyResult<LookupResult> {
|
||||
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<HashValue> {
|
||||
let raw_hash = vm._hash(object)?;
|
||||
let mut hasher = DefaultHasher::new();
|
||||
|
||||
@@ -57,6 +57,7 @@ impl<T> RcList<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "flame-it", flame("RcList"))]
|
||||
pub fn iter(&self) -> Iter<T> {
|
||||
Iter {
|
||||
next: self.head.as_ref().map(|node| &**node),
|
||||
@@ -67,6 +68,7 @@ impl<T> RcList<T> {
|
||||
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::Item> {
|
||||
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<PyObjectRef> {
|
||||
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<PyObjectRef> {
|
||||
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<PyObjectRef> {
|
||||
self.globals.get_item_option(name, vm).unwrap()
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -228,6 +228,7 @@ fn _mro(cls: &PyClassRef) -> Vec<PyClassRef> {
|
||||
|
||||
/// 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)
|
||||
}
|
||||
|
||||
@@ -1021,6 +1021,8 @@ pub trait ItemProtocol {
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult;
|
||||
fn del_item<T: IntoPyObject>(&self, key: T, vm: &VirtualMachine) -> PyResult;
|
||||
|
||||
#[cfg_attr(feature = "flame-it", flame("ItemProtocol"))]
|
||||
fn get_item_option<T: IntoPyObject>(
|
||||
&self,
|
||||
key: T,
|
||||
|
||||
@@ -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<PyObjectRef>) -> 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<T>(&self, obj: PyObjectRef, attr_name: T) -> PyResult
|
||||
where
|
||||
T: TryIntoRef<PyString>,
|
||||
|
||||
Reference in New Issue
Block a user