Răsfoiți Sursa

Low-overhead profiler, part 7: console ports.

Mike Pall 12 ani în urmă
părinte
comite
483f823ea4
3 a modificat fișierele cu 25 adăugiri și 3 ștergeri
  1. 1 0
      src/Makefile
  2. 4 1
      src/lj_arch.h
  3. 20 2
      src/lj_profile.c

+ 1 - 0
src/Makefile

@@ -237,6 +237,7 @@ ifneq (,$(findstring LJ_TARGET_PS3 1,$(TARGET_TESTARCH)))
   TARGET_SYS= PS3
   TARGET_ARCH+= -D__CELLOS_LV2__
   TARGET_XCFLAGS+= -DLUAJIT_USE_SYSMALLOC
+  TARGET_XLIBS+= -lpthread
 endif
 ifneq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH)))
   TARGET_ARCH+= -DLUAJIT_NO_UNWIND

+ 4 - 1
src/lj_arch.h

@@ -371,7 +371,10 @@
 #elif LJ_TARGET_POSIX
 #define LJ_HASPROFILE		1
 #define LJ_PROFILE_SIGPROF	1
-#elif LJ_TARGET_WINDOWS
+#elif LJ_TARGET_PS3
+#define LJ_HASPROFILE		1
+#define LJ_PROFILE_PTHREAD	1
+#elif LJ_TARGET_WINDOWS || LJ_TARGET_XBOX360
 #define LJ_HASPROFILE		1
 #define LJ_PROFILE_WTHREAD	1
 #else

+ 20 - 2
src/lj_profile.c

@@ -30,6 +30,10 @@
 #elif LJ_PROFILE_PTHREAD
 
 #include <pthread.h>
+#include <time.h>
+#if LJ_TARGET_PS3
+#include <sys/timer.h>
+#endif
 
 #elif LJ_PROFILE_WTHREAD
 
@@ -54,9 +58,11 @@ typedef struct ProfileState {
   pthread_t thread;		/* Timer thread. */
   int abort;			/* Abort timer thread. */
 #elif LJ_PROFILE_WTHREAD
+#if LJ_TARGET_WINDOWS
   HINSTANCE wmm;		/* WinMM library handle. */
   WMM_TPFUNC wmm_tbp;		/* WinMM timeBeginPeriod function. */
   WMM_TPFUNC wmm_tep;		/* WinMM timeEndPeriod function. */
+#endif
   HANDLE thread;		/* Timer thread. */
   int abort;			/* Abort timer thread. */
 #endif
@@ -144,11 +150,17 @@ static void profile_timer_stop(ProfileState *ps)
 static void *profile_thread(ProfileState *ps)
 {
   int interval = ps->interval;
+#if !LJ_TARGET_PS3
   struct timespec ts;
   ts.tv_sec = interval / 1000;
   ts.tv_nsec = (interval % 1000) * 1000000;
+#endif
   while (1) {
+#if LJ_TARGET_PS3
+    sys_timer_usleep(interval * 1000);
+#else
     nanosleep(&ts, NULL);
+#endif
     if (ps->abort) break;
     profile_trigger(ps);
   }
@@ -176,19 +188,24 @@ static DWORD WINAPI profile_thread(void *psx)
 {
   ProfileState *ps = (ProfileState *)psx;
   int interval = ps->interval;
-  ps->wmm_tbp(1);
+#if LJ_TARGET_WINDOWS
+  ps->wmm_tbp(interval);
+#endif
   while (1) {
     Sleep(interval);
     if (ps->abort) break;
     profile_trigger(ps);
   }
-  ps->wmm_tep(1);
+#if LJ_TARGET_WINDOWS
+  ps->wmm_tep(interval);
+#endif
   return 0;
 }
 
 /* Start profiling timer thread. */
 static void profile_timer_start(ProfileState *ps)
 {
+#if LJ_TARGET_WINDOWS
   if (!ps->wmm) {  /* Load WinMM library on-demand. */
     ps->wmm = LoadLibraryA("winmm.dll");
     if (ps->wmm) {
@@ -200,6 +217,7 @@ static void profile_timer_start(ProfileState *ps)
       }
     }
   }
+#endif
   ps->abort = 0;
   ps->thread = CreateThread(NULL, 0, profile_thread, ps, 0, NULL);
 }