[Jifty-commit] r5422 - in Runops-Hook/trunk: .
Jifty commits
jifty-commit at lists.jifty.org
Sat May 10 07:24:55 EDT 2008
Author: nothingmuch
Date: Sat May 10 07:24:54 2008
New Revision: 5422
Modified:
Runops-Hook/trunk/Hook.xs
Runops-Hook/trunk/t/06counters.t
Log:
move threshold mgmt to _perl hook, remove _noop, plus a bit more refactoring
Modified: Runops-Hook/trunk/Hook.xs
==============================================================================
--- Runops-Hook/trunk/Hook.xs (original)
+++ Runops-Hook/trunk/Hook.xs Sat May 10 07:24:54 2008
@@ -32,30 +32,13 @@
/* this is the modified runloop */
int runops_hooked(pTHX)
{
- if ( !Runops_Hook_op_counters )
- Runops_Hook_op_counters = newHV();
+ while (PL_op) {
- for (;PL_op;) {
/* global flag controls all hooking behavior */
if (Runops_Hook_enabled) {
- if (Runops_Hook_threshold == 0) {
- /* no threshold set means simple hooking */
- if (Runops_Hook_hook(aTHX))
- continue;
- } else {
- /* having a threshold means that only ops that are hit enough
- * times get hooked, the idea is that this can be used for
- * trace caching */
-
- /* unfortunately we need to keep the counters in a hash */
- SV **count = hv_fetch(Runops_Hook_op_counters, (char *)PL_op, sizeof(PL_op), 1);
- UV c = SvTRUE(*count) ? SvUV(*count) + 1 : 1;
- sv_setuv(*count, c);
-
- if (c >= Runops_Hook_threshold)
- if (Runops_Hook_hook(aTHX))
- continue;
- }
+ /* no threshold set means simple hooking */
+ if (Runops_Hook_hook && Runops_Hook_hook(aTHX))
+ continue;
}
PL_op = CALL_FPTR(PL_op->op_ppaddr)(aTHX);
@@ -78,13 +61,6 @@
Runops_Hook_enabled = 0;
}
-/* this is the default hook that does nothing */
-bool
-Runops_Hook_noop (pTHX) {
- /* resume normally */
- return 0;
-}
-
SV *
Runops_Hook_op_to_BOP (pTHX_ OP *op) {
dSP;
@@ -182,6 +158,24 @@
bool ret;
IV arity;
+ if (Runops_Hook_threshold != 0) {
+ /* having a threshold means that only ops that are hit enough
+ * times get hooked, the idea is that this can be used for
+ * trace caching */
+
+ if ( !Runops_Hook_op_counters )
+ Runops_Hook_op_counters = newHV();
+
+ /* unfortunately we need to keep the counters in a hash */
+ SV **count = hv_fetch(Runops_Hook_op_counters, (char *)PL_op, sizeof(PL_op), 1);
+ UV c = SvTRUE(*count) ? SvUV(*count) + 1 : 1;
+ sv_setuv(*count, c);
+
+ /* if we haven't reached the threshold yet, then return */
+ if (c < Runops_Hook_threshold)
+ return 0;
+ }
+
/* don't want to hook the hook */
Runops_Hook_disable();
@@ -275,7 +269,7 @@
void
Runops_Hook_clear_hook () {
- Runops_Hook_hook = Runops_Hook_noop;
+ Runops_Hook_hook = NULL;
}
void
@@ -330,6 +324,9 @@
counters()
CODE:
{
+ if ( !Runops_Hook_op_counters )
+ Runops_Hook_op_counters = newHV();
+
RETVAL = Runops_Hook_op_counters;
}
OUTPUT:
Modified: Runops-Hook/trunk/t/06counters.t
==============================================================================
--- Runops-Hook/trunk/t/06counters.t (original)
+++ Runops-Hook/trunk/t/06counters.t Sat May 10 07:24:54 2008
@@ -8,10 +8,11 @@
ok( !Runops::Hook::enabled(), "disabled" );
+Runops::Hook::set_hook(sub {});
+
is_deeply( Runops::Hook::counters(), {}, "no counters yet" );
Runops::Hook::enable();
-ok( Runops::Hook::enabled(), "enabled" );
Runops::Hook::set_threshold(3);
@@ -20,6 +21,8 @@
$i++;
}
+Runops::Hook::disable();
+
is( $i, 10, "loop ran correctly" );
ok( scalar(keys %{ Runops::Hook::counters() }), "counted something now" );
More information about the Jifty-commit
mailing list