Exemple #1
0
int main( int argc, const char* argv[] )
{
  int i,j,iret;
  double first[SIZE][SIZE];
  double second[SIZE][SIZE];
  double multiply[SIZE][SIZE];
  double dtime;
  for (i = 0; i < SIZE; i++) { //rows in first
    for (j = 0; j < SIZE; j++) { //columns in first
      first[i][j]=i+j;
      second[j][i]=i-j;
      multiply[i][j]=0.0;
    }
  }
  profiler_init();
  dtime = dclock();
  profiler_start();
  iret=mm(first,second,multiply);
  profiler_stop();
  dtime = dclock()-dtime;
  profiler_print();
  printf( "Time: %le \n", dtime);
  fflush( stdout );

  double check=0.0;
  for(i=0;i<SIZE;i++){
    for(j=0;j<SIZE;j++){
      check+=multiply[i][j];      
    }
  }
  printf("check %le \n",check);


  return iret;
}
Exemple #2
0
void mozilla_sampler_lock()
{
  profiler_stop();
  nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
  if (os)
    os->NotifyObservers(nullptr, "profiler-locked", nullptr);
}
Exemple #3
0
void mozilla_sampler_shutdown()
{
  sInitCount--;

  if (sInitCount > 0)
    return;

  // Save the profile on shutdown if requested.
  TableTicker *t = tlsTicker.get();
  if (t) {
    const char *val = PR_GetEnv("MOZ_PROFILER_SHUTDOWN");
    if (val) {
      std::ofstream stream;
      stream.open(val);
      if (stream.is_open()) {
        t->ToStreamAsJSON(stream);
        stream.close();
      }
    }
  }

  profiler_stop();

  set_stderr_callback(nullptr);

  Sampler::Shutdown();

  PseudoStack *stack = tlsPseudoStack.get();
  stack->deref();
  tlsPseudoStack.set(nullptr);
}
Exemple #4
0
void mozilla_sampler_shutdown()
{
  sInitCount--;

  if (sInitCount > 0)
    return;

  // Save the profile on shutdown if requested.
  TableTicker *t = tlsTicker.get();
  if (t) {
    const char *val = PR_GetEnv("MOZ_PROFILER_SHUTDOWN");
    if (val) {
      std::ofstream stream;
      stream.open(val);
      if (stream.is_open()) {
        t->ToStreamAsJSON(stream);
        stream.close();
      }
    }
  }

  profiler_stop();

  delete sInterposeObserver;
  sInterposeObserver = nullptr;
  mozilla::IOInterposer::ClearInstance();

  Sampler::Shutdown();

  // We can't delete the Stack because we can be between a
  // sampler call_enter/call_exit point.
  // TODO Need to find a safe time to delete Stack
}
Exemple #5
0
void mozilla_sampler_lock()
{
  profiler_stop();
#ifndef SPS_STANDALONE
  nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
  if (os)
    os->NotifyObservers(nullptr, "profiler-locked", nullptr);
#endif
}
static int profiler_init(lua_State *L) {
  lprofP_STATE* S;
  const char* outfile;
  float function_call_time;

  lua_pushlightuserdata(L, &profstate_id);
  lua_gettable(L, LUA_REGISTRYINDEX);
  if(!lua_isnil(L, -1)) {
    profiler_stop(L);
  }
  lua_pop(L, 1);

  function_call_time = calcCallTime(L);

  outfile = NULL;
  if(lua_gettop(L) >= 1)
    outfile = luaL_checkstring(L, 1);

  /* init with default file name and printing a header line */
  if (!(S=lprofP_init_core_profiler(outfile, 1, function_call_time))) {
    return luaL_error(L,"LuaProfiler error: output file could not be opened!");
  }

  lua_sethook(L, (lua_Hook)callhook, LUA_MASKCALL | LUA_MASKRET, 0);

  lua_pushlightuserdata(L, &profstate_id);
  lua_pushlightuserdata(L, S);
  lua_settable(L, LUA_REGISTRYINDEX);
	
  /* use our own exit function instead */
  lua_getglobal(L, "os");
  lua_pushlightuserdata(L, &exit_id);
  lua_pushstring(L, "exit");
  lua_gettable(L, -3);
  lua_settable(L, LUA_REGISTRYINDEX);
  lua_pushstring(L, "exit");
  lua_pushcfunction(L, (lua_CFunction)exit_profiler);
  lua_settable(L, -3);

#if 0
  /* use our own coroutine.create function instead */
  lua_getglobal(L, "coroutine");
  lua_pushstring(L, "create");
  lua_pushcfunction(L, (lua_CFunction)coroutine_create);
  lua_settable(L, -3);
#endif

  /* the following statement is to simulate how the execution stack is */
  /* supposed to be by the time the profiler is activated when loaded  */
  /* as a library.                                                     */

  lprofP_callhookIN(S, "profiler_init", "(C)", -1, -1);
	
  lua_pushboolean(L, 1);
  return 1;
}
Exemple #7
0
static VALUE
rb_profile_block(VALUE module, VALUE usec)
{
    rb_need_block();

    profiler_start(module, usec);
    rb_yield(Qundef);
    profiler_stop(module);

    return Qnil;
}
Exemple #8
0
// Values are only honored on the first start
void mozilla_sampler_start(int aProfileEntries, int aInterval,
                           const char** aFeatures, uint32_t aFeatureCount)
{
  if (!stack_key_initialized)
    profiler_init();

  /* If the sampling interval was set using env vars, use that
     in preference to anything else. */
  if (sUnwindInterval > 0)
    aInterval = sUnwindInterval;

  PseudoStack *stack = tlsPseudoStack.get();
  if (!stack) {
    ASSERT(false);
    return;
  }

  // Reset the current state if the profiler is running
  profiler_stop();

  TableTicker* t;
  if (sps_version2()) {
    t = new BreakpadSampler(aInterval ? aInterval : PROFILE_DEFAULT_INTERVAL,
                           aProfileEntries ? aProfileEntries : PROFILE_DEFAULT_ENTRY,
                           aFeatures, aFeatureCount);
  } else {
    t = new TableTicker(aInterval ? aInterval : PROFILE_DEFAULT_INTERVAL,
                        aProfileEntries ? aProfileEntries : PROFILE_DEFAULT_ENTRY,
                        aFeatures, aFeatureCount);
  }
  tlsTicker.set(t);
  t->Start();
  if (t->ProfileJS()) {
      mozilla::MutexAutoLock lock(*Sampler::sRegisteredThreadsMutex);
      std::vector<ThreadInfo*> threads = t->GetRegisteredThreads();

      for (uint32_t i = 0; i < threads.size(); i++) {
        ThreadInfo* info = threads[i];
        ThreadProfile* thread_profile = info->Profile();
        if (!thread_profile) {
          continue;
        }
        thread_profile->GetPseudoStack()->enableJSSampling();
      }
  }

  sIsProfiling = true;

  nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
  if (os)
    os->NotifyObservers(nullptr, "profiler-started", nullptr);
}
Exemple #9
0
// 注册hook事件,生成log文件,并把当前profile状态压入registry表
int profiler_init(lua_State *L)
{
	lua_getglobal(L, GLOBALSTATE_NAME);
	//如果不为nil,则证明是多次init了,这时候我们先stop上一次的,在启动新的
	if(!lua_isnil(L, -1))
	{
		profiler_stop(L);	
	}
	lua_pop(L, 1);

	// 初始化全局变量
	GlobalState* pGlobalState = (GlobalState*)malloc(sizeof(GlobalState));
	lua_pushlightuserdata(L, pGlobalState);
	lua_setglobal(L, GLOBALSTATE_NAME);

	pGlobalState->BufCount = 0;
	pGlobalState->Buffer = (BufferData*)malloc(sizeof(BufferData) * MAX_BUFFER_COUNT);
	ProfState *S;
	const char* OutFile;

	pGlobalState->FuncCallTime = calcCallTime(L);
	OutFile = NULL;
	if (lua_gettop(L) == 1)
		OutFile = luaL_checkstring(L, -1); // 因为start有一个输出文件名的可选参数

	lua_sethook(L, (lua_Hook)CallHook, LUA_MASKCALL | LUA_MASKRET, 0);
	pGlobalState->HookMark = 1;

	if (!(S=InitCoreProfiler(OutFile, 1, pGlobalState))) // 生成log文件,并输出首行信息,返回初始化成员的S
	{
		luaL_error(L, "LuaProfiler error: output file could not be opened!");
		lua_pushnil(L);
		return 0;
	}

	// 输出键值对,把生成表存储在以LUA_REGISTRYINDEX为假索引的registry表(栈)中
	lua_pushlightuserdata(L, &StateID);
	lua_pushlightuserdata(L, S);
	lua_settable(L, LUA_REGISTRYINDEX);

	CallHookIn(S, "start", "(C)", -1, -1);
	lua_pushboolean(L, 1); // 为后面的检测提供依据

	return 1;
}
Exemple #10
0
void mozilla_sampler_shutdown()
{
  sInitCount--;

  if (sInitCount > 0)
    return;

  // Save the profile on shutdown if requested.
  GeckoSampler *t = tlsTicker.get();
  if (t) {
    const char *val = getenv("MOZ_PROFILER_SHUTDOWN");
    if (val) {
      std::ofstream stream;
      stream.open(val);
      if (stream.is_open()) {
        t->ToStreamAsJSON(stream);
        stream.close();
      }
    }
  }

  profiler_stop();

#ifndef SPS_STANDALONE
  set_stderr_callback(nullptr);
#endif

  Sampler::Shutdown();

#ifdef SPS_STANDALONE
  mozilla::TimeStamp::Shutdown();
#endif

  PseudoStack *stack = tlsPseudoStack.get();
  stack->deref();
  tlsPseudoStack.set(nullptr);

#ifdef MOZ_TASK_TRACER
  mozilla::tasktracer::ShutdownTaskTracer();
#endif
}
Exemple #11
0
void mozilla_sampler_shutdown()
{
  sInitCount--;

  if (sInitCount > 0)
    return;

  // Save the profile on shutdown if requested.
  TableTicker *t = tlsTicker.get();
  if (t) {
    const char *val = PR_GetEnv("MOZ_PROFILER_SHUTDOWN");
    if (val) {
      std::ofstream stream;
      stream.open(val);
      if (stream.is_open()) {
        t->ToStreamAsJSON(stream);
        stream.close();
      }
    }
  }

  profiler_stop();

  // Unregister IO interpose observer
  mozilla::IOInterposer::Unregister(mozilla::IOInterposeObserver::OpAll,
                                    sInterposeObserver);
  // mozilla_sampler_shutdown is only called at shutdown, and late-write checks
  // might need the IO interposer, so we don't clear it. Don't worry it's
  // designed not to report leaks.
  // mozilla::IOInterposer::Clear();
  mozilla::ClearNSPRIOInterposing();
  sInterposeObserver = nullptr;

  Sampler::Shutdown();

  // We can't delete the Stack because we can be between a
  // sampler call_enter/call_exit point.
  // TODO Need to find a safe time to delete Stack
}
Exemple #12
0
Result send_from_buffer(void* buffer, u32 size)
{
   Result res;

   profiler_start();

   res = ctrnet_send(client, &size, 4, 0, &client_addr);

   if (res < 0)
      return res;

   res = ctrnet_send(client, buffer, size, 0, &client_addr);

   if (res < 0)
      return res;

   profiler_stop();
   profiler_speed("sent", size);

   return res;

}
Exemple #13
0
void mozilla_sampler_shutdown()
{
  sInitCount--;

  if (sInitCount > 0)
    return;

  // Save the profile on shutdown if requested.
  TableTicker *t = tlsTicker.get();
  if (t) {
    const char *val = PR_GetEnv("MOZ_PROFILER_SHUTDOWN");
    if (val) {
      std::ofstream stream;
      stream.open(val);
      if (stream.is_open()) {
        t->ToStreamAsJSON(stream);
        stream.close();
      }
    }
  }

  // Shut down and reap the unwinder thread.  We have to do this
  // before stopping the sampler, so as to guarantee that the unwinder
  // thread doesn't try to access memory that the subsequent call to
  // mozilla_sampler_stop causes to be freed.
  if (sps_version2()) {
    uwt__deinit();
  }

  profiler_stop();

  Sampler::Shutdown();

  // We can't delete the Stack because we can be between a
  // sampler call_enter/call_exit point.
  // TODO Need to find a safe time to delete Stack
}
Exemple #14
0
// Values are only honored on the first start
void mozilla_sampler_start(int aProfileEntries, double aInterval,
                           const char** aFeatures, uint32_t aFeatureCount,
                           const char** aThreadNameFilters, uint32_t aFilterCount)

