static int freeEntry(rotating_node_t *header, void *arg) { ProfilerEntry *entry = (ProfilerEntry*) header; RotatingTree_Enum(entry->calls, freeSubEntry, NULL); Py_DECREF(entry->userObj); free(entry); return 0; }
static void flush_unmatched_allstacks(ProfilerObject *pObj) { RotatingTree_Enum(pObj->profilerStacks, &flush_unmatched_enum, pObj); pObj->profilerStacks = EMPTY_ROTATING_TREE; pObj->currentProfilerStack = NULL; pObj->nProfilerStacks = 0; }
static void clearEntries(ProfilerObject *pObj) { RotatingTree_Enum(pObj->profilerEntries, freeEntry, NULL); pObj->profilerEntries = EMPTY_ROTATING_TREE; /* release the memory hold by the free list of ProfilerContexts */ while (pObj->freelistProfilerContext) { ProfilerContext *c = pObj->freelistProfilerContext; pObj->freelistProfilerContext = c->previous; free(c); } }
/* Enumerate all nodes in the tree. The callback enumfn() should return zero to continue the enumeration, or non-zero to interrupt it. A non-zero value is directly returned by RotatingTree_Enum(). */ int RotatingTree_Enum(rotating_node_t *root, rotating_tree_enum_fn enumfn, void *arg) { int result; rotating_node_t *node; while (root != NULL) { result = RotatingTree_Enum(root->left, enumfn, arg); if (result != 0) return result; node = root->right; result = enumfn(root, arg); if (result != 0) return result; root = node; } return 0; }
static int statsForEntry(rotating_node_t *node, void *arg) { ProfilerEntry *entry = (ProfilerEntry*) node; statscollector_t *collect = (statscollector_t*) arg; PyObject *info; int err; if (entry->callcount == 0) return 0; /* skip */ if (entry->calls != EMPTY_ROTATING_TREE) { collect->sublist = PyList_New(0); if (collect->sublist == NULL) return -1; if (RotatingTree_Enum(entry->calls, statsForSubEntry, collect) != 0) { Py_DECREF(collect->sublist); return -1; } } else { Py_INCREF(Py_None); collect->sublist = Py_None; } info = PyObject_CallFunction((PyObject*) &StatsEntryType, "((OllddO))", entry->userObj, entry->callcount, entry->recursivecallcount, collect->factor * entry->tt, collect->factor * entry->it, collect->sublist); Py_DECREF(collect->sublist); if (info == NULL) return -1; err = PyList_Append(collect->list, info); Py_DECREF(info); return err; }