Bug 1235858 - Record the time stamp, use it for crash reports. r=botond

This commit is contained in:
Milan Sreckovic 2015-12-30 11:47:00 +01:00
Родитель a64d29e25a
Коммит 3ebd8ac2fd
3 изменённых файлов: 25 добавлений и 16 удалений

Просмотреть файл

@ -14,6 +14,7 @@
#ifdef MOZ_LOGGING
#include "mozilla/Logging.h"
#endif
#include "mozilla/Tuple.h"
#if defined(MOZ_WIDGET_GONK) || defined(MOZ_WIDGET_ANDROID)
#include "nsDebug.h"
@ -220,19 +221,23 @@ struct CriticalLogger {
static void CrashAction(LogReason aReason);
};
// The int is the index of the Log call; if the number of logs exceeds some preset
// capacity we may not get all of them, so the indices help figure out which
// ones we did save. The double is expected to be the "TimeDuration",
// time in seconds since the process creation.
typedef mozilla::Tuple<int32_t,std::string,double> LoggingRecordEntry;
// Implement this interface and init the Factory with an instance to
// forward critical logs.
typedef std::vector<LoggingRecordEntry> LoggingRecord;
class LogForwarder {
public:
virtual ~LogForwarder() {}
virtual void Log(const std::string &aString) = 0;
virtual void CrashAction(LogReason aReason) = 0;
// Provide a copy of the logs to the caller. The int is the index
// of the Log call, if the number of logs exceeds some preset capacity
// we may not get all of them, so the indices help figure out which
// ones we did save.
virtual std::vector<std::pair<int32_t,std::string> > StringsVectorCopy() = 0;
// Provide a copy of the logs to the caller.
virtual LoggingRecord LoggingRecordCopy() = 0;
};
class NoLog

Просмотреть файл

@ -10,6 +10,7 @@
#include "mozilla/layers/SharedBufferManagerChild.h"
#include "mozilla/layers/ISurfaceAllocator.h" // for GfxMemoryImageReporter
#include "mozilla/Telemetry.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/Logging.h"
#include "mozilla/Services.h"
@ -191,7 +192,7 @@ public:
virtual void Log(const std::string& aString) override;
virtual void CrashAction(LogReason aReason) override;
virtual std::vector<std::pair<int32_t,std::string> > StringsVectorCopy() override;
virtual LoggingRecord LoggingRecordCopy() override;
void SetCircularBufferSize(uint32_t aCapacity);
@ -201,7 +202,7 @@ private:
void UpdateCrashReport();
private:
std::vector<std::pair<int32_t,std::string> > mBuffer;
LoggingRecord mBuffer;
nsCString mCrashCriticalKey;
uint32_t mMaxCapacity;
int32_t mIndex;
@ -225,8 +226,8 @@ void CrashStatsLogForwarder::SetCircularBufferSize(uint32_t aCapacity)
mBuffer.reserve(static_cast<size_t>(aCapacity));
}
std::vector<std::pair<int32_t,std::string> >
CrashStatsLogForwarder::StringsVectorCopy()
LoggingRecord
CrashStatsLogForwarder::LoggingRecordCopy()
{
MutexAutoLock lock(mMutex);
return mBuffer;
@ -248,9 +249,12 @@ CrashStatsLogForwarder::UpdateStringsVector(const std::string& aString)
MOZ_ASSERT(index >= 0 && index < (int32_t)mMaxCapacity);
MOZ_ASSERT(index <= mIndex && index <= (int32_t)mBuffer.size());
bool ignored;
double tStamp = (TimeStamp::NowLoRes()-TimeStamp::ProcessCreation(ignored)).ToSecondsSigDigits();
// Checking for index >= mBuffer.size(), rather than index == mBuffer.size()
// just out of paranoia, but we know index <= mBuffer.size().
std::pair<int32_t,std::string> newEntry(mIndex,aString);
LoggingRecordEntry newEntry(mIndex,aString,tStamp);
if (index >= static_cast<int32_t>(mBuffer.size())) {
mBuffer.push_back(newEntry);
} else {
@ -262,8 +266,8 @@ CrashStatsLogForwarder::UpdateStringsVector(const std::string& aString)
void CrashStatsLogForwarder::UpdateCrashReport()
{
std::stringstream message;
for(std::vector<std::pair<int32_t, std::string> >::iterator it = mBuffer.begin(); it != mBuffer.end(); ++it) {
message << "|[" << (*it).first << "]" << (*it).second;
for(LoggingRecord::iterator it = mBuffer.begin(); it != mBuffer.end(); ++it) {
message << "|[" << Get<0>(*it) << "]" << Get<1>(*it) << " (t=" << Get<2>(*it) << ")";
}
#ifdef MOZ_CRASHREPORTER

Просмотреть файл

@ -1075,7 +1075,7 @@ NS_IMETHODIMP GfxInfoBase::GetFailures(uint32_t* failureCount,
// and the strings in it should be small as well (the error messages in the
// code.) The second copy happens with the Clone() calls. Technically,
// we don't need the mutex lock after the StringVectorCopy() call.
std::vector<std::pair<int32_t,std::string> > loggedStrings = logForwarder->StringsVectorCopy();
LoggingRecord loggedStrings = logForwarder->LoggingRecordCopy();
*failureCount = loggedStrings.size();
if (*failureCount != 0) {
@ -1093,11 +1093,11 @@ NS_IMETHODIMP GfxInfoBase::GetFailures(uint32_t* failureCount,
}
/* copy over the failure messages into the array we just allocated */
std::vector<std::pair<int32_t, std::string> >::const_iterator it;
LoggingRecord::const_iterator it;
uint32_t i=0;
for(it = loggedStrings.begin() ; it != loggedStrings.end(); ++it, i++) {
(*failures)[i] = (char*)nsMemory::Clone((*it).second.c_str(), (*it).second.size() + 1);
if (indices) (*indices)[i] = (*it).first;
(*failures)[i] = (char*)nsMemory::Clone(Get<1>(*it).c_str(), Get<1>(*it).size() + 1);
if (indices) (*indices)[i] = Get<0>(*it);
if (!(*failures)[i]) {
/* <sarcasm> I'm too afraid to use an inline function... </sarcasm> */