{
  LOG("BEGIN mozilla_sampler_start");

  if (!stack_key_initialized)
    profiler_init(nullptr);

  /* If the sampling interval was set using env vars, use that
     in preference to anything else. */
  if (sUnwindInterval > 0)
    aInterval = sUnwindInterval;

  /* If the entry count was set using env vars, use that, too: */
  if (sProfileEntries > 0)
    aProfileEntries = sProfileEntries;

  // Reset the current state if the profiler is running
  profiler_stop();

  GeckoSampler* t;
  t = new GeckoSampler(aInterval ? aInterval : PROFILE_DEFAULT_INTERVAL,
                      aProfileEntries ? aProfileEntries : PROFILE_DEFAULT_ENTRY,
                      aFeatures, aFeatureCount,
                      aThreadNameFilters, aFilterCount);

  tlsTicker.set(t);
  t->Start();
  if (t->ProfileJS() || t->InPrivacyMode()) {
      ::MutexAutoLock lock(*Sampler::sRegisteredThreadsMutex);
      std::vector<ThreadInfo*> threads = t->GetRegisteredThreads();

      for (uint32_t i = 0; i < threads.size(); i++) {
        ThreadInfo* info = threads[i];
        if (info->IsPendingDelete()) {
          continue;
        }
        ThreadProfile* thread_profile = info->Profile();
        if (!thread_profile) {
          continue;
        }
        thread_profile->GetPseudoStack()->reinitializeOnResume();
#ifndef SPS_STANDALONE
        if (t->ProfileJS()) {
          thread_profile->GetPseudoStack()->enableJSSampling();
        }
        if (t->InPrivacyMode()) {
          thread_profile->GetPseudoStack()->mPrivacyMode = true;
        }
#endif
      }
  }

#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
  if (t->ProfileJava()) {
    int javaInterval = aInterval;
    // Java sampling doesn't accuratly keep up with 1ms sampling
    if (javaInterval < 10) {
      aInterval = 10;
    }
    mozilla::widget::GeckoJavaSampler::StartJavaProfiling(javaInterval, 1000);
  }
#endif

#ifndef SPS_STANDALONE
  if (t->AddMainThreadIO()) {
    if (!sInterposeObserver) {
      // Lazily create IO interposer observer
      sInterposeObserver = new mozilla::ProfilerIOInterposeObserver();
    }
    mozilla::IOInterposer::Register(mozilla::IOInterposeObserver::OpAll,
                                    sInterposeObserver);
  }
#endif

  sIsProfiling = true;
#ifndef SPS_STANDALONE
  sIsGPUProfiling = t->ProfileGPU();
  sIsLayersDump = t->LayersDump();
  sIsDisplayListDump = t->DisplayListDump();
  sIsRestyleProfiling = t->ProfileRestyle();

  if (Sampler::CanNotifyObservers()) {
    nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
    if (os) {
      nsTArray<nsCString> featuresArray;
      nsTArray<nsCString> threadNameFiltersArray;

      for (size_t i = 0; i < aFeatureCount; ++i) {
        featuresArray.AppendElement(aFeatures[i]);
      }

      for (size_t i = 0; i < aFilterCount; ++i) {
        threadNameFiltersArray.AppendElement(aThreadNameFilters[i]);
      }

      nsCOMPtr<nsIProfilerStartParams> params =
        new nsProfilerStartParams(aProfileEntries, aInterval, featuresArray,
                                  threadNameFiltersArray);

      os->NotifyObservers(params, "profiler-started", nullptr);
    }
  }
#endif

  LOG("END   mozilla_sampler_start");
}
Exemple #15
0
// Values are only honored on the first start
void mozilla_sampler_start(int aProfileEntries, double aInterval,
                           const char** aFeatures, uint32_t aFeatureCount,
                           const char** aThreadNameFilters, uint32_t aFilterCount)

