Backout f42ea2a158e4(bug 733861) due to build bustage on all platforms.

This commit is contained in:
Ryan VanderMeulen 2012-03-22 19:10:16 -04:00
parent fc7977fd47
commit 20596c6e7f

View File

@ -38,15 +38,13 @@
#include <string> #include <string>
#include <stdio.h> #include <stdio.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include "sps_sampler.h" #include "sps_sampler.h"
#include "platform.h" #include "platform.h"
#include "nsXULAppAPI.h" #include "nsXULAppAPI.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "prenv.h" #include "prenv.h"
#include "shared-libraries.h" #include "shared-libraries.h"
#include "mozilla/StringBuilder.h"
#include "mozilla/StackWalk.h" #include "mozilla/StackWalk.h"
#include "JSObjectBuilder.h" #include "JSObjectBuilder.h"
@ -149,7 +147,7 @@ public:
, mTagName(aTagName) , mTagName(aTagName)
{ } { }
friend std::ostream& operator<<(std::ostream& stream, const ProfileEntry& entry); string TagToString(ThreadProfile *profile);
private: private:
friend class ThreadProfile; friend class ThreadProfile;
@ -260,7 +258,14 @@ public:
mWritePos = mLastFlushPos; mWritePos = mLastFlushPos;
} }
friend std::ostream& operator<<(std::ostream& stream, const Profile& profile); void ToString(StringBuilder &profile)
{
int readPos = mReadPos;
while (readPos != mLastFlushPos) {
profile.Append(mEntries[readPos].TagToString(this).c_str());
readPos = (readPos + 1) % mEntrySize;
}
}
JSObject *ToJSObject(JSContext *aCx) JSObject *ToJSObject(JSContext *aCx)
{ {
@ -304,6 +309,16 @@ public:
return profile; return profile;
} }
void WriteProfile(FILE* stream)
{
int readPos = mReadPos;
while (readPos != mLastFlushPos) {
string tag = mEntries[readPos].TagToString(this);
fwrite(tag.data(), 1, tag.length(), stream);
readPos = (readPos + 1) % mEntrySize;
}
}
ProfileStack* GetStack() ProfileStack* GetStack()
{ {
return mStack; return mStack;
@ -416,11 +431,10 @@ public:
} }
#endif #endif
std::ofstream stream; FILE* stream = ::fopen(buff, "w");
stream.open(buff); if (stream) {
if (stream.is_open()) { t->GetPrimaryThreadProfile()->WriteProfile(stream);
stream << *(t->GetPrimaryThreadProfile()); ::fclose(stream);
stream.close();
LOG("Saved to " FOLDER "profile_TYPE_PID.txt"); LOG("Saved to " FOLDER "profile_TYPE_PID.txt");
} else { } else {
LOG("Fail to open profile log file."); LOG("Fail to open profile log file.");
@ -661,32 +675,31 @@ void TableTicker::Tick(TickSample* sample)
} }
} }
std::ostream& operator<<(std::ostream& stream, const Profile& profile) string ProfileEntry::TagToString(ThreadProfile *profile)
{ {
int readPos = profile.mReadPos; string tag = "";
while (readPos != profile.mLastFlushPos) { if (mTagName == 'r') {
stream << profile.mEntries[readPos]; char buff[50];
readPos = (readPos + 1) % profile.mEntrySize; snprintf(buff, 50, "%-40f", mTagFloat);
} tag += string(1, mTagName) + string("-") + string(buff) + string("\n");
return stream; } else if (mTagName == 'l') {
} char tagBuff[1024];
Address pc = mTagAddress;
std::ostream& operator<<(std::ostream& stream, const ProfileEntry& entry) snprintf(tagBuff, 1024, "l-%p\n", pc);
{ tag += string(tagBuff);
if (entry.mTagName == 'r') {
stream << entry.mTagName << "-" << std::fixed << entry.mTagFloat << "\n";
} else if (entry.mTagName == 'l') {
stream << entry.mTagName << "-" << static_cast<const void*>(entry.mTagData) << "\n";
} else { } else {
stream << entry.mTagName << "-" << entry.mTagData << "\n"; tag += string(1, mTagName) + string("-") + string(mTagData) + string("\n");
} }
#ifdef ENABLE_SPS_LEAF_DATA #ifdef ENABLE_SPS_LEAF_DATA
if (entry.mLeafAddress) { if (mLeafAddress) {
stream << entry.mTagName << "-" << entry.mLeafAddress << "\n"; char tagBuff[1024];
unsigned long pc = (unsigned long)mLeafAddress;
snprintf(tagBuff, 1024, "l-%llu\n", pc);
tag += string(tagBuff);
} }
#endif #endif
return stream; return tag;
} }
void mozilla_sampler_init() void mozilla_sampler_init()
@ -754,12 +767,11 @@ char* mozilla_sampler_get_profile()
return NULL; return NULL;
} }
std::stringstream profile; StringBuilder profile;
profile << *(t->GetPrimaryThreadProfile()); t->GetPrimaryThreadProfile()->ToString(profile);
std::string profileString = profile.str(); char *rtn = (char*)malloc( (profile.Length()+1) * sizeof(char) );
char *rtn = (char*)malloc( (profileString.length() + 1) * sizeof(char) ); strcpy(rtn, profile.Buffer());
strcpy(rtn, profileString.c_str());
return rtn; return rtn;
} }