mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
Bug 733861 - Use std::ostreams for profile stringification. r=BenWa
This commit is contained in:
parent
dd0518f1ec
commit
38ac2ed1e9
@ -59,9 +59,7 @@ namespace std {
|
||||
template ostream& ostream::_M_insert(unsigned long);
|
||||
template ostream& ostream::_M_insert(long long);
|
||||
template ostream& ostream::_M_insert(unsigned long long);
|
||||
#ifdef DEBUG
|
||||
template ostream& ostream::_M_insert(const void*);
|
||||
#endif
|
||||
template ostream& __ostream_insert(ostream&, const char*, streamsize);
|
||||
template istream& istream::_M_extract(double&);
|
||||
#endif
|
||||
|
@ -38,13 +38,15 @@
|
||||
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include "sps_sampler.h"
|
||||
#include "platform.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "prenv.h"
|
||||
#include "shared-libraries.h"
|
||||
#include "mozilla/StringBuilder.h"
|
||||
#include "mozilla/StackWalk.h"
|
||||
#include "JSObjectBuilder.h"
|
||||
|
||||
@ -147,7 +149,7 @@ public:
|
||||
, mTagName(aTagName)
|
||||
{ }
|
||||
|
||||
string TagToString(ThreadProfile *profile);
|
||||
friend std::ostream& operator<<(std::ostream& stream, const ProfileEntry& entry);
|
||||
|
||||
private:
|
||||
friend class ThreadProfile;
|
||||
@ -258,14 +260,7 @@ public:
|
||||
mWritePos = mLastFlushPos;
|
||||
}
|
||||
|
||||
void ToString(StringBuilder &profile)
|
||||
{
|
||||
int readPos = mReadPos;
|
||||
while (readPos != mLastFlushPos) {
|
||||
profile.Append(mEntries[readPos].TagToString(this).c_str());
|
||||
readPos = (readPos + 1) % mEntrySize;
|
||||
}
|
||||
}
|
||||
friend std::ostream& operator<<(std::ostream& stream, const ThreadProfile& profile);
|
||||
|
||||
JSObject *ToJSObject(JSContext *aCx)
|
||||
{
|
||||
@ -309,16 +304,6 @@ public:
|
||||
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()
|
||||
{
|
||||
return mStack;
|
||||
@ -431,10 +416,11 @@ public:
|
||||
}
|
||||
#endif
|
||||
|
||||
FILE* stream = ::fopen(buff, "w");
|
||||
if (stream) {
|
||||
t->GetPrimaryThreadProfile()->WriteProfile(stream);
|
||||
::fclose(stream);
|
||||
std::ofstream stream;
|
||||
stream.open(buff);
|
||||
if (stream.is_open()) {
|
||||
stream << *(t->GetPrimaryThreadProfile());
|
||||
stream.close();
|
||||
LOG("Saved to " FOLDER "profile_TYPE_PID.txt");
|
||||
} else {
|
||||
LOG("Fail to open profile log file.");
|
||||
@ -675,31 +661,32 @@ void TableTicker::Tick(TickSample* sample)
|
||||
}
|
||||
}
|
||||
|
||||
string ProfileEntry::TagToString(ThreadProfile *profile)
|
||||
std::ostream& operator<<(std::ostream& stream, const ThreadProfile& profile)
|
||||
{
|
||||
string tag = "";
|
||||
if (mTagName == 'r') {
|
||||
char buff[50];
|
||||
snprintf(buff, 50, "%-40f", mTagFloat);
|
||||
tag += string(1, mTagName) + string("-") + string(buff) + string("\n");
|
||||
} else if (mTagName == 'l') {
|
||||
char tagBuff[1024];
|
||||
Address pc = mTagAddress;
|
||||
snprintf(tagBuff, 1024, "l-%p\n", pc);
|
||||
tag += string(tagBuff);
|
||||
int readPos = profile.mReadPos;
|
||||
while (readPos != profile.mLastFlushPos) {
|
||||
stream << profile.mEntries[readPos];
|
||||
readPos = (readPos + 1) % profile.mEntrySize;
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream, const ProfileEntry& entry)
|
||||
{
|
||||
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 {
|
||||
tag += string(1, mTagName) + string("-") + string(mTagData) + string("\n");
|
||||
stream << entry.mTagName << "-" << entry.mTagData << "\n";
|
||||
}
|
||||
|
||||
#ifdef ENABLE_SPS_LEAF_DATA
|
||||
if (mLeafAddress) {
|
||||
char tagBuff[1024];
|
||||
unsigned long pc = (unsigned long)mLeafAddress;
|
||||
snprintf(tagBuff, 1024, "l-%llu\n", pc);
|
||||
tag += string(tagBuff);
|
||||
if (entry.mLeafAddress) {
|
||||
stream << entry.mTagName << "-" << entry.mLeafAddress << "\n";
|
||||
}
|
||||
#endif
|
||||
return tag;
|
||||
return stream;
|
||||
}
|
||||
|
||||
void mozilla_sampler_init()
|
||||
@ -767,11 +754,12 @@ char* mozilla_sampler_get_profile()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
StringBuilder profile;
|
||||
t->GetPrimaryThreadProfile()->ToString(profile);
|
||||
std::stringstream profile;
|
||||
profile << *(t->GetPrimaryThreadProfile());
|
||||
|
||||
char *rtn = (char*)malloc( (profile.Length()+1) * sizeof(char) );
|
||||
strcpy(rtn, profile.Buffer());
|
||||
std::string profileString = profile.str();
|
||||
char *rtn = (char*)malloc( (profileString.length() + 1) * sizeof(char) );
|
||||
strcpy(rtn, profileString.c_str());
|
||||
return rtn;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user