mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Bug 809317 - Part 1: Provide a pseudo stack implementation of SAMPLER_PRINT_LOCATION. r=ehsan
--HG-- extra : rebase_source : ba956341ba6115f5c0f60a067c46aee45d29724b
This commit is contained in:
parent
f3e9f0a56b
commit
dd15d96b6d
@ -143,8 +143,6 @@ public:
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& stream, const ProfileEntry& entry);
|
||||
|
||||
private:
|
||||
friend class ThreadProfile;
|
||||
union {
|
||||
const char* mTagData;
|
||||
char mTagChars[sizeof(void*)];
|
||||
@ -157,6 +155,8 @@ private:
|
||||
char mTagName;
|
||||
};
|
||||
|
||||
typedef void (*IterateTagsCallback)(const ProfileEntry& entry, const char* tagStringData);
|
||||
|
||||
#define PROFILE_MAX_ENTRY 100000
|
||||
class ThreadProfile
|
||||
{
|
||||
@ -280,6 +280,33 @@ public:
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& stream, const ThreadProfile& profile);
|
||||
|
||||
void IterateTags(IterateTagsCallback aCallback)
|
||||
{
|
||||
MOZ_ASSERT(aCallback);
|
||||
|
||||
int readPos = mReadPos;
|
||||
while (readPos != mLastFlushPos) {
|
||||
// Number of tag consumed
|
||||
int incBy = 1;
|
||||
const ProfileEntry& entry = mEntries[readPos];
|
||||
|
||||
// Read ahead to the next tag, if it's a 'd' tag process it now
|
||||
const char* tagStringData = entry.mTagData;
|
||||
int readAheadPos = (readPos + 1) % mEntrySize;
|
||||
char tagBuff[DYNAMIC_MAX_STRING];
|
||||
// Make sure the string is always null terminated if it fills up DYNAMIC_MAX_STRING-2
|
||||
tagBuff[DYNAMIC_MAX_STRING-1] = '\0';
|
||||
|
||||
if (readAheadPos != mLastFlushPos && mEntries[readAheadPos].mTagName == 'd') {
|
||||
tagStringData = processDynamicTag(readPos, &incBy, tagBuff);
|
||||
}
|
||||
|
||||
aCallback(entry, tagStringData);
|
||||
|
||||
readPos = (readPos + incBy) % mEntrySize;
|
||||
}
|
||||
}
|
||||
|
||||
JSObject *ToJSObject(JSContext *aCx)
|
||||
{
|
||||
JSObjectBuilder b(aCx);
|
||||
@ -1193,3 +1220,31 @@ void mozilla_sampler_frame_number(int frameNumber)
|
||||
{
|
||||
sFrameNumber = frameNumber;
|
||||
}
|
||||
|
||||
void print_callback(const ProfileEntry& entry, const char* tagStringData) {
|
||||
switch (entry.mTagName) {
|
||||
case 's':
|
||||
case 'c':
|
||||
printf_stderr(" %s\n", tagStringData);
|
||||
}
|
||||
}
|
||||
|
||||
void mozilla_sampler_print_location()
|
||||
{
|
||||
if (!stack_key_initialized)
|
||||
mozilla_sampler_init();
|
||||
|
||||
ProfileStack *stack = tlsStack.get();
|
||||
if (!stack) {
|
||||
MOZ_ASSERT(false);
|
||||
return;
|
||||
}
|
||||
|
||||
ThreadProfile threadProfile(1000, stack);
|
||||
doSampleStackTrace(stack, threadProfile, NULL);
|
||||
|
||||
threadProfile.flush();
|
||||
|
||||
printf_stderr("Backtrace:\n");
|
||||
threadProfile.IterateTags(print_callback);
|
||||
}
|
||||
|
@ -80,6 +80,9 @@
|
||||
#define SAMPLE_LABEL_FN(name_space, info)
|
||||
#define SAMPLE_MARKER(info)
|
||||
|
||||
// Tracing features
|
||||
#define SAMPLER_PRINT_LOCATION()
|
||||
|
||||
#endif
|
||||
|
||||
#endif // ifndef SAMPLER_H
|
||||
|
@ -64,6 +64,8 @@ extern bool stack_key_initialized;
|
||||
#define SAMPLE_LABEL_PRINTF(name_space, info, ...) mozilla::SamplerStackFramePrintfRAII SAMPLER_APPEND_LINE_NUMBER(sampler_raii)(name_space "::" info, __LINE__, __VA_ARGS__)
|
||||
#define SAMPLE_MARKER(info) mozilla_sampler_add_marker(info)
|
||||
|
||||
#define SAMPLER_PRINT_LOCATION() mozilla_sampler_print_location()
|
||||
|
||||
/* we duplicate this code here to avoid header dependencies
|
||||
* which make it more difficult to include in other places */
|
||||
#if defined(_M_X64) || defined(__x86_64__)
|
||||
@ -171,6 +173,8 @@ JSObject *mozilla_sampler_get_profile_data(JSContext *aCx);
|
||||
const char** mozilla_sampler_get_features();
|
||||
void mozilla_sampler_init();
|
||||
|
||||
void mozilla_sampler_print_location();
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class NS_STACK_CLASS SamplerStackFrameRAII {
|
||||
|
Loading…
Reference in New Issue
Block a user