profile.resume_co bugfix

This commit is contained in:
Cloud Wu
2017-05-04 16:58:24 +08:00
parent ea129cd9f6
commit acb0c57844

View File

@@ -107,7 +107,7 @@ lstop(lua_State *L) {
total_time += ti;
lua_pushnumber(L, total_time);
#ifdef DEBUG_LOG
fprintf(stderr, "PROFILE [%p] stop (%lf / %lf)\n", lua_tothread(L,1), ti, total_time);
fprintf(stderr, "PROFILE [%p] stop (%lf/%lf)\n", lua_tothread(L,1), ti, total_time);
#endif
return 1;
@@ -115,18 +115,15 @@ lstop(lua_State *L) {
static int
timing_resume(lua_State *L) {
#ifdef DEBUG_LOG
lua_State *from = lua_tothread(L, -1);
#endif
lua_pushvalue(L, -1);
lua_rawget(L, lua_upvalueindex(2));
if (lua_isnil(L, -1)) { // check total time
lua_pop(L,1);
lua_pop(L,2); // pop from coroutine
} else {
lua_pop(L,1);
lua_pushvalue(L,1);
double ti = get_time();
#ifdef DEBUG_LOG
fprintf(stderr, "PROFILE [%p] resume\n", from);
fprintf(stderr, "PROFILE [%p] resume %lf\n", lua_tothread(L, -1), ti);
#endif
lua_pushnumber(L, ti);
lua_rawset(L, lua_upvalueindex(1)); // set start time
@@ -147,7 +144,7 @@ lresume(lua_State *L) {
static int
lresume_co(lua_State *L) {
luaL_checktype(L, 2, LUA_TTHREAD);
lua_rotate(L, 2, -1);
lua_rotate(L, 2, -1); // 'from' coroutine rotate to the top(index -1)
return timing_resume(L);
}