Skip to content

Commit

Permalink
Bug 1145306 - Expose circular buffer status from profiler. r=mstange
Browse files Browse the repository at this point in the history
  • Loading branch information
Kannan Vijayan committed Apr 22, 2015
1 parent b9f7c92 commit 525df29
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 1 deletion.
16 changes: 16 additions & 0 deletions tools/profiler/GeckoProfiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,22 @@ static inline void profiler_save_profile_to_file(char* aFilename) { }
// Returns a null terminated char* array.
static inline char** profiler_get_features() { return nullptr; }

// Get information about the current buffer status.
// Retursn (using outparams) the current write position in the buffer,
// the total size of the buffer, and the generation of the buffer.
// This information may be useful to a user-interface displaying the
// current status of the profiler, allowing the user to get a sense
// for how fast the buffer is being written to, and how much
// data is visible.
static inline void profiler_get_buffer_info(uint32_t *aCurrentPosition,
uint32_t *aTotalSize,
uint32_t *aGeneration)
{
*aCurrentPosition = 0;
*aTotalSize = 0;
*aGeneration = 0;
}

// Discard the profile, throw away the profile and notify 'profiler-locked'.
// This function is to be used when entering private browsing to prevent
// the profiler from collecting sensitive data.
Expand Down
3 changes: 3 additions & 0 deletions tools/profiler/GeckoProfilerFunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ extern "C" {

const char** mozilla_sampler_get_features();

void mozilla_sampler_get_buffer_info(uint32_t *aCurrentPosition, uint32_t *aTotalSize,
uint32_t *aGeneration);

void mozilla_sampler_init(void* stackTop);

void mozilla_sampler_shutdown();
Expand Down
7 changes: 7 additions & 0 deletions tools/profiler/GeckoProfilerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ const char** profiler_get_features()
return mozilla_sampler_get_features();
}

static inline
void profiler_get_buffer_info(uint32_t *aCurrentPosition, uint32_t *aTotalSize,
uint32_t *aGeneration)
{
return mozilla_sampler_get_buffer_info(aCurrentPosition, aTotalSize, aGeneration);
}

static inline
void profiler_lock()
{
Expand Down
8 changes: 8 additions & 0 deletions tools/profiler/TableTicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1079,3 +1079,11 @@ SyncProfile* TableTicker::GetBacktrace()

return profile;
}

void
TableTicker::GetBufferInfo(uint32_t *aCurrentPosition, uint32_t *aTotalSize, uint32_t *aGeneration)
{
*aCurrentPosition = mBuffer->mWritePos;
*aTotalSize = mBuffer->mEntrySize;
*aGeneration = mBuffer->mGeneration;
}
2 changes: 2 additions & 0 deletions tools/profiler/TableTicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ class TableTicker: public Sampler {
bool DisplayListDump() const { return mDisplayListDump; }
bool ProfileRestyle() const { return mProfileRestyle; }

void GetBufferInfo(uint32_t *aCurrentPosition, uint32_t *aTotalSize, uint32_t *aGeneration);

protected:
// Called within a signal. This function must be reentrant
virtual void InplaceTick(TickSample* sample);
Expand Down
5 changes: 4 additions & 1 deletion tools/profiler/nsIProfiler.idl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class nsCString;

[ref] native StringArrayRef(const nsTArray<nsCString>);

[scriptable, uuid(42d1e0e3-303a-424f-89ea-4f15c699d767)]
[scriptable, uuid(edd65f3f-c2a2-4217-a2e2-40347ba4a2b3)]
interface nsIProfiler : nsISupports
{
void StartProfiler(in uint32_t aEntries, in double aInterval,
Expand All @@ -31,6 +31,9 @@ interface nsIProfiler : nsISupports
boolean IsActive();
void GetFeatures(out uint32_t aCount, [retval, array, size_is(aCount)] out string aFeatures);

void GetBufferInfo(out uint32_t aCurrentPosition, out uint32_t aTotalSize,
out uint32_t aGeneration);

/**
* Returns a JSON string of an array of shared library objects.
* Every object has three properties: start, end, and name.
Expand Down
10 changes: 10 additions & 0 deletions tools/profiler/nsProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,13 @@ nsProfiler::GetFeatures(uint32_t *aCount, char ***aFeatures)
*aCount = len;
return NS_OK;
}

NS_IMETHODIMP
nsProfiler::GetBufferInfo(uint32_t *aCurrentPosition, uint32_t *aTotalSize, uint32_t *aGeneration)
{
MOZ_ASSERT(aCurrentPosition);
MOZ_ASSERT(aTotalSize);
MOZ_ASSERT(aGeneration);
profiler_get_buffer_info(aCurrentPosition, aTotalSize, aGeneration);
return NS_OK;
}
17 changes: 17 additions & 0 deletions tools/profiler/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,23 @@ const char** mozilla_sampler_get_features()
return features;
}

void mozilla_sampler_get_buffer_info(uint32_t *aCurrentPosition, uint32_t *aTotalSize,
uint32_t *aGeneration)
{
*aCurrentPosition = 0;
*aTotalSize = 0;
*aGeneration = 0;

if (!stack_key_initialized)
return;

TableTicker *t = tlsTicker.get();
if (!t)
return;

t->GetBufferInfo(aCurrentPosition, aTotalSize, aGeneration);
}

// Values are only honored on the first start
void mozilla_sampler_start(int aProfileEntries, double aInterval,
const char** aFeatures, uint32_t aFeatureCount,
Expand Down

0 comments on commit 525df29

Please sign in to comment.