{
  if (!stack_key_initialized)
    profiler_init(nullptr);

  /* If the sampling interval was set using env vars, use that
     in preference to anything else. */
  if (sUnwindInterval > 0)
    aInterval = sUnwindInterval;

  /* If the entry count was set using env vars, use that, too: */
  if (sProfileEntries > 0)
    aProfileEntries = sProfileEntries;

  // Reset the current state if the profiler is running
  profiler_stop();

  TableTicker* t;
  t = new TableTicker(aInterval ? aInterval : PROFILE_DEFAULT_INTERVAL,
                      aProfileEntries ? aProfileEntries : PROFILE_DEFAULT_ENTRY,
                      aFeatures, aFeatureCount,
                      aThreadNameFilters, aFilterCount);
  if (t->HasUnwinderThread()) {
    // Create the unwinder thread.  ATM there is only one.
    uwt__init();
  }

  tlsTicker.set(t);
  t->Start();
  if (t->ProfileJS() || t->InPrivacyMode()) {
      mozilla::MutexAutoLock lock(*Sampler::sRegisteredThreadsMutex);
      std::vector<ThreadInfo*> threads = t->GetRegisteredThreads();

      for (uint32_t i = 0; i < threads.size(); i++) {
        ThreadInfo* info = threads[i];
        ThreadProfile* thread_profile = info->Profile();
        if (!thread_profile) {
          continue;
        }
        if (t->ProfileJS()) {
          thread_profile->GetPseudoStack()->enableJSSampling();
        }
        if (t->InPrivacyMode()) {
          thread_profile->GetPseudoStack()->mPrivacyMode = true;
        }
      }
  }

#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
  if (t->ProfileJava()) {
    int javaInterval = aInterval;
    // Java sampling doesn't accuratly keep up with 1ms sampling
    if (javaInterval < 10) {
      aInterval = 10;
    }
    mozilla::AndroidBridge::Bridge()->StartJavaProfiling(javaInterval, 1000);
  }
#endif

  if (t->AddMainThreadIO()) {
    if (!sInterposeObserver) {
      // Lazily create IO interposer observer
      sInterposeObserver = new mozilla::ProfilerIOInterposeObserver();
    }
    mozilla::IOInterposer::Register(mozilla::IOInterposeObserver::OpAll,
                                    sInterposeObserver);
  }

  sIsProfiling = true;

  nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
  if (os)
    os->NotifyObservers(nullptr, "profiler-started", nullptr);
}