diff options
author | Mike Pall <mike> | 2013-09-10 01:02:09 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2013-09-10 01:25:33 +0200 |
commit | 483f823ea4438024d83a08592bc0c646a3fdf99c (patch) | |
tree | b3480f1d996469bee0c23e23377eaa2906cf53f2 | |
parent | 803d4ddf0c8cfae1c5c300f7d7306f5a6cafb68a (diff) | |
download | luajit-483f823ea4438024d83a08592bc0c646a3fdf99c.tar.gz luajit-483f823ea4438024d83a08592bc0c646a3fdf99c.tar.bz2 luajit-483f823ea4438024d83a08592bc0c646a3fdf99c.zip |
Low-overhead profiler, part 7: console ports.
-rw-r--r-- | src/Makefile | 1 | ||||
-rw-r--r-- | src/lj_arch.h | 5 | ||||
-rw-r--r-- | src/lj_profile.c | 22 |
3 files changed, 25 insertions, 3 deletions
diff --git a/src/Makefile b/src/Makefile index e7f48fdd..cdca7211 100644 --- a/src/Makefile +++ b/src/Makefile | |||
@@ -237,6 +237,7 @@ ifneq (,$(findstring LJ_TARGET_PS3 1,$(TARGET_TESTARCH))) | |||
237 | TARGET_SYS= PS3 | 237 | TARGET_SYS= PS3 |
238 | TARGET_ARCH+= -D__CELLOS_LV2__ | 238 | TARGET_ARCH+= -D__CELLOS_LV2__ |
239 | TARGET_XCFLAGS+= -DLUAJIT_USE_SYSMALLOC | 239 | TARGET_XCFLAGS+= -DLUAJIT_USE_SYSMALLOC |
240 | TARGET_XLIBS+= -lpthread | ||
240 | endif | 241 | endif |
241 | ifneq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH))) | 242 | ifneq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH))) |
242 | TARGET_ARCH+= -DLUAJIT_NO_UNWIND | 243 | TARGET_ARCH+= -DLUAJIT_NO_UNWIND |
diff --git a/src/lj_arch.h b/src/lj_arch.h index ccb54270..7ded0143 100644 --- a/src/lj_arch.h +++ b/src/lj_arch.h | |||
@@ -371,7 +371,10 @@ | |||
371 | #elif LJ_TARGET_POSIX | 371 | #elif LJ_TARGET_POSIX |
372 | #define LJ_HASPROFILE 1 | 372 | #define LJ_HASPROFILE 1 |
373 | #define LJ_PROFILE_SIGPROF 1 | 373 | #define LJ_PROFILE_SIGPROF 1 |
374 | #elif LJ_TARGET_WINDOWS | 374 | #elif LJ_TARGET_PS3 |
375 | #define LJ_HASPROFILE 1 | ||
376 | #define LJ_PROFILE_PTHREAD 1 | ||
377 | #elif LJ_TARGET_WINDOWS || LJ_TARGET_XBOX360 | ||
375 | #define LJ_HASPROFILE 1 | 378 | #define LJ_HASPROFILE 1 |
376 | #define LJ_PROFILE_WTHREAD 1 | 379 | #define LJ_PROFILE_WTHREAD 1 |
377 | #else | 380 | #else |
diff --git a/src/lj_profile.c b/src/lj_profile.c index a58aefc8..c7bc6168 100644 --- a/src/lj_profile.c +++ b/src/lj_profile.c | |||
@@ -30,6 +30,10 @@ | |||
30 | #elif LJ_PROFILE_PTHREAD | 30 | #elif LJ_PROFILE_PTHREAD |
31 | 31 | ||
32 | #include <pthread.h> | 32 | #include <pthread.h> |
33 | #include <time.h> | ||
34 | #if LJ_TARGET_PS3 | ||
35 | #include <sys/timer.h> | ||
36 | #endif | ||
33 | 37 | ||
34 | #elif LJ_PROFILE_WTHREAD | 38 | #elif LJ_PROFILE_WTHREAD |
35 | 39 | ||
@@ -54,9 +58,11 @@ typedef struct ProfileState { | |||
54 | pthread_t thread; /* Timer thread. */ | 58 | pthread_t thread; /* Timer thread. */ |
55 | int abort; /* Abort timer thread. */ | 59 | int abort; /* Abort timer thread. */ |
56 | #elif LJ_PROFILE_WTHREAD | 60 | #elif LJ_PROFILE_WTHREAD |
61 | #if LJ_TARGET_WINDOWS | ||
57 | HINSTANCE wmm; /* WinMM library handle. */ | 62 | HINSTANCE wmm; /* WinMM library handle. */ |
58 | WMM_TPFUNC wmm_tbp; /* WinMM timeBeginPeriod function. */ | 63 | WMM_TPFUNC wmm_tbp; /* WinMM timeBeginPeriod function. */ |
59 | WMM_TPFUNC wmm_tep; /* WinMM timeEndPeriod function. */ | 64 | WMM_TPFUNC wmm_tep; /* WinMM timeEndPeriod function. */ |
65 | #endif | ||
60 | HANDLE thread; /* Timer thread. */ | 66 | HANDLE thread; /* Timer thread. */ |
61 | int abort; /* Abort timer thread. */ | 67 | int abort; /* Abort timer thread. */ |
62 | #endif | 68 | #endif |
@@ -144,11 +150,17 @@ static void profile_timer_stop(ProfileState *ps) | |||
144 | static void *profile_thread(ProfileState *ps) | 150 | static void *profile_thread(ProfileState *ps) |
145 | { | 151 | { |
146 | int interval = ps->interval; | 152 | int interval = ps->interval; |
153 | #if !LJ_TARGET_PS3 | ||
147 | struct timespec ts; | 154 | struct timespec ts; |
148 | ts.tv_sec = interval / 1000; | 155 | ts.tv_sec = interval / 1000; |
149 | ts.tv_nsec = (interval % 1000) * 1000000; | 156 | ts.tv_nsec = (interval % 1000) * 1000000; |
157 | #endif | ||
150 | while (1) { | 158 | while (1) { |
159 | #if LJ_TARGET_PS3 | ||
160 | sys_timer_usleep(interval * 1000); | ||
161 | #else | ||
151 | nanosleep(&ts, NULL); | 162 | nanosleep(&ts, NULL); |
163 | #endif | ||
152 | if (ps->abort) break; | 164 | if (ps->abort) break; |
153 | profile_trigger(ps); | 165 | profile_trigger(ps); |
154 | } | 166 | } |
@@ -176,19 +188,24 @@ static DWORD WINAPI profile_thread(void *psx) | |||
176 | { | 188 | { |
177 | ProfileState *ps = (ProfileState *)psx; | 189 | ProfileState *ps = (ProfileState *)psx; |
178 | int interval = ps->interval; | 190 | int interval = ps->interval; |
179 | ps->wmm_tbp(1); | 191 | #if LJ_TARGET_WINDOWS |
192 | ps->wmm_tbp(interval); | ||
193 | #endif | ||
180 | while (1) { | 194 | while (1) { |
181 | Sleep(interval); | 195 | Sleep(interval); |
182 | if (ps->abort) break; | 196 | if (ps->abort) break; |
183 | profile_trigger(ps); | 197 | profile_trigger(ps); |
184 | } | 198 | } |
185 | ps->wmm_tep(1); | 199 | #if LJ_TARGET_WINDOWS |
200 | ps->wmm_tep(interval); | ||
201 | #endif | ||
186 | return 0; | 202 | return 0; |
187 | } | 203 | } |
188 | 204 | ||
189 | /* Start profiling timer thread. */ | 205 | /* Start profiling timer thread. */ |
190 | static void profile_timer_start(ProfileState *ps) | 206 | static void profile_timer_start(ProfileState *ps) |
191 | { | 207 | { |
208 | #if LJ_TARGET_WINDOWS | ||
192 | if (!ps->wmm) { /* Load WinMM library on-demand. */ | 209 | if (!ps->wmm) { /* Load WinMM library on-demand. */ |
193 | ps->wmm = LoadLibraryA("winmm.dll"); | 210 | ps->wmm = LoadLibraryA("winmm.dll"); |
194 | if (ps->wmm) { | 211 | if (ps->wmm) { |
@@ -200,6 +217,7 @@ static void profile_timer_start(ProfileState *ps) | |||
200 | } | 217 | } |
201 | } | 218 | } |
202 | } | 219 | } |
220 | #endif | ||
203 | ps->abort = 0; | 221 | ps->abort = 0; |
204 | ps->thread = CreateThread(NULL, 0, profile_thread, ps, 0, NULL); | 222 | ps->thread = CreateThread(NULL, 0, profile_thread, ps, 0, NULL); |
205 | } | 223 | } |