2013-03-25 21:57:28 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2013-11-21 17:08:01 +00:00
|
|
|
#ifndef TableTicker_h
|
|
|
|
#define TableTicker_h
|
|
|
|
|
2013-03-25 21:57:28 +00:00
|
|
|
#include "platform.h"
|
|
|
|
#include "ProfileEntry.h"
|
2013-03-29 19:34:49 +00:00
|
|
|
#include "mozilla/Mutex.h"
|
2013-10-08 14:05:25 +00:00
|
|
|
#include "IntelPowerGadget.h"
|
2013-03-25 21:57:28 +00:00
|
|
|
|
|
|
|
static bool
|
|
|
|
hasFeature(const char** aFeatures, uint32_t aFeatureCount, const char* aFeature) {
|
|
|
|
for(size_t i = 0; i < aFeatureCount; i++) {
|
|
|
|
if (strcmp(aFeatures[i], aFeature) == 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-16 20:31:50 +00:00
|
|
|
static bool
|
|
|
|
threadSelected(ThreadInfo* aInfo, char** aThreadNameFilters, uint32_t aFeatureCount) {
|
|
|
|
if (aFeatureCount == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < aFeatureCount; ++i) {
|
|
|
|
const char* filterPrefix = aThreadNameFilters[i];
|
|
|
|
if (strncmp(aInfo->Name(), filterPrefix, strlen(filterPrefix)) == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-25 21:57:28 +00:00
|
|
|
extern TimeStamp sLastTracerEvent;
|
|
|
|
extern int sFrameNumber;
|
|
|
|
extern int sLastFrameNumber;
|
|
|
|
extern unsigned int sCurrentEventGeneration;
|
|
|
|
extern unsigned int sLastSampledEventGeneration;
|
|
|
|
|
|
|
|
class BreakpadSampler;
|
|
|
|
|
|
|
|
class TableTicker: public Sampler {
|
|
|
|
public:
|
2013-03-26 16:34:27 +00:00
|
|
|
TableTicker(double aInterval, int aEntrySize,
|
2013-05-16 20:31:50 +00:00
|
|
|
const char** aFeatures, uint32_t aFeatureCount,
|
|
|
|
const char** aThreadNameFilters, uint32_t aFilterCount)
|
2013-03-29 19:34:49 +00:00
|
|
|
: Sampler(aInterval, true, aEntrySize)
|
|
|
|
, mPrimaryThreadProfile(nullptr)
|
2013-03-25 21:57:28 +00:00
|
|
|
, mSaveRequested(false)
|
2013-04-01 19:45:03 +00:00
|
|
|
, mUnwinderThread(false)
|
2013-05-16 20:31:50 +00:00
|
|
|
, mFilterCount(aFilterCount)
|
2013-10-08 14:05:25 +00:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
, mIntelPowerGadget(nullptr)
|
|
|
|
#endif
|
2013-03-25 21:57:28 +00:00
|
|
|
{
|
|
|
|
mUseStackWalk = hasFeature(aFeatures, aFeatureCount, "stackwalk");
|
|
|
|
|
|
|
|
//XXX: It's probably worth splitting the jank profiler out from the regular profiler at some point
|
|
|
|
mJankOnly = hasFeature(aFeatures, aFeatureCount, "jank");
|
|
|
|
mProfileJS = hasFeature(aFeatures, aFeatureCount, "js");
|
2013-04-23 17:10:29 +00:00
|
|
|
mProfileJava = hasFeature(aFeatures, aFeatureCount, "java");
|
2013-10-08 14:05:25 +00:00
|
|
|
mProfilePower = hasFeature(aFeatures, aFeatureCount, "power");
|
2013-04-23 17:10:29 +00:00
|
|
|
mProfileThreads = hasFeature(aFeatures, aFeatureCount, "threads");
|
2013-04-01 19:45:03 +00:00
|
|
|
mUnwinderThread = hasFeature(aFeatures, aFeatureCount, "unwinder") || sps_version2();
|
2013-03-25 21:57:28 +00:00
|
|
|
mAddLeafAddresses = hasFeature(aFeatures, aFeatureCount, "leaf");
|
2013-06-14 16:42:10 +00:00
|
|
|
mPrivacyMode = hasFeature(aFeatures, aFeatureCount, "privacy");
|
2013-06-14 18:01:02 +00:00
|
|
|
mAddMainThreadIO = hasFeature(aFeatures, aFeatureCount, "mainthreadio");
|
2013-03-29 19:34:49 +00:00
|
|
|
|
2013-10-08 14:05:25 +00:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
if (mProfilePower) {
|
|
|
|
mIntelPowerGadget = new IntelPowerGadget();
|
|
|
|
mProfilePower = mIntelPowerGadget->Init();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-05-16 20:31:50 +00:00
|
|
|
// Deep copy aThreadNameFilters
|
|
|
|
mThreadNameFilters = new char*[aFilterCount];
|
|
|
|
for (uint32_t i = 0; i < aFilterCount; ++i) {
|
|
|
|
mThreadNameFilters[i] = strdup(aThreadNameFilters[i]);
|
|
|
|
}
|
|
|
|
|
2013-04-23 17:10:29 +00:00
|
|
|
sStartTime = TimeStamp::Now();
|
|
|
|
|
2013-03-29 19:34:49 +00:00
|
|
|
{
|
|
|
|
mozilla::MutexAutoLock lock(*sRegisteredThreadsMutex);
|
|
|
|
|
|
|
|
// Create ThreadProfile for each registered thread
|
|
|
|
for (uint32_t i = 0; i < sRegisteredThreads->size(); i++) {
|
|
|
|
ThreadInfo* info = sRegisteredThreads->at(i);
|
2013-04-03 22:59:17 +00:00
|
|
|
|
2013-05-16 20:31:50 +00:00
|
|
|
RegisterThread(info);
|
2013-03-29 19:34:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SetActiveSampler(this);
|
|
|
|
}
|
2013-03-25 21:57:28 +00:00
|
|
|
}
|
|
|
|
|
2013-03-29 19:34:49 +00:00
|
|
|
~TableTicker() {
|
|
|
|
if (IsActive())
|
|
|
|
Stop();
|
|
|
|
|
|
|
|
SetActiveSampler(nullptr);
|
|
|
|
|
|
|
|
// Destroy ThreadProfile for all threads
|
|
|
|
{
|
|
|
|
mozilla::MutexAutoLock lock(*sRegisteredThreadsMutex);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < sRegisteredThreads->size(); i++) {
|
|
|
|
ThreadInfo* info = sRegisteredThreads->at(i);
|
|
|
|
ThreadProfile* profile = info->Profile();
|
|
|
|
if (profile) {
|
|
|
|
delete profile;
|
|
|
|
info->SetProfile(nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-08 14:05:25 +00:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
delete mIntelPowerGadget;
|
|
|
|
#endif
|
2013-03-29 19:34:49 +00:00
|
|
|
}
|
2013-04-18 12:15:09 +00:00
|
|
|
|
2013-05-16 20:31:50 +00:00
|
|
|
void RegisterThread(ThreadInfo* aInfo) {
|
|
|
|
if (!aInfo->IsMainThread() && !mProfileThreads) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!threadSelected(aInfo, mThreadNameFilters, mFilterCount)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadProfile* profile = new ThreadProfile(aInfo->Name(),
|
|
|
|
EntrySize(),
|
|
|
|
aInfo->Stack(),
|
|
|
|
aInfo->ThreadId(),
|
|
|
|
aInfo->GetPlatformData(),
|
2013-09-11 18:50:46 +00:00
|
|
|
aInfo->IsMainThread(),
|
|
|
|
aInfo->StackTop());
|
2013-05-16 20:31:50 +00:00
|
|
|
aInfo->SetProfile(profile);
|
|
|
|
}
|
|
|
|
|
2013-03-25 21:57:28 +00:00
|
|
|
// Called within a signal. This function must be reentrant
|
|
|
|
virtual void Tick(TickSample* sample);
|
|
|
|
|
2013-09-25 15:28:34 +00:00
|
|
|
// Immediately captures the calling thread's call stack and returns it.
|
|
|
|
virtual SyncProfile* GetBacktrace();
|
|
|
|
|
2013-03-25 21:57:28 +00:00
|
|
|
// Called within a signal. This function must be reentrant
|
|
|
|
virtual void RequestSave()
|
|
|
|
{
|
|
|
|
mSaveRequested = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void HandleSaveRequest();
|
|
|
|
|
|
|
|
ThreadProfile* GetPrimaryThreadProfile()
|
|
|
|
{
|
2013-03-29 19:34:49 +00:00
|
|
|
if (!mPrimaryThreadProfile) {
|
|
|
|
mozilla::MutexAutoLock lock(*sRegisteredThreadsMutex);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < sRegisteredThreads->size(); i++) {
|
|
|
|
ThreadInfo* info = sRegisteredThreads->at(i);
|
|
|
|
if (info->IsMainThread()) {
|
|
|
|
mPrimaryThreadProfile = info->Profile();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mPrimaryThreadProfile;
|
2013-03-25 21:57:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ToStreamAsJSON(std::ostream& stream);
|
|
|
|
virtual JSObject *ToJSObject(JSContext *aCx);
|
2013-09-05 23:10:37 +00:00
|
|
|
template <typename Builder> typename Builder::Object GetMetaJSCustomObject(Builder& b);
|
2013-03-25 21:57:28 +00:00
|
|
|
|
2013-04-01 19:45:03 +00:00
|
|
|
bool HasUnwinderThread() const { return mUnwinderThread; }
|
2013-04-03 22:59:17 +00:00
|
|
|
bool ProfileJS() const { return mProfileJS; }
|
2013-04-23 17:10:29 +00:00
|
|
|
bool ProfileJava() const { return mProfileJava; }
|
2013-10-08 14:05:25 +00:00
|
|
|
bool ProfilePower() const { return mProfilePower; }
|
2013-04-03 22:59:17 +00:00
|
|
|
bool ProfileThreads() const { return mProfileThreads; }
|
2013-06-14 16:42:10 +00:00
|
|
|
bool InPrivacyMode() const { return mPrivacyMode; }
|
2013-06-14 18:01:02 +00:00
|
|
|
bool AddMainThreadIO() const { return mAddMainThreadIO; }
|
2013-03-25 21:57:28 +00:00
|
|
|
|
|
|
|
protected:
|
2013-04-01 19:45:03 +00:00
|
|
|
// Called within a signal. This function must be reentrant
|
|
|
|
virtual void UnwinderTick(TickSample* sample);
|
|
|
|
|
|
|
|
// Called within a signal. This function must be reentrant
|
|
|
|
virtual void InplaceTick(TickSample* sample);
|
|
|
|
|
2013-03-25 21:57:28 +00:00
|
|
|
// Not implemented on platforms which do not support backtracing
|
|
|
|
void doNativeBacktrace(ThreadProfile &aProfile, TickSample* aSample);
|
|
|
|
|
2013-09-05 23:10:37 +00:00
|
|
|
template <typename Builder> void BuildJSObject(Builder& b, typename Builder::ObjectHandle profile);
|
2013-03-25 21:57:28 +00:00
|
|
|
|
|
|
|
// This represent the application's main thread (SAMPLER_INIT)
|
2013-03-29 19:34:49 +00:00
|
|
|
ThreadProfile* mPrimaryThreadProfile;
|
2013-03-25 21:57:28 +00:00
|
|
|
bool mSaveRequested;
|
|
|
|
bool mAddLeafAddresses;
|
|
|
|
bool mUseStackWalk;
|
|
|
|
bool mJankOnly;
|
|
|
|
bool mProfileJS;
|
2013-04-03 22:59:17 +00:00
|
|
|
bool mProfileThreads;
|
2013-04-01 19:45:03 +00:00
|
|
|
bool mUnwinderThread;
|
2013-04-23 17:10:29 +00:00
|
|
|
bool mProfileJava;
|
2013-10-08 14:05:25 +00:00
|
|
|
bool mProfilePower;
|
2013-05-16 20:31:50 +00:00
|
|
|
|
|
|
|
// Keep the thread filter to check against new thread that
|
|
|
|
// are started while profiling
|
|
|
|
char** mThreadNameFilters;
|
|
|
|
uint32_t mFilterCount;
|
2013-06-14 16:42:10 +00:00
|
|
|
bool mPrivacyMode;
|
2013-06-14 18:01:02 +00:00
|
|
|
bool mAddMainThreadIO;
|
2013-10-08 14:05:25 +00:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
IntelPowerGadget* mIntelPowerGadget;
|
|
|
|
#endif
|
2013-03-25 21:57:28 +00:00
|
|
|
};
|
|
|
|
|
2013-11-21 17:08:01 +00:00
|
|
|
#endif
|
|
|
|
|