Add some extra profiling trace points.

This commit is contained in:
Windel Bouwman
2019-07-23 19:55:04 +02:00
parent 4e1ebb0645
commit 25816a2775
6 changed files with 15 additions and 0 deletions

View File

@@ -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();

View File

@@ -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()
}

View File

@@ -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);

View File

@@ -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)
}

View File

@@ -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,

View File

@@ -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>,