diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lj_dispatch.c | 8 | ||||
-rw-r--r-- | src/lj_profile.c | 28 | ||||
-rw-r--r-- | src/lj_profile.h | 4 |
3 files changed, 40 insertions, 0 deletions
diff --git a/src/lj_dispatch.c b/src/lj_dispatch.c index af269c44..0146d8cd 100644 --- a/src/lj_dispatch.c +++ b/src/lj_dispatch.c | |||
@@ -362,11 +362,19 @@ static void callhook(lua_State *L, int event, BCLine line) | |||
362 | /* Top frame, nextframe = NULL. */ | 362 | /* Top frame, nextframe = NULL. */ |
363 | ar.i_ci = (int)((L->base-1) - tvref(L->stack)); | 363 | ar.i_ci = (int)((L->base-1) - tvref(L->stack)); |
364 | lj_state_checkstack(L, 1+LUA_MINSTACK); | 364 | lj_state_checkstack(L, 1+LUA_MINSTACK); |
365 | #if LJ_HASPROFILE && !LJ_PROFILE_SIGPROF | ||
366 | lj_profile_hook_enter(g); | ||
367 | #else | ||
365 | hook_enter(g); | 368 | hook_enter(g); |
369 | #endif | ||
366 | hookf(L, &ar); | 370 | hookf(L, &ar); |
367 | lua_assert(hook_active(g)); | 371 | lua_assert(hook_active(g)); |
368 | setgcref(g->cur_L, obj2gco(L)); | 372 | setgcref(g->cur_L, obj2gco(L)); |
373 | #if LJ_HASPROFILE && !LJ_PROFILE_SIGPROF | ||
374 | lj_profile_hook_leave(g); | ||
375 | #else | ||
369 | hook_leave(g); | 376 | hook_leave(g); |
377 | #endif | ||
370 | } | 378 | } |
371 | } | 379 | } |
372 | 380 | ||
diff --git a/src/lj_profile.c b/src/lj_profile.c index 1984a676..b4bab7f8 100644 --- a/src/lj_profile.c +++ b/src/lj_profile.c | |||
@@ -87,6 +87,34 @@ static ProfileState profile_state; | |||
87 | /* Default sample interval in milliseconds. */ | 87 | /* Default sample interval in milliseconds. */ |
88 | #define LJ_PROFILE_INTERVAL_DEFAULT 10 | 88 | #define LJ_PROFILE_INTERVAL_DEFAULT 10 |
89 | 89 | ||
90 | /* -- Profiler/hook interaction ------------------------------------------- */ | ||
91 | |||
92 | #if !LJ_PROFILE_SIGPROF | ||
93 | void LJ_FASTCALL lj_profile_hook_enter(global_State *g) | ||
94 | { | ||
95 | ProfileState *ps = &profile_state; | ||
96 | if (ps->g) { | ||
97 | profile_lock(ps); | ||
98 | hook_enter(g); | ||
99 | profile_unlock(ps); | ||
100 | } else { | ||
101 | hook_enter(g); | ||
102 | } | ||
103 | } | ||
104 | |||
105 | void LJ_FASTCALL lj_profile_hook_leave(global_State *g) | ||
106 | { | ||
107 | ProfileState *ps = &profile_state; | ||
108 | if (ps->g) { | ||
109 | profile_lock(ps); | ||
110 | hook_leave(g); | ||
111 | profile_unlock(ps); | ||
112 | } else { | ||
113 | hook_leave(g); | ||
114 | } | ||
115 | } | ||
116 | #endif | ||
117 | |||
90 | /* -- Profile callbacks --------------------------------------------------- */ | 118 | /* -- Profile callbacks --------------------------------------------------- */ |
91 | 119 | ||
92 | /* Callback from profile hook (HOOK_PROFILE already cleared). */ | 120 | /* Callback from profile hook (HOOK_PROFILE already cleared). */ |
diff --git a/src/lj_profile.h b/src/lj_profile.h index ad26f2b6..3feb3c1e 100644 --- a/src/lj_profile.h +++ b/src/lj_profile.h | |||
@@ -11,6 +11,10 @@ | |||
11 | #if LJ_HASPROFILE | 11 | #if LJ_HASPROFILE |
12 | 12 | ||
13 | LJ_FUNC void LJ_FASTCALL lj_profile_interpreter(lua_State *L); | 13 | LJ_FUNC void LJ_FASTCALL lj_profile_interpreter(lua_State *L); |
14 | #if !LJ_PROFILE_SIGPROF | ||
15 | LJ_FUNC void LJ_FASTCALL lj_profile_hook_enter(global_State *g); | ||
16 | LJ_FUNC void LJ_FASTCALL lj_profile_hook_leave(global_State *g); | ||
17 | #endif | ||
14 | 18 | ||
15 | #endif | 19 | #endif |
16 | 20 | ||