Exemplo n.º 1
0
void VerifyProcTest(pid_t pid, pid_t tid,
                    bool (*ReadyFunc)(const backtrace_t*),
                    void (*VerifyFunc)(const backtrace_t*)) {
  pid_t ptrace_tid;
  if (tid < 0) {
    ptrace_tid = pid;
  } else {
    ptrace_tid = tid;
  }
  uint64_t start = NanoTime();
  bool verified = false;
  do {
    usleep(US_PER_MSEC);
    if (ptrace(PTRACE_ATTACH, ptrace_tid, 0, 0) == 0) {
      // Wait for the process to get to a stopping point.
      WaitForStop(ptrace_tid);

      backtrace_context_t context;
      ASSERT_TRUE(backtrace_create_context(&context, pid, tid, 0));
      if (ReadyFunc(context.backtrace)) {
        VerifyFunc(context.backtrace);
        verified = true;
      }
      backtrace_destroy_context(&context);
      ASSERT_TRUE(ptrace(PTRACE_DETACH, ptrace_tid, 0, 0) == 0);
    }
    // If 5 seconds have passed, then we are done.
  } while (!verified && (NanoTime() - start) <= 5 * NS_PER_SEC);
  ASSERT_TRUE(verified);
}
void VerifyProcTest(pid_t pid, pid_t tid,
                    bool (*ReadyFunc)(Backtrace*),
                    void (*VerifyFunc)(Backtrace*)) {
  pid_t ptrace_tid;
  if (tid < 0) {
    ptrace_tid = pid;
  } else {
    ptrace_tid = tid;
  }
  uint64_t start = NanoTime();
  bool verified = false;
  do {
    usleep(US_PER_MSEC);
    if (ptrace(PTRACE_ATTACH, ptrace_tid, 0, 0) == 0) {
      // Wait for the process to get to a stopping point.
      WaitForStop(ptrace_tid);

      UniquePtr<Backtrace> backtrace(Backtrace::Create(pid, tid));
      ASSERT_TRUE(backtrace->Unwind(0));
      ASSERT_TRUE(backtrace.get() != NULL);
      if (ReadyFunc(backtrace.get())) {
        VerifyFunc(backtrace.get());
        verified = true;
      }

      ASSERT_TRUE(ptrace(PTRACE_DETACH, ptrace_tid, 0, 0) == 0);
    }
    // If 5 seconds have passed, then we are done.
  } while (!verified && (NanoTime() - start) <= 5 * NS_PER_SEC);
  ASSERT_TRUE(verified);
}
bool WaitForNonZero(int32_t* value, uint64_t seconds) {
  uint64_t start = NanoTime();
  do {
    if (android_atomic_acquire_load(value)) {
      return true;
    }
  } while ((NanoTime() - start) < seconds * NS_PER_SEC);
  return false;
}
Exemplo n.º 4
0
void RunRepeatedly(Benchmark* b, int iterations) {
  gBytesProcessed = 0;
  ResetBenchmarkTiming();
  uint64_t StartTimeNs = NanoTime();
  b->RunFn(iterations);
  // Catch us if we fail to log anything.
  if ((gBenchmarkTotalTimeNs == 0) && (StartTimeNs != 0) &&
      (gBenchmarkStartTimeNs == 0)) {
    gBenchmarkTotalTimeNs = NanoTime() - StartTimeNs;
  }
}
void WaitForStop(pid_t pid) {
  uint64_t start = NanoTime();

  siginfo_t si;
  while (ptrace(PTRACE_GETSIGINFO, pid, 0, &si) < 0 && (errno == EINTR || errno == ESRCH)) {
    if ((NanoTime() - start) > NS_PER_SEC) {
      printf("The process did not get to a stopping point in 1 second.\n");
      break;
    }
    usleep(US_PER_MSEC);
  }
}
Exemplo n.º 6
0
void Benchmark::RunRepeatedlyWithArg(int iterations, int arg) {
  gBytesProcessed = 0;
  gBenchmarkTotalTimeNs = 0;
  gBenchmarkStartTimeNs = NanoTime();
  if (fn_ != NULL) {
    fn_(iterations);
  } else {
    fn_range_(iterations, arg);
  }
  if (gBenchmarkStartTimeNs != 0) {
    gBenchmarkTotalTimeNs += NanoTime() - gBenchmarkStartTimeNs;
  }
}
Exemplo n.º 7
0
void Run(Benchmark* b) {
  // run once in case it's expensive
  unsigned iterations = 1;
  uint64_t s = NanoTime();
  RunRepeatedly(b, iterations);
  s = NanoTime() - s;
  while (s < 2e9 && gBenchmarkTotalTimeNs < 1e9 && iterations < 1e9) {
    unsigned last = iterations;
    if (gBenchmarkTotalTimeNs / iterations == 0) {
      iterations = 1e9;
    } else {
      iterations = 1e9 / (gBenchmarkTotalTimeNs / iterations);
    }
    iterations =
        std::max(last + 1, std::min(iterations + iterations / 2, 100 * last));
    iterations = Round(iterations);
    s = NanoTime();
    RunRepeatedly(b, iterations);
    s = NanoTime() - s;
  }

  char throughput[100];
  throughput[0] = '\0';
  if (gBenchmarkTotalTimeNs > 0 && gBytesProcessed > 0) {
    double mib_processed = static_cast<double>(gBytesProcessed) / 1e6;
    double seconds = static_cast<double>(gBenchmarkTotalTimeNs) / 1e9;
    snprintf(throughput, sizeof(throughput), " %8.2f MiB/s",
             mib_processed / seconds);
  }

  char full_name[100];
  snprintf(full_name, sizeof(full_name), "%s%s%s", b->Name(),
           b->ArgName() ? "/" : "", b->ArgName() ? b->ArgName() : "");

  uint64_t mean = gBenchmarkTotalTimeNs / iterations;
  uint64_t sdev = 0;
  if (gBenchmarkNum == iterations) {
    mean = gBenchmarkTotalTimeNs / gBenchmarkNum;
    uint64_t nXvariance = gBenchmarkTotalTimeNsSquared * gBenchmarkNum -
                          (gBenchmarkTotalTimeNs * gBenchmarkTotalTimeNs);
    sdev = (sqrt((double)nXvariance) / gBenchmarkNum / gBenchmarkNum) + 0.5;
  }
  if (mean > (10000 * sdev)) {
    printf("%-25s %10" PRIu64 " %10" PRIu64 "%s\n", full_name,
           static_cast<uint64_t>(iterations), mean, throughput);
  } else {
    printf("%-25s %10" PRIu64 " %10" PRIu64 "(\317\203%" PRIu64 ")%s\n",
           full_name, static_cast<uint64_t>(iterations), mean, sdev, throughput);
  }
  fflush(stdout);
}
Exemplo n.º 8
0
void StopBenchmarkTiming(void) {
  if (gBenchmarkStartTimeNs != 0) {
    int64_t diff = NanoTime() - gBenchmarkStartTimeNs;
    gBenchmarkTotalTimeNs += diff;
    gBenchmarkTotalTimeNsSquared += diff * diff;
    ++gBenchmarkNum;
  }
  gBenchmarkStartTimeNs = 0;
}
TEST(libbacktrace, ptrace_threads) {
  pid_t pid;
  if ((pid = fork()) == 0) {
    for (size_t i = 0; i < NUM_PTRACE_THREADS; i++) {
      pthread_attr_t attr;
      pthread_attr_init(&attr);
      pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

      pthread_t thread;
      ASSERT_TRUE(pthread_create(&thread, &attr, PtraceThreadLevelRun, NULL) == 0);
    }
    ASSERT_NE(test_level_one(1, 2, 3, 4, NULL, NULL), 0);
    exit(1);
  }

  // Check to see that all of the threads are running before unwinding.
  std::vector<pid_t> threads;
  uint64_t start = NanoTime();
  do {
    usleep(US_PER_MSEC);
    threads.clear();
    GetThreads(pid, &threads);
  } while ((threads.size() != NUM_PTRACE_THREADS + 1) &&
      ((NanoTime() - start) <= 5 * NS_PER_SEC));
  ASSERT_EQ(threads.size(), static_cast<size_t>(NUM_PTRACE_THREADS + 1));

  ASSERT_TRUE(ptrace(PTRACE_ATTACH, pid, 0, 0) == 0);
  WaitForStop(pid);
  for (std::vector<int>::const_iterator it = threads.begin(); it != threads.end(); ++it) {
    // Skip the current forked process, we only care about the threads.
    if (pid == *it) {
      continue;
    }
    VerifyProcTest(pid, *it, ReadyLevelBacktrace, VerifyLevelDump);
  }
  ASSERT_TRUE(ptrace(PTRACE_DETACH, pid, 0, 0) == 0);

  kill(pid, SIGKILL);
  int status;
  ASSERT_EQ(waitpid(pid, &status, 0), pid);
}
Exemplo n.º 10
0
__int64 xxRandom( void )
{
	__int64 Now = NanoTime() - g_Prev / 2;
	CString strRand, strLast;
	strRand.Format( "%I64d", Now );
	if( strLast.GetLength() < 2 )
		return 0;

	strLast = strRand.GetAt( strRand.GetLength()-1 );
	strLast += strRand.GetAt( strRand.GetLength()-2 );
	return( static_cast<__int64>( _ttol( strLast ) ) );
}
TEST(signal, sigtimedwait_timeout) {
  // Block SIGALRM.
  sigset_t just_SIGALRM;
  sigemptyset(&just_SIGALRM);
  sigaddset(&just_SIGALRM, SIGALRM);
  sigset_t original_set;
  ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &just_SIGALRM, &original_set));

  // Wait timeout.
  int64_t start_time = NanoTime();
  siginfo_t info;
  struct timespec timeout;
  timeout.tv_sec = 0;
  timeout.tv_nsec = 1000000;
  errno = 0;
  ASSERT_EQ(-1, sigtimedwait(&just_SIGALRM, &info, &timeout));
  ASSERT_EQ(EAGAIN, errno);
  ASSERT_GE(NanoTime() - start_time, 1000000);

  ASSERT_EQ(0, sigprocmask(SIG_SETMASK, &original_set, NULL));
}
Exemplo n.º 12
0
double	GetFractionalVsync()
{
	const VsyncState state = GetVsyncState();

	const	jlong	t = NanoTime();
	if ( state.vsyncBaseNano == 0 )
	{
		return 0;
	}
	const	double vsync = (double)state.vsyncCount + (double)(t - state.vsyncBaseNano ) / state.vsyncPeriodNano;

	return vsync;
}
Exemplo n.º 13
0
// This is separate to allow easy switching to a fixed value.
VsyncState GetVsyncState()
{
	if ( 0 )
	{	// constant
		static VsyncState	state;
		if ( state.vsyncBaseNano == 0 ) {
			state.vsyncBaseNano = NanoTime();
			state.vsyncPeriodNano = 1e9 / 60.0;
		}
		return state;
	}
	else
	{	// normal update
		return UpdatedVsyncState.GetState();
	}
}
Exemplo n.º 14
0
void StartBenchmarkTiming(void) {
  if (gBenchmarkStartTimeNs == 0) {
    gBenchmarkStartTimeNs = NanoTime();
  }
}
Exemplo n.º 15
0
#ifdef __DDOM
#include "User.h"
#include "Mover.h"
#include "World.h"
#include "DDom.h"
extern CUserMng g_UserMng;

#include "DPCoreClient.h"
extern	CDPCoreClient		g_DPCoreClient;

#include "dpdatabaseclient.h"
extern	CDPDatabaseClient	g_dpDBClient;


inline unsigned __int64 NanoTime();
static unsigned __int64 g_Prev = NanoTime();
__int64 xxRandom( void );

CDDomTeam::CDDomTeam()
{
	Init();
}
void CDDomTeam::Init( void )
{
	nKill = nDeath = nTouch = nCaptureS = 0;
	m_TeamPlayer.clear();
}
CDDomTeam::~CDDomTeam()
{
}
Exemplo n.º 16
0
double TimeInSeconds() {
	return NanoTime() * 1e-9;
}
Exemplo n.º 17
0
void StopBenchmarkTiming() {
  if (gBenchmarkStartTimeNs != 0) {
    gBenchmarkTotalTimeNs += NanoTime() - gBenchmarkStartTimeNs;
  }
  gBenchmarkStartTimeNs = 0;
}