2013-01-17 16:45:11 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-04-27 11:07:02 -07:00
|
|
|
|
2012-08-21 14:14:38 -07:00
|
|
|
#include <algorithm>
|
2012-12-14 15:58:45 -08:00
|
|
|
|
2013-01-08 06:04:37 -08:00
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include <prio.h>
|
|
|
|
|
2012-12-14 15:58:45 -08:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
#include "mozilla/Likely.h"
|
2013-11-22 11:17:30 -08:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2012-12-14 15:58:45 -08:00
|
|
|
|
2011-04-27 11:07:02 -07:00
|
|
|
#include "base/histogram.h"
|
2011-12-09 12:15:53 -08:00
|
|
|
#include "base/pickle.h"
|
2011-04-27 11:07:02 -07:00
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2013-04-19 04:54:18 -07:00
|
|
|
#include "nsThreadManager.h"
|
2013-01-07 11:45:25 -08:00
|
|
|
#include "nsCOMArray.h"
|
2011-04-27 11:07:02 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2013-01-08 06:04:37 -08:00
|
|
|
#include "nsXPCOMPrivate.h"
|
2014-01-03 09:02:48 -08:00
|
|
|
#include "nsIXULAppInfo.h"
|
|
|
|
#include "nsVersionComparator.h"
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2011-04-27 11:07:02 -07:00
|
|
|
#include "mozilla/ModuleUtils.h"
|
|
|
|
#include "nsIXPConnect.h"
|
|
|
|
#include "mozilla/Services.h"
|
2012-06-15 15:21:56 -07:00
|
|
|
#include "jsapi.h"
|
|
|
|
#include "jsfriendapi.h"
|
2013-01-27 12:35:12 -08:00
|
|
|
#include "js/GCAPI.h"
|
2013-09-23 10:25:00 -07:00
|
|
|
#include "nsString.h"
|
2011-04-27 11:07:02 -07:00
|
|
|
#include "nsITelemetry.h"
|
2011-12-09 12:15:53 -08:00
|
|
|
#include "nsIFile.h"
|
2013-01-31 13:11:38 -08:00
|
|
|
#include "nsIFileStreams.h"
|
2012-10-05 09:19:14 -07:00
|
|
|
#include "nsIMemoryReporter.h"
|
2013-01-31 13:11:38 -08:00
|
|
|
#include "nsISeekableStream.h"
|
2013-04-19 04:54:18 -07:00
|
|
|
#include "Telemetry.h"
|
2011-06-20 14:48:03 -07:00
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsBaseHashtable.h"
|
2011-05-21 23:23:20 -07:00
|
|
|
#include "nsXULAppAPI.h"
|
2014-02-13 13:20:45 -08:00
|
|
|
#include "nsReadableUtils.h"
|
2011-12-06 12:12:55 -08:00
|
|
|
#include "nsThreadUtils.h"
|
2014-02-13 13:20:45 -08:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#endif
|
2012-12-13 20:13:03 -08:00
|
|
|
#include "nsNetCID.h"
|
2013-01-31 13:11:38 -08:00
|
|
|
#include "nsNetUtil.h"
|
2012-12-13 09:06:27 -08:00
|
|
|
#include "plstr.h"
|
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
2013-11-22 11:17:31 -08:00
|
|
|
#include "mozilla/BackgroundHangMonitor.h"
|
2013-11-22 11:17:31 -08:00
|
|
|
#include "mozilla/ThreadHangStats.h"
|
2012-08-21 14:14:38 -07:00
|
|
|
#include "mozilla/ProcessedStack.h"
|
2011-12-06 12:12:55 -08:00
|
|
|
#include "mozilla/Mutex.h"
|
2011-12-09 12:15:53 -08:00
|
|
|
#include "mozilla/FileUtils.h"
|
2012-03-21 10:26:48 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-12-09 15:30:06 -08:00
|
|
|
#include "mozilla/StaticPtr.h"
|
|
|
|
#include "mozilla/IOInterposer.h"
|
2013-11-05 04:45:20 -08:00
|
|
|
#include "mozilla/PoisonIOInterposer.h"
|
2014-01-27 13:47:00 -08:00
|
|
|
#include "mozilla/StartupTimeline.h"
|
2013-08-14 04:17:47 -07:00
|
|
|
#if defined(MOZ_ENABLE_PROFILER_SPS)
|
|
|
|
#include "shared-libraries.h"
|
|
|
|
#endif
|
2011-04-27 11:07:02 -07:00
|
|
|
|
2014-01-03 09:02:48 -08:00
|
|
|
#define EXPIRED_ID "__expired__"
|
|
|
|
|
2011-05-19 19:33:05 -07:00
|
|
|
namespace {
|
|
|
|
|
2011-04-27 11:07:02 -07:00
|
|
|
using namespace base;
|
2011-06-20 14:47:58 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2012-02-13 11:47:40 -08:00
|
|
|
template<class EntryType>
|
|
|
|
class AutoHashtable : public nsTHashtable<EntryType>
|
|
|
|
{
|
|
|
|
public:
|
2012-05-16 04:39:21 -07:00
|
|
|
AutoHashtable(uint32_t initSize = PL_DHASH_MIN_SIZE);
|
2013-05-02 19:02:37 -07:00
|
|
|
typedef bool (*ReflectEntryFunc)(EntryType *entry, JSContext *cx, JS::Handle<JSObject*> obj);
|
|
|
|
bool ReflectIntoJS(ReflectEntryFunc entryFunc, JSContext *cx, JS::Handle<JSObject*> obj);
|
2012-02-13 11:47:40 -08:00
|
|
|
private:
|
|
|
|
struct EnumeratorArgs {
|
|
|
|
JSContext *cx;
|
2013-05-02 19:02:37 -07:00
|
|
|
JS::Handle<JSObject*> obj;
|
2012-02-13 11:47:40 -08:00
|
|
|
ReflectEntryFunc entryFunc;
|
|
|
|
};
|
|
|
|
static PLDHashOperator ReflectEntryStub(EntryType *entry, void *arg);
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class EntryType>
|
2012-05-16 04:39:21 -07:00
|
|
|
AutoHashtable<EntryType>::AutoHashtable(uint32_t initSize)
|
2013-09-02 01:41:57 -07:00
|
|
|
: nsTHashtable<EntryType>(initSize)
|
2012-02-13 11:47:40 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename EntryType>
|
|
|
|
PLDHashOperator
|
|
|
|
AutoHashtable<EntryType>::ReflectEntryStub(EntryType *entry, void *arg)
|
|
|
|
{
|
|
|
|
EnumeratorArgs *args = static_cast<EnumeratorArgs *>(arg);
|
|
|
|
if (!args->entryFunc(entry, args->cx, args->obj)) {
|
|
|
|
return PL_DHASH_STOP;
|
|
|
|
}
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reflect the individual entries of table into JS, usually by defining
|
|
|
|
* some property and value of obj. entryFunc is called for each entry.
|
|
|
|
*/
|
|
|
|
template<typename EntryType>
|
|
|
|
bool
|
2012-06-18 13:20:52 -07:00
|
|
|
AutoHashtable<EntryType>::ReflectIntoJS(ReflectEntryFunc entryFunc,
|
2013-05-02 19:02:37 -07:00
|
|
|
JSContext *cx, JS::Handle<JSObject*> obj)
|
2012-02-13 11:47:40 -08:00
|
|
|
{
|
|
|
|
EnumeratorArgs args = { cx, obj, entryFunc };
|
2012-05-16 04:39:21 -07:00
|
|
|
uint32_t num = this->EnumerateEntries(ReflectEntryStub, static_cast<void*>(&args));
|
2012-02-13 11:47:40 -08:00
|
|
|
return num == this->Count();
|
|
|
|
}
|
|
|
|
|
2012-11-05 10:45:19 -08:00
|
|
|
// This class is conceptually a list of ProcessedStack objects, but it represents them
|
|
|
|
// more efficiently by keeping a single global list of modules.
|
|
|
|
class CombinedStacks {
|
|
|
|
public:
|
|
|
|
typedef std::vector<Telemetry::ProcessedStack::Frame> Stack;
|
|
|
|
const Telemetry::ProcessedStack::Module& GetModule(unsigned aIndex) const;
|
|
|
|
size_t GetModuleCount() const;
|
|
|
|
const Stack& GetStack(unsigned aIndex) const;
|
|
|
|
void AddStack(const Telemetry::ProcessedStack& aStack);
|
|
|
|
size_t GetStackCount() const;
|
|
|
|
size_t SizeOfExcludingThis() const;
|
|
|
|
private:
|
|
|
|
std::vector<Telemetry::ProcessedStack::Module> mModules;
|
|
|
|
std::vector<Stack> mStacks;
|
|
|
|
};
|
|
|
|
|
2012-11-27 05:52:25 -08:00
|
|
|
static JSObject *
|
|
|
|
CreateJSStackObject(JSContext *cx, const CombinedStacks &stacks);
|
|
|
|
|
2012-11-05 10:45:19 -08:00
|
|
|
size_t
|
|
|
|
CombinedStacks::GetModuleCount() const {
|
|
|
|
return mModules.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Telemetry::ProcessedStack::Module&
|
|
|
|
CombinedStacks::GetModule(unsigned aIndex) const {
|
|
|
|
return mModules[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CombinedStacks::AddStack(const Telemetry::ProcessedStack& aStack) {
|
|
|
|
mStacks.resize(mStacks.size() + 1);
|
|
|
|
CombinedStacks::Stack& adjustedStack = mStacks.back();
|
|
|
|
|
|
|
|
size_t stackSize = aStack.GetStackSize();
|
2013-01-10 03:44:15 -08:00
|
|
|
for (size_t i = 0; i < stackSize; ++i) {
|
2012-11-05 10:45:19 -08:00
|
|
|
const Telemetry::ProcessedStack::Frame& frame = aStack.GetFrame(i);
|
|
|
|
uint16_t modIndex;
|
|
|
|
if (frame.mModIndex == std::numeric_limits<uint16_t>::max()) {
|
|
|
|
modIndex = frame.mModIndex;
|
|
|
|
} else {
|
|
|
|
const Telemetry::ProcessedStack::Module& module =
|
|
|
|
aStack.GetModule(frame.mModIndex);
|
|
|
|
std::vector<Telemetry::ProcessedStack::Module>::iterator modIterator =
|
|
|
|
std::find(mModules.begin(), mModules.end(), module);
|
|
|
|
if (modIterator == mModules.end()) {
|
|
|
|
mModules.push_back(module);
|
|
|
|
modIndex = mModules.size() - 1;
|
|
|
|
} else {
|
|
|
|
modIndex = modIterator - mModules.begin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Telemetry::ProcessedStack::Frame adjustedFrame = { frame.mOffset, modIndex };
|
|
|
|
adjustedStack.push_back(adjustedFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const CombinedStacks::Stack&
|
|
|
|
CombinedStacks::GetStack(unsigned aIndex) const {
|
|
|
|
return mStacks[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
CombinedStacks::GetStackCount() const {
|
|
|
|
return mStacks.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
CombinedStacks::SizeOfExcludingThis() const {
|
|
|
|
// This is a crude approximation. We would like to do something like
|
|
|
|
// aMallocSizeOf(&mModules[0]), but on linux aMallocSizeOf will call
|
|
|
|
// malloc_usable_size which is only safe on the pointers returned by malloc.
|
|
|
|
// While it works on current libstdc++, it is better to be safe and not assume
|
|
|
|
// that &vec[0] points to one. We could use a custom allocator, but
|
|
|
|
// it doesn't seem worth it.
|
|
|
|
size_t n = 0;
|
|
|
|
n += mModules.capacity() * sizeof(Telemetry::ProcessedStack::Module);
|
|
|
|
n += mStacks.capacity() * sizeof(Stack);
|
|
|
|
for (std::vector<Stack>::const_iterator i = mStacks.begin(),
|
|
|
|
e = mStacks.end(); i != e; ++i) {
|
|
|
|
const Stack& s = *i;
|
|
|
|
n += s.capacity() * sizeof(Telemetry::ProcessedStack::Frame);
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
class HangReports {
|
|
|
|
public:
|
|
|
|
size_t SizeOfExcludingThis() const;
|
2014-01-27 13:47:00 -08:00
|
|
|
void AddHang(const Telemetry::ProcessedStack& aStack, uint32_t aDuration,
|
|
|
|
int32_t aSystemUptime, int32_t aFirefoxUptime);
|
2012-11-05 10:45:19 -08:00
|
|
|
uint32_t GetDuration(unsigned aIndex) const;
|
2014-01-27 13:47:00 -08:00
|
|
|
int32_t GetSystemUptime(unsigned aIndex) const;
|
|
|
|
int32_t GetFirefoxUptime(unsigned aIndex) const;
|
2012-11-27 05:52:25 -08:00
|
|
|
const CombinedStacks& GetStacks() const;
|
2012-11-05 10:45:19 -08:00
|
|
|
private:
|
2014-01-27 13:47:00 -08:00
|
|
|
struct HangInfo {
|
|
|
|
// Hang duration (in seconds)
|
|
|
|
uint32_t mDuration;
|
|
|
|
// System uptime (in minutes) at the time of the hang
|
|
|
|
int32_t mSystemUptime;
|
|
|
|
// Firefox uptime (in minutes) at the time of the hang
|
|
|
|
int32_t mFirefoxUptime;
|
|
|
|
};
|
|
|
|
std::vector<HangInfo> mHangInfo;
|
2012-11-05 10:45:19 -08:00
|
|
|
CombinedStacks mStacks;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2014-01-27 13:47:00 -08:00
|
|
|
HangReports::AddHang(const Telemetry::ProcessedStack& aStack,
|
|
|
|
uint32_t aDuration,
|
|
|
|
int32_t aSystemUptime,
|
|
|
|
int32_t aFirefoxUptime) {
|
|
|
|
HangInfo info = { aDuration, aSystemUptime, aFirefoxUptime };
|
|
|
|
mHangInfo.push_back(info);
|
2012-11-05 10:45:19 -08:00
|
|
|
mStacks.AddStack(aStack);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
HangReports::SizeOfExcludingThis() const {
|
|
|
|
size_t n = 0;
|
|
|
|
n += mStacks.SizeOfExcludingThis();
|
|
|
|
// This is a crude approximation. See comment on
|
|
|
|
// CombinedStacks::SizeOfExcludingThis.
|
2014-01-27 13:47:00 -08:00
|
|
|
n += mHangInfo.capacity() * sizeof(HangInfo);
|
2012-11-05 10:45:19 -08:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2012-11-27 05:52:25 -08:00
|
|
|
const CombinedStacks&
|
|
|
|
HangReports::GetStacks() const {
|
|
|
|
return mStacks;
|
2012-11-05 10:45:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
HangReports::GetDuration(unsigned aIndex) const {
|
2014-01-27 13:47:00 -08:00
|
|
|
return mHangInfo[aIndex].mDuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
HangReports::GetSystemUptime(unsigned aIndex) const {
|
|
|
|
return mHangInfo[aIndex].mSystemUptime;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
HangReports::GetFirefoxUptime(unsigned aIndex) const {
|
|
|
|
return mHangInfo[aIndex].mFirefoxUptime;
|
2012-11-05 10:45:19 -08:00
|
|
|
}
|
|
|
|
|
2013-12-09 15:30:06 -08:00
|
|
|
/**
|
|
|
|
* IOInterposeObserver recording statistics of main-thread I/O during execution,
|
|
|
|
* aimed at consumption by TelemetryImpl
|
|
|
|
*/
|
|
|
|
class TelemetryIOInterposeObserver : public IOInterposeObserver
|
|
|
|
{
|
|
|
|
/** File-level statistics structure */
|
|
|
|
struct FileStats {
|
|
|
|
FileStats()
|
|
|
|
: creates(0)
|
|
|
|
, reads(0)
|
|
|
|
, writes(0)
|
|
|
|
, fsyncs(0)
|
|
|
|
, stats(0)
|
|
|
|
, totalTime(0)
|
|
|
|
{}
|
|
|
|
uint32_t creates; /** Number of create/open operations */
|
|
|
|
uint32_t reads; /** Number of read operations */
|
|
|
|
uint32_t writes; /** Number of write operations */
|
|
|
|
uint32_t fsyncs; /** Number of fsync operations */
|
|
|
|
uint32_t stats; /** Number of stat operations */
|
|
|
|
double totalTime; /** Accumulated duration of all operations */
|
|
|
|
};
|
2014-02-11 13:24:49 -08:00
|
|
|
|
|
|
|
struct SafeDir {
|
|
|
|
SafeDir(const nsAString& aPath, const nsAString& aSubstName)
|
|
|
|
: mPath(aPath)
|
|
|
|
, mSubstName(aSubstName)
|
|
|
|
{}
|
|
|
|
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
|
|
|
|
return mPath.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
|
|
|
|
mSubstName.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
nsString mPath; /** Path to the directory */
|
|
|
|
nsString mSubstName; /** Name to substitute with */
|
|
|
|
};
|
|
|
|
|
2013-12-09 15:30:06 -08:00
|
|
|
public:
|
|
|
|
TelemetryIOInterposeObserver(nsIFile* aXreDir);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An implementation of Observe that records statistics of all
|
|
|
|
* file IO operations.
|
|
|
|
*/
|
|
|
|
void Observe(Observation& aOb);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reflect recorded file IO statistics into Javascript
|
|
|
|
*/
|
|
|
|
bool ReflectIntoJS(JSContext *cx, JS::Handle<JSObject*> rootObj);
|
|
|
|
|
2014-02-11 13:24:49 -08:00
|
|
|
/**
|
|
|
|
* Adds a path for inclusion in main thread I/O report.
|
|
|
|
* @param aPath Directory path
|
|
|
|
* @param aSubstName Name to substitute for aPath for privacy reasons
|
|
|
|
*/
|
|
|
|
void AddPath(const nsAString& aPath, const nsAString& aSubstName);
|
2013-12-09 15:30:06 -08:00
|
|
|
|
2014-03-18 15:07:35 -07:00
|
|
|
enum Stage
|
|
|
|
{
|
|
|
|
STAGE_STARTUP = 0,
|
|
|
|
STAGE_NORMAL,
|
|
|
|
STAGE_SHUTDOWN,
|
|
|
|
NUM_STAGES
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a new stage in the lifecycle of this process.
|
|
|
|
* @param aNewStage One of the STAGE_* enum values.
|
|
|
|
*/
|
|
|
|
inline void SetStage(Stage aNewStage)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aNewStage != NUM_STAGES);
|
|
|
|
mCurStage = aNewStage;
|
|
|
|
}
|
|
|
|
|
2014-01-31 19:14:51 -08:00
|
|
|
/**
|
|
|
|
* Get size of hash table with file stats
|
|
|
|
*/
|
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
|
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
|
|
|
|
size_t size;
|
|
|
|
size = mFileStats.SizeOfExcludingThis(SizeOfFileIOEntryTypeExcludingThis,
|
|
|
|
aMallocSizeOf) +
|
|
|
|
mSafeDirs.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
uint32_t safeDirsLen = mSafeDirs.Length();
|
|
|
|
for (uint32_t i = 0; i < safeDirsLen; ++i) {
|
2014-02-11 13:24:49 -08:00
|
|
|
size += mSafeDirs[i].SizeOfExcludingThis(aMallocSizeOf);
|
2014-01-31 19:14:51 -08:00
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2013-12-09 15:30:06 -08:00
|
|
|
private:
|
2014-03-18 15:07:35 -07:00
|
|
|
struct FileStatsByStage
|
|
|
|
{
|
|
|
|
FileStats mStats[NUM_STAGES];
|
|
|
|
};
|
|
|
|
typedef nsBaseHashtableET<nsStringHashKey, FileStatsByStage> FileIOEntryType;
|
|
|
|
|
2013-12-09 15:30:06 -08:00
|
|
|
// Statistics for each filename
|
|
|
|
AutoHashtable<FileIOEntryType> mFileStats;
|
|
|
|
// Container for whitelisted directories
|
2014-02-11 13:24:49 -08:00
|
|
|
nsTArray<SafeDir> mSafeDirs;
|
2014-03-18 15:07:35 -07:00
|
|
|
Stage mCurStage;
|
2013-12-09 15:30:06 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reflect a FileIOEntryType object to a Javascript property on obj with
|
|
|
|
* filename as key containing array:
|
|
|
|
* [totalTime, creates, reads, writes, fsyncs, stats]
|
|
|
|
*/
|
|
|
|
static bool ReflectFileStats(FileIOEntryType* entry, JSContext *cx,
|
|
|
|
JS::Handle<JSObject*> obj);
|
2014-01-31 19:14:51 -08:00
|
|
|
|
|
|
|
static size_t SizeOfFileIOEntryTypeExcludingThis(FileIOEntryType* aEntry,
|
|
|
|
mozilla::MallocSizeOf mallocSizeOf,
|
|
|
|
void*)
|
|
|
|
{
|
|
|
|
return aEntry->GetKey().SizeOfExcludingThisIfUnshared(mallocSizeOf);
|
|
|
|
}
|
2013-12-09 15:30:06 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
TelemetryIOInterposeObserver::TelemetryIOInterposeObserver(nsIFile* aXreDir)
|
2014-03-18 15:07:35 -07:00
|
|
|
: mCurStage(STAGE_STARTUP)
|
2013-12-09 15:30:06 -08:00
|
|
|
{
|
|
|
|
nsAutoString xreDirPath;
|
|
|
|
nsresult rv = aXreDir->GetPath(xreDirPath);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2014-02-11 13:24:49 -08:00
|
|
|
AddPath(xreDirPath, NS_LITERAL_STRING("{xre}"));
|
2013-12-09 15:30:06 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-11 13:24:49 -08:00
|
|
|
void TelemetryIOInterposeObserver::AddPath(const nsAString& aPath,
|
|
|
|
const nsAString& aSubstName)
|
2013-12-09 15:30:06 -08:00
|
|
|
{
|
2014-02-11 13:24:49 -08:00
|
|
|
mSafeDirs.AppendElement(SafeDir(aPath, aSubstName));
|
2013-12-09 15:30:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TelemetryIOInterposeObserver::Observe(Observation& aOb)
|
|
|
|
{
|
|
|
|
// We only report main-thread I/O
|
2014-03-14 15:35:01 -07:00
|
|
|
if (!IsMainThread()) {
|
2013-12-09 15:30:06 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the filename
|
|
|
|
const char16_t* filename = aOb.Filename();
|
|
|
|
|
|
|
|
// Discard observations without filename
|
|
|
|
if (!filename) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-13 13:20:45 -08:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
nsCaseInsensitiveStringComparator comparator;
|
|
|
|
#else
|
|
|
|
nsDefaultStringComparator comparator;
|
|
|
|
#endif
|
2014-02-11 13:24:49 -08:00
|
|
|
nsAutoString processedName;
|
2013-12-09 15:30:06 -08:00
|
|
|
nsDependentString filenameStr(filename);
|
|
|
|
uint32_t safeDirsLen = mSafeDirs.Length();
|
|
|
|
for (uint32_t i = 0; i < safeDirsLen; ++i) {
|
2014-02-13 13:20:45 -08:00
|
|
|
if (StringBeginsWith(filenameStr, mSafeDirs[i].mPath, comparator)) {
|
|
|
|
processedName = mSafeDirs[i].mSubstName;
|
|
|
|
processedName += Substring(filenameStr, mSafeDirs[i].mPath.Length());
|
|
|
|
break;
|
2013-12-09 15:30:06 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-11 13:24:49 -08:00
|
|
|
if (processedName.IsEmpty()) {
|
2013-12-09 15:30:06 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new entry or retrieve the existing one
|
2014-02-11 13:24:49 -08:00
|
|
|
FileIOEntryType* entry = mFileStats.PutEntry(processedName);
|
2013-12-09 15:30:06 -08:00
|
|
|
if (entry) {
|
2014-03-18 15:07:35 -07:00
|
|
|
FileStats& stats = entry->mData.mStats[mCurStage];
|
2013-12-09 15:30:06 -08:00
|
|
|
// Update the statistics
|
2014-03-18 15:07:35 -07:00
|
|
|
stats.totalTime += (double) aOb.Duration().ToMilliseconds();
|
2013-12-09 15:30:06 -08:00
|
|
|
switch (aOb.ObservedOperation()) {
|
|
|
|
case OpCreateOrOpen:
|
2014-03-18 15:07:35 -07:00
|
|
|
stats.creates++;
|
2013-12-09 15:30:06 -08:00
|
|
|
break;
|
|
|
|
case OpRead:
|
2014-03-18 15:07:35 -07:00
|
|
|
stats.reads++;
|
2013-12-09 15:30:06 -08:00
|
|
|
break;
|
|
|
|
case OpWrite:
|
2014-03-18 15:07:35 -07:00
|
|
|
stats.writes++;
|
2013-12-09 15:30:06 -08:00
|
|
|
break;
|
|
|
|
case OpFSync:
|
2014-03-18 15:07:35 -07:00
|
|
|
stats.fsyncs++;
|
2013-12-09 15:30:06 -08:00
|
|
|
break;
|
|
|
|
case OpStat:
|
2014-03-18 15:07:35 -07:00
|
|
|
stats.stats++;
|
2013-12-09 15:30:06 -08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TelemetryIOInterposeObserver::ReflectFileStats(FileIOEntryType* entry,
|
|
|
|
JSContext *cx,
|
|
|
|
JS::Handle<JSObject*> obj)
|
|
|
|
{
|
2014-03-18 15:07:35 -07:00
|
|
|
JS::AutoValueArray<NUM_STAGES> stages(cx);
|
2013-12-09 15:30:06 -08:00
|
|
|
|
2014-03-18 15:07:35 -07:00
|
|
|
FileStatsByStage& statsByStage = entry->mData;
|
|
|
|
for (int s = STAGE_STARTUP; s < NUM_STAGES; ++s) {
|
|
|
|
FileStats& fileStats = statsByStage.mStats[s];
|
2013-12-09 15:30:06 -08:00
|
|
|
|
2014-03-18 15:07:35 -07:00
|
|
|
if (fileStats.totalTime == 0 && fileStats.creates == 0 &&
|
|
|
|
fileStats.reads == 0 && fileStats.writes == 0 &&
|
|
|
|
fileStats.fsyncs == 0 && fileStats.stats == 0) {
|
|
|
|
// Don't add an array that contains no information
|
|
|
|
stages[s].setNull();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Array we want to report
|
|
|
|
JS::AutoValueArray<6> stats(cx);
|
|
|
|
stats[0].setNumber(fileStats.totalTime);
|
|
|
|
stats[1].setNumber(fileStats.creates);
|
|
|
|
stats[2].setNumber(fileStats.reads);
|
|
|
|
stats[3].setNumber(fileStats.writes);
|
|
|
|
stats[4].setNumber(fileStats.fsyncs);
|
|
|
|
stats[5].setNumber(fileStats.stats);
|
|
|
|
|
|
|
|
// Create jsStats as array of elements above
|
|
|
|
JS::RootedObject jsStats(cx, JS_NewArrayObject(cx, stats));
|
|
|
|
if (!jsStats) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
stages[s].setObject(*jsStats);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::RootedObject jsEntry(cx, JS_NewArrayObject(cx, stages));
|
2013-12-09 15:30:06 -08:00
|
|
|
if (!jsEntry) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add jsEntry to top-level dictionary
|
|
|
|
const nsAString& key = entry->GetKey();
|
|
|
|
return JS_DefineUCProperty(cx, obj, key.Data(), key.Length(),
|
2014-03-18 15:07:35 -07:00
|
|
|
OBJECT_TO_JSVAL(jsEntry), nullptr, nullptr,
|
|
|
|
JSPROP_ENUMERATE | JSPROP_READONLY);
|
2013-12-09 15:30:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TelemetryIOInterposeObserver::ReflectIntoJS(JSContext *cx,
|
|
|
|
JS::Handle<JSObject*> rootObj)
|
|
|
|
{
|
|
|
|
return mFileStats.ReflectIntoJS(ReflectFileStats, cx, rootObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is not a member of TelemetryImpl because we want to record I/O during
|
|
|
|
// startup.
|
|
|
|
StaticAutoPtr<TelemetryIOInterposeObserver> sTelemetryIOObserver;
|
|
|
|
|
|
|
|
void
|
|
|
|
ClearIOReporting()
|
|
|
|
{
|
|
|
|
if (!sTelemetryIOObserver) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
IOInterposer::Unregister(IOInterposeObserver::OpAll, sTelemetryIOObserver);
|
|
|
|
sTelemetryIOObserver = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-11-06 21:35:30 -08:00
|
|
|
class TelemetryImpl MOZ_FINAL
|
2013-12-07 22:09:10 -08:00
|
|
|
: public nsITelemetry
|
|
|
|
, public nsIMemoryReporter
|
2011-04-27 11:07:02 -07:00
|
|
|
{
|
2013-07-18 19:24:15 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2011-04-27 11:07:02 -07:00
|
|
|
NS_DECL_NSITELEMETRY
|
2013-12-07 22:09:10 -08:00
|
|
|
NS_DECL_NSIMEMORYREPORTER
|
2011-04-27 11:07:02 -07:00
|
|
|
|
2011-05-19 19:33:05 -07:00
|
|
|
public:
|
2011-06-20 14:48:03 -07:00
|
|
|
~TelemetryImpl();
|
2013-11-06 21:35:30 -08:00
|
|
|
|
|
|
|
void InitMemoryReporter();
|
|
|
|
|
2011-06-28 16:57:44 -07:00
|
|
|
static bool CanRecord();
|
|
|
|
static already_AddRefed<nsITelemetry> CreateTelemetryInstance();
|
|
|
|
static void ShutdownTelemetry();
|
2012-03-21 10:26:48 -07:00
|
|
|
static void RecordSlowStatement(const nsACString &sql, const nsACString &dbName,
|
2012-08-21 12:29:28 -07:00
|
|
|
uint32_t delay);
|
2012-03-14 19:57:04 -07:00
|
|
|
#if defined(MOZ_ENABLE_PROFILER_SPS)
|
2014-01-27 13:47:00 -08:00
|
|
|
static void RecordChromeHang(uint32_t aDuration,
|
|
|
|
Telemetry::ProcessedStack &aStack,
|
|
|
|
int32_t aSystemUptime,
|
|
|
|
int32_t aFirefoxUptime);
|
2012-03-14 19:57:04 -07:00
|
|
|
#endif
|
2013-11-22 11:17:31 -08:00
|
|
|
static void RecordThreadHangStats(Telemetry::ThreadHangStats& aStats);
|
2012-01-06 14:13:02 -08:00
|
|
|
static nsresult GetHistogramEnumId(const char *name, Telemetry::ID *id);
|
2013-11-06 21:35:30 -08:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
|
2012-08-21 12:29:28 -07:00
|
|
|
struct Stat {
|
2012-05-16 04:39:21 -07:00
|
|
|
uint32_t hitCount;
|
|
|
|
uint32_t totalTime;
|
2012-08-21 12:29:28 -07:00
|
|
|
};
|
|
|
|
struct StmtStats {
|
|
|
|
struct Stat mainThread;
|
|
|
|
struct Stat otherThreads;
|
2011-12-06 12:12:55 -08:00
|
|
|
};
|
|
|
|
typedef nsBaseHashtableET<nsCStringHashKey, StmtStats> SlowSQLEntryType;
|
2011-06-20 14:47:58 -07:00
|
|
|
|
|
|
|
private:
|
2013-11-06 21:35:30 -08:00
|
|
|
TelemetryImpl();
|
2012-10-05 09:19:14 -07:00
|
|
|
|
2012-08-21 12:29:28 -07:00
|
|
|
static nsCString SanitizeSQL(const nsACString& sql);
|
|
|
|
|
|
|
|
enum SanitizedState { Sanitized, Unsanitized };
|
|
|
|
|
2012-05-16 04:39:21 -07:00
|
|
|
static void StoreSlowSQL(const nsACString &offender, uint32_t delay,
|
2012-08-21 12:29:28 -07:00
|
|
|
SanitizedState state);
|
2012-03-21 10:26:48 -07:00
|
|
|
|
2012-08-21 12:29:28 -07:00
|
|
|
static bool ReflectMainThreadSQL(SlowSQLEntryType *entry, JSContext *cx,
|
2013-05-02 19:02:37 -07:00
|
|
|
JS::Handle<JSObject*> obj);
|
2012-08-21 12:29:28 -07:00
|
|
|
static bool ReflectOtherThreadsSQL(SlowSQLEntryType *entry, JSContext *cx,
|
2013-05-02 19:02:37 -07:00
|
|
|
JS::Handle<JSObject*> obj);
|
2012-08-21 12:29:28 -07:00
|
|
|
static bool ReflectSQL(const SlowSQLEntryType *entry, const Stat *stat,
|
2013-05-02 19:02:37 -07:00
|
|
|
JSContext *cx, JS::Handle<JSObject*> obj);
|
2012-03-21 10:26:48 -07:00
|
|
|
|
2013-05-02 19:02:37 -07:00
|
|
|
bool AddSQLInfo(JSContext *cx, JS::Handle<JSObject*> rootObj, bool mainThread,
|
2012-08-21 12:29:28 -07:00
|
|
|
bool privateSQL);
|
2014-01-09 09:39:36 -08:00
|
|
|
bool GetSQLStats(JSContext *cx, JS::MutableHandle<JS::Value> ret,
|
|
|
|
bool includePrivateSql);
|
2011-12-06 12:12:55 -08:00
|
|
|
|
2012-01-06 11:39:29 -08:00
|
|
|
// Like GetHistogramById, but returns the underlying C++ object, not the JS one.
|
|
|
|
nsresult GetHistogramByName(const nsACString &name, Histogram **ret);
|
2012-01-06 14:13:02 -08:00
|
|
|
bool ShouldReflectHistogram(Histogram *h);
|
|
|
|
void IdentifyCorruptHistograms(StatisticsRecorder::Histograms &hs);
|
|
|
|
typedef StatisticsRecorder::Histograms::iterator HistogramIterator;
|
2012-01-20 13:56:48 -08:00
|
|
|
|
|
|
|
struct AddonHistogramInfo {
|
2012-05-16 04:39:21 -07:00
|
|
|
uint32_t min;
|
|
|
|
uint32_t max;
|
|
|
|
uint32_t bucketCount;
|
|
|
|
uint32_t histogramType;
|
2012-01-20 13:56:48 -08:00
|
|
|
Histogram *h;
|
|
|
|
};
|
|
|
|
typedef nsBaseHashtableET<nsCStringHashKey, AddonHistogramInfo> AddonHistogramEntryType;
|
|
|
|
typedef AutoHashtable<AddonHistogramEntryType> AddonHistogramMapType;
|
|
|
|
typedef nsBaseHashtableET<nsCStringHashKey, AddonHistogramMapType *> AddonEntryType;
|
|
|
|
typedef AutoHashtable<AddonEntryType> AddonMapType;
|
|
|
|
static bool AddonHistogramReflector(AddonHistogramEntryType *entry,
|
2013-05-02 19:02:37 -07:00
|
|
|
JSContext *cx, JS::Handle<JSObject*> obj);
|
|
|
|
static bool AddonReflector(AddonEntryType *entry, JSContext *cx, JS::Handle<JSObject*> obj);
|
2012-03-02 06:59:38 -08:00
|
|
|
static bool CreateHistogramForAddon(const nsACString &name,
|
|
|
|
AddonHistogramInfo &info);
|
2013-05-10 08:37:13 -07:00
|
|
|
void ReadLateWritesStacks(nsIFile* aProfileDir);
|
2012-01-20 13:56:48 -08:00
|
|
|
AddonMapType mAddonMap;
|
|
|
|
|
2012-01-06 14:13:02 -08:00
|
|
|
// This is used for speedy string->Telemetry::ID conversions
|
2011-06-20 14:48:03 -07:00
|
|
|
typedef nsBaseHashtableET<nsCharPtrHashKey, Telemetry::ID> CharPtrEntryType;
|
2012-02-13 11:47:40 -08:00
|
|
|
typedef AutoHashtable<CharPtrEntryType> HistogramMapType;
|
2011-06-20 14:48:03 -07:00
|
|
|
HistogramMapType mHistogramMap;
|
2011-06-28 16:57:44 -07:00
|
|
|
bool mCanRecord;
|
|
|
|
static TelemetryImpl *sTelemetry;
|
2012-08-21 12:29:28 -07:00
|
|
|
AutoHashtable<SlowSQLEntryType> mPrivateSQL;
|
|
|
|
AutoHashtable<SlowSQLEntryType> mSanitizedSQL;
|
2012-02-13 11:47:40 -08:00
|
|
|
// This gets marked immutable in debug builds, so we can't use
|
|
|
|
// AutoHashtable here.
|
2011-12-06 12:12:55 -08:00
|
|
|
nsTHashtable<nsCStringHashKey> mTrackedDBs;
|
|
|
|
Mutex mHashMutex;
|
2012-11-05 10:45:19 -08:00
|
|
|
HangReports mHangReports;
|
2012-03-12 04:07:05 -07:00
|
|
|
Mutex mHangReportsMutex;
|
2013-11-22 11:17:31 -08:00
|
|
|
// mThreadHangStats stores recorded, inactive thread hang stats
|
|
|
|
Vector<Telemetry::ThreadHangStats> mThreadHangStats;
|
|
|
|
Mutex mThreadHangStatsMutex;
|
2012-12-13 09:06:27 -08:00
|
|
|
|
2013-01-08 06:04:37 -08:00
|
|
|
CombinedStacks mLateWritesStacks; // This is collected out of the main thread.
|
2012-12-19 07:29:08 -08:00
|
|
|
bool mCachedTelemetryData;
|
2012-12-13 09:06:27 -08:00
|
|
|
uint32_t mLastShutdownTime;
|
2013-01-31 13:11:38 -08:00
|
|
|
uint32_t mFailedLockCount;
|
2013-01-07 11:45:25 -08:00
|
|
|
nsCOMArray<nsIFetchTelemetryDataCallback> mCallbacks;
|
2012-12-19 07:29:08 -08:00
|
|
|
friend class nsFetchTelemetryData;
|
2011-04-27 11:07:02 -07:00
|
|
|
};
|
|
|
|
|
2013-10-10 13:38:05 -07:00
|
|
|
TelemetryImpl* TelemetryImpl::sTelemetry = nullptr;
|
2011-06-28 16:57:44 -07:00
|
|
|
|
2013-12-07 22:09:10 -08:00
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF(TelemetryMallocSizeOf)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TelemetryImpl::CollectReports(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData)
|
2013-11-06 21:35:30 -08:00
|
|
|
{
|
2013-12-07 22:09:10 -08:00
|
|
|
return MOZ_COLLECT_REPORT(
|
|
|
|
"explicit/telemetry", KIND_HEAP, UNITS_BYTES,
|
|
|
|
SizeOfIncludingThis(TelemetryMallocSizeOf),
|
|
|
|
"Memory used by the telemetry system.");
|
2013-11-06 21:35:30 -08:00
|
|
|
}
|
|
|
|
|
2011-05-19 19:33:05 -07:00
|
|
|
// A initializer to initialize histogram collection
|
|
|
|
StatisticsRecorder gStatisticsRecorder;
|
2011-04-27 11:07:02 -07:00
|
|
|
|
2011-06-20 14:47:58 -07:00
|
|
|
// Hardcoded probes
|
|
|
|
struct TelemetryHistogram {
|
2012-05-16 04:39:21 -07:00
|
|
|
uint32_t min;
|
|
|
|
uint32_t max;
|
|
|
|
uint32_t bucketCount;
|
|
|
|
uint32_t histogramType;
|
2013-11-06 06:02:29 -08:00
|
|
|
uint32_t id_offset;
|
2014-01-03 09:02:48 -08:00
|
|
|
uint32_t expiration_offset;
|
2013-02-13 07:51:24 -08:00
|
|
|
bool extendedStatisticsOK;
|
2012-08-28 09:55:32 -07:00
|
|
|
|
|
|
|
const char *id() const;
|
2014-01-03 09:02:48 -08:00
|
|
|
const char *expiration() const;
|
2011-06-20 14:47:58 -07:00
|
|
|
};
|
|
|
|
|
2012-08-24 12:54:55 -07:00
|
|
|
#include "TelemetryHistogramData.inc"
|
2012-01-06 14:13:02 -08:00
|
|
|
bool gCorruptHistograms[Telemetry::HistogramCount];
|
2011-06-20 14:47:58 -07:00
|
|
|
|
2012-08-28 09:55:32 -07:00
|
|
|
const char *
|
|
|
|
TelemetryHistogram::id() const
|
|
|
|
{
|
|
|
|
return &gHistogramStringTable[this->id_offset];
|
|
|
|
}
|
|
|
|
|
2014-01-03 09:02:48 -08:00
|
|
|
const char *
|
|
|
|
TelemetryHistogram::expiration() const
|
2014-01-03 08:31:17 -08:00
|
|
|
{
|
2014-01-03 09:02:48 -08:00
|
|
|
return &gHistogramStringTable[this->expiration_offset];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsExpired(const char *expiration){
|
|
|
|
static Version current_version = Version(MOZ_APP_VERSION);
|
|
|
|
MOZ_ASSERT(expiration);
|
|
|
|
return strcmp(expiration, "never") && (mozilla::Version(expiration) <= current_version);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsExpired(const Histogram *histogram){
|
|
|
|
return histogram->histogram_name() == EXPIRED_ID;
|
2012-01-06 11:40:04 -08:00
|
|
|
}
|
|
|
|
|
2011-06-20 14:47:58 -07:00
|
|
|
nsresult
|
2014-01-03 09:02:48 -08:00
|
|
|
HistogramGet(const char *name, const char *expiration, uint32_t min, uint32_t max,
|
|
|
|
uint32_t bucketCount, uint32_t histogramType, Histogram **result)
|
2011-06-20 14:47:58 -07:00
|
|
|
{
|
2012-03-02 06:59:38 -08:00
|
|
|
if (histogramType != nsITelemetry::HISTOGRAM_BOOLEAN
|
|
|
|
&& histogramType != nsITelemetry::HISTOGRAM_FLAG) {
|
2011-06-20 14:47:58 -07:00
|
|
|
// Sanity checks for histogram parameters.
|
|
|
|
if (min >= max)
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
|
|
|
if (bucketCount <= 2)
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
|
|
|
if (min < 1)
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
2014-01-03 09:02:48 -08:00
|
|
|
if (IsExpired(expiration)) {
|
|
|
|
name = EXPIRED_ID;
|
|
|
|
min = 1;
|
|
|
|
max = 2;
|
|
|
|
bucketCount = 3;
|
|
|
|
histogramType = nsITelemetry::HISTOGRAM_LINEAR;
|
|
|
|
}
|
|
|
|
|
2011-06-20 14:47:58 -07:00
|
|
|
switch (histogramType) {
|
|
|
|
case nsITelemetry::HISTOGRAM_EXPONENTIAL:
|
2011-06-30 14:58:00 -07:00
|
|
|
*result = Histogram::FactoryGet(name, min, max, bucketCount, Histogram::kUmaTargetedHistogramFlag);
|
2011-06-20 14:47:58 -07:00
|
|
|
break;
|
|
|
|
case nsITelemetry::HISTOGRAM_LINEAR:
|
2011-06-30 14:58:00 -07:00
|
|
|
*result = LinearHistogram::FactoryGet(name, min, max, bucketCount, Histogram::kUmaTargetedHistogramFlag);
|
2011-06-20 14:47:58 -07:00
|
|
|
break;
|
|
|
|
case nsITelemetry::HISTOGRAM_BOOLEAN:
|
2011-06-30 14:58:00 -07:00
|
|
|
*result = BooleanHistogram::FactoryGet(name, Histogram::kUmaTargetedHistogramFlag);
|
2011-06-20 14:47:58 -07:00
|
|
|
break;
|
2012-03-02 06:59:38 -08:00
|
|
|
case nsITelemetry::HISTOGRAM_FLAG:
|
|
|
|
*result = FlagHistogram::FactoryGet(name, Histogram::kUmaTargetedHistogramFlag);
|
|
|
|
break;
|
2011-06-20 14:47:58 -07:00
|
|
|
default:
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// O(1) histogram lookup by numeric id
|
|
|
|
nsresult
|
|
|
|
GetHistogramByEnumId(Telemetry::ID id, Histogram **ret)
|
|
|
|
{
|
|
|
|
static Histogram* knownHistograms[Telemetry::HistogramCount] = {0};
|
|
|
|
Histogram *h = knownHistograms[id];
|
|
|
|
if (h) {
|
|
|
|
*ret = h;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TelemetryHistogram &p = gHistograms[id];
|
2014-01-03 09:02:48 -08:00
|
|
|
nsresult rv = HistogramGet(p.id(), p.expiration(), p.min, p.max, p.bucketCount, p.histogramType, &h);
|
2011-06-20 14:47:58 -07:00
|
|
|
if (NS_FAILED(rv))
|
2011-08-05 06:53:48 -07:00
|
|
|
return rv;
|
2011-06-20 14:47:58 -07:00
|
|
|
|
2012-08-27 13:47:32 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Check that the C++ Histogram code computes the same ranges as the
|
|
|
|
// Python histogram code.
|
2014-01-03 09:02:48 -08:00
|
|
|
if (!IsExpired(p.expiration())) {
|
|
|
|
const struct bounds &b = gBucketLowerBoundIndex[id];
|
|
|
|
if (b.length != 0) {
|
|
|
|
MOZ_ASSERT(size_t(b.length) == h->bucket_count(),
|
|
|
|
"C++/Python bucket # mismatch");
|
|
|
|
for (int i = 0; i < b.length; ++i) {
|
|
|
|
MOZ_ASSERT(gBucketLowerBounds[b.offset + i] == h->ranges(i),
|
|
|
|
"C++/Python bucket mismatch");
|
|
|
|
}
|
2012-08-27 13:47:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-02-13 07:51:24 -08:00
|
|
|
if (p.extendedStatisticsOK) {
|
|
|
|
h->SetFlags(Histogram::kExtendedStatisticsFlag);
|
|
|
|
}
|
2011-06-20 14:47:58 -07:00
|
|
|
*ret = knownHistograms[id] = h;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-19 19:33:05 -07:00
|
|
|
bool
|
2013-05-01 15:43:53 -07:00
|
|
|
FillRanges(JSContext *cx, JS::Handle<JSObject*> array, Histogram *h)
|
2011-04-27 11:07:02 -07:00
|
|
|
{
|
2013-05-02 19:02:37 -07:00
|
|
|
JS::Rooted<JS::Value> range(cx);
|
2011-06-20 14:47:58 -07:00
|
|
|
for (size_t i = 0; i < h->bucket_count(); i++) {
|
2013-05-02 19:02:37 -07:00
|
|
|
range = INT_TO_JSVAL(h->ranges(i));
|
|
|
|
if (!JS_DefineElement(cx, array, i, range, nullptr, nullptr, JSPROP_ENUMERATE))
|
2011-04-27 11:07:02 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-06 14:13:02 -08:00
|
|
|
enum reflectStatus {
|
|
|
|
REFLECT_OK,
|
|
|
|
REFLECT_CORRUPT,
|
|
|
|
REFLECT_FAILURE
|
|
|
|
};
|
|
|
|
|
|
|
|
enum reflectStatus
|
2013-05-02 19:02:37 -07:00
|
|
|
ReflectHistogramAndSamples(JSContext *cx, JS::Handle<JSObject*> obj, Histogram *h,
|
2011-12-13 09:03:30 -08:00
|
|
|
const Histogram::SampleSet &ss)
|
2011-04-27 11:07:02 -07:00
|
|
|
{
|
2012-01-06 14:13:02 -08:00
|
|
|
// We don't want to reflect corrupt histograms.
|
|
|
|
if (h->FindCorruption(ss) != Histogram::NO_INCONSISTENCIES) {
|
|
|
|
return REFLECT_CORRUPT;
|
|
|
|
}
|
|
|
|
|
2014-01-21 18:11:17 -08:00
|
|
|
if (!(JS_DefineProperty(cx, obj, "min", h->declared_min(), JSPROP_ENUMERATE)
|
|
|
|
&& JS_DefineProperty(cx, obj, "max", h->declared_max(), JSPROP_ENUMERATE)
|
|
|
|
&& JS_DefineProperty(cx, obj, "histogram_type", h->histogram_type(), JSPROP_ENUMERATE)
|
|
|
|
&& JS_DefineProperty(cx, obj, "sum", double(ss.sum()), JSPROP_ENUMERATE))) {
|
2012-11-30 12:50:23 -08:00
|
|
|
return REFLECT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-12-07 11:02:39 -08:00
|
|
|
if (h->histogram_type() == Histogram::HISTOGRAM) {
|
2014-01-21 18:11:17 -08:00
|
|
|
if (!(JS_DefineProperty(cx, obj, "log_sum", ss.log_sum(), JSPROP_ENUMERATE)
|
|
|
|
&& JS_DefineProperty(cx, obj, "log_sum_squares", ss.log_sum_squares(), JSPROP_ENUMERATE))) {
|
2012-12-07 11:02:39 -08:00
|
|
|
return REFLECT_FAILURE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Export |sum_squares| as two separate 32-bit properties so that we
|
|
|
|
// can accurately reconstruct it on the analysis side.
|
|
|
|
uint64_t sum_squares = ss.sum_squares();
|
|
|
|
// Cast to avoid implicit truncation warnings.
|
|
|
|
uint32_t lo = static_cast<uint32_t>(sum_squares);
|
|
|
|
uint32_t hi = static_cast<uint32_t>(sum_squares >> 32);
|
2014-01-21 18:11:17 -08:00
|
|
|
if (!(JS_DefineProperty(cx, obj, "sum_squares_lo", lo, JSPROP_ENUMERATE)
|
|
|
|
&& JS_DefineProperty(cx, obj, "sum_squares_hi", hi, JSPROP_ENUMERATE))) {
|
2012-12-07 11:02:39 -08:00
|
|
|
return REFLECT_FAILURE;
|
|
|
|
}
|
2012-02-15 14:01:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
const size_t count = h->bucket_count();
|
2014-02-12 02:50:46 -08:00
|
|
|
JS::Rooted<JSObject*> rarray(cx, JS_NewArrayObject(cx, count));
|
2012-02-15 14:01:53 -08:00
|
|
|
if (!rarray) {
|
|
|
|
return REFLECT_FAILURE;
|
|
|
|
}
|
|
|
|
if (!(FillRanges(cx, rarray, h)
|
2014-01-21 18:11:17 -08:00
|
|
|
&& JS_DefineProperty(cx, obj, "ranges", rarray, JSPROP_ENUMERATE))) {
|
2012-02-15 14:01:53 -08:00
|
|
|
return REFLECT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-02-12 02:50:46 -08:00
|
|
|
JS::Rooted<JSObject*> counts_array(cx, JS_NewArrayObject(cx, count));
|
2012-02-15 14:01:53 -08:00
|
|
|
if (!counts_array) {
|
|
|
|
return REFLECT_FAILURE;
|
|
|
|
}
|
2014-01-21 18:11:17 -08:00
|
|
|
if (!JS_DefineProperty(cx, obj, "counts", counts_array, JSPROP_ENUMERATE)) {
|
2012-01-06 14:13:02 -08:00
|
|
|
return REFLECT_FAILURE;
|
2011-04-27 11:07:02 -07:00
|
|
|
}
|
2011-06-20 14:47:58 -07:00
|
|
|
for (size_t i = 0; i < count; i++) {
|
2012-02-15 14:01:53 -08:00
|
|
|
if (!JS_DefineElement(cx, counts_array, i, INT_TO_JSVAL(ss.counts(i)),
|
2013-10-10 13:38:05 -07:00
|
|
|
nullptr, nullptr, JSPROP_ENUMERATE)) {
|
2012-01-06 14:13:02 -08:00
|
|
|
return REFLECT_FAILURE;
|
2011-04-27 11:07:02 -07:00
|
|
|
}
|
|
|
|
}
|
2013-05-02 19:02:37 -07:00
|
|
|
|
2012-01-06 14:13:02 -08:00
|
|
|
return REFLECT_OK;
|
2011-04-27 11:07:02 -07:00
|
|
|
}
|
|
|
|
|
2011-12-13 09:03:30 -08:00
|
|
|
enum reflectStatus
|
2013-05-02 19:02:37 -07:00
|
|
|
ReflectHistogramSnapshot(JSContext *cx, JS::Handle<JSObject*> obj, Histogram *h)
|
2011-12-13 09:03:30 -08:00
|
|
|
{
|
|
|
|
Histogram::SampleSet ss;
|
|
|
|
h->SnapshotSample(&ss);
|
|
|
|
return ReflectHistogramAndSamples(cx, obj, h, ss);
|
|
|
|
}
|
|
|
|
|
2012-05-08 07:58:20 -07:00
|
|
|
bool
|
|
|
|
IsEmpty(const Histogram *h)
|
|
|
|
{
|
|
|
|
Histogram::SampleSet ss;
|
|
|
|
h->SnapshotSample(&ss);
|
|
|
|
|
|
|
|
return ss.counts(0) == 0 && ss.sum() == 0;
|
|
|
|
}
|
|
|
|
|
2013-08-02 00:41:57 -07:00
|
|
|
bool
|
2013-03-06 13:16:46 -08:00
|
|
|
JSHistogram_Add(JSContext *cx, unsigned argc, JS::Value *vp)
|
2011-04-27 11:07:02 -07:00
|
|
|
{
|
2013-08-15 14:41:51 -07:00
|
|
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
|
|
|
if (!args.length()) {
|
2011-06-28 16:54:33 -07:00
|
|
|
JS_ReportError(cx, "Expected one argument");
|
2013-08-02 00:41:57 -07:00
|
|
|
return false;
|
2011-06-28 16:54:33 -07:00
|
|
|
}
|
|
|
|
|
2013-08-15 14:41:51 -07:00
|
|
|
if (!(args[0].isNumber() || args[0].isBoolean())) {
|
2011-06-28 16:54:33 -07:00
|
|
|
JS_ReportError(cx, "Not a number");
|
2013-08-02 00:41:57 -07:00
|
|
|
return false;
|
2011-06-28 16:54:33 -07:00
|
|
|
}
|
|
|
|
|
2012-06-06 00:22:24 -07:00
|
|
|
int32_t value;
|
2013-08-15 14:41:51 -07:00
|
|
|
if (!JS::ToInt32(cx, args[0], &value)) {
|
2013-08-02 00:41:57 -07:00
|
|
|
return false;
|
2011-06-28 16:54:33 -07:00
|
|
|
}
|
|
|
|
|
2011-06-28 16:57:44 -07:00
|
|
|
if (TelemetryImpl::CanRecord()) {
|
|
|
|
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
2011-12-01 13:30:28 -08:00
|
|
|
if (!obj) {
|
2013-08-02 00:41:57 -07:00
|
|
|
return false;
|
2011-12-01 13:30:28 -08:00
|
|
|
}
|
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
Histogram *h = static_cast<Histogram*>(JS_GetPrivate(obj));
|
2013-02-22 09:38:43 -08:00
|
|
|
h->Add(value);
|
2011-06-28 16:57:44 -07:00
|
|
|
}
|
2013-08-02 00:41:57 -07:00
|
|
|
return true;
|
|
|
|
|
2011-04-27 11:07:02 -07:00
|
|
|
}
|
|
|
|
|
2013-08-02 00:41:57 -07:00
|
|
|
bool
|
2013-03-06 13:16:46 -08:00
|
|
|
JSHistogram_Snapshot(JSContext *cx, unsigned argc, JS::Value *vp)
|
2011-04-27 11:07:02 -07:00
|
|
|
{
|
2014-03-25 11:42:33 -07:00
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
2011-04-27 11:07:02 -07:00
|
|
|
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
2011-12-01 13:30:28 -08:00
|
|
|
if (!obj) {
|
2013-08-02 00:41:57 -07:00
|
|
|
return false;
|
2011-12-01 13:30:28 -08:00
|
|
|
}
|
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
Histogram *h = static_cast<Histogram*>(JS_GetPrivate(obj));
|
2014-01-16 09:48:58 -08:00
|
|
|
JS::Rooted<JSObject*> snapshot(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
|
2011-04-27 11:07:02 -07:00
|
|
|
if (!snapshot)
|
2013-08-02 00:41:57 -07:00
|
|
|
return false;
|
2012-01-06 14:13:02 -08:00
|
|
|
|
|
|
|
switch (ReflectHistogramSnapshot(cx, snapshot, h)) {
|
|
|
|
case REFLECT_FAILURE:
|
2013-08-02 00:41:57 -07:00
|
|
|
return false;
|
2012-01-06 14:13:02 -08:00
|
|
|
case REFLECT_CORRUPT:
|
|
|
|
JS_ReportError(cx, "Histogram is corrupt");
|
2013-08-02 00:41:57 -07:00
|
|
|
return false;
|
2012-01-06 14:13:02 -08:00
|
|
|
case REFLECT_OK:
|
2014-03-25 11:42:33 -07:00
|
|
|
args.rval().setObject(*snapshot);
|
2013-08-02 00:41:57 -07:00
|
|
|
return true;
|
2012-01-06 14:13:02 -08:00
|
|
|
default:
|
2013-06-28 18:38:30 -07:00
|
|
|
MOZ_CRASH("unhandled reflection status");
|
2012-01-06 14:13:02 -08:00
|
|
|
}
|
2011-04-27 11:07:02 -07:00
|
|
|
}
|
|
|
|
|
2013-08-02 00:41:57 -07:00
|
|
|
bool
|
2013-03-06 13:16:46 -08:00
|
|
|
JSHistogram_Clear(JSContext *cx, unsigned argc, JS::Value *vp)
|
2012-05-08 12:39:24 -07:00
|
|
|
{
|
|
|
|
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
|
|
|
if (!obj) {
|
2013-08-02 00:41:57 -07:00
|
|
|
return false;
|
2012-05-08 12:39:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Histogram *h = static_cast<Histogram*>(JS_GetPrivate(obj));
|
|
|
|
h->Clear();
|
2013-08-02 00:41:57 -07:00
|
|
|
return true;
|
2012-05-08 12:39:24 -07:00
|
|
|
}
|
|
|
|
|
2013-08-02 00:41:57 -07:00
|
|
|
nsresult
|
2014-01-09 09:39:36 -08:00
|
|
|
WrapAndReturnHistogram(Histogram *h, JSContext *cx, JS::MutableHandle<JS::Value> ret)
|
2011-04-27 11:07:02 -07:00
|
|
|
{
|
2013-09-11 05:49:05 -07:00
|
|
|
static const JSClass JSHistogram_class = {
|
2011-04-27 11:07:02 -07:00
|
|
|
"JSHistogram", /* name */
|
|
|
|
JSCLASS_HAS_PRIVATE, /* flags */
|
2013-04-05 21:22:55 -07:00
|
|
|
JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
|
2012-03-19 07:27:58 -07:00
|
|
|
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub
|
2011-04-27 11:07:02 -07:00
|
|
|
};
|
|
|
|
|
2014-01-16 09:48:58 -08:00
|
|
|
JS::Rooted<JSObject*> obj(cx, JS_NewObject(cx, &JSHistogram_class, JS::NullPtr(), JS::NullPtr()));
|
2011-04-27 11:07:02 -07:00
|
|
|
if (!obj)
|
|
|
|
return NS_ERROR_FAILURE;
|
2012-05-08 12:39:24 -07:00
|
|
|
if (!(JS_DefineFunction(cx, obj, "add", JSHistogram_Add, 1, 0)
|
|
|
|
&& JS_DefineFunction(cx, obj, "snapshot", JSHistogram_Snapshot, 0, 0)
|
|
|
|
&& JS_DefineFunction(cx, obj, "clear", JSHistogram_Clear, 0, 0))) {
|
2012-02-15 14:01:53 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2012-02-05 12:07:23 -08:00
|
|
|
JS_SetPrivate(obj, h);
|
2014-01-09 09:39:36 -08:00
|
|
|
ret.setObject(*obj);
|
2012-02-15 14:01:53 -08:00
|
|
|
return NS_OK;
|
2011-04-27 11:07:02 -07:00
|
|
|
}
|
2011-06-20 14:47:58 -07:00
|
|
|
|
2012-12-13 20:13:03 -08:00
|
|
|
static uint32_t
|
|
|
|
ReadLastShutdownDuration(const char *filename) {
|
|
|
|
FILE *f = fopen(filename, "r");
|
|
|
|
if (!f) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int shutdownTime;
|
|
|
|
int r = fscanf(f, "%d\n", &shutdownTime);
|
|
|
|
fclose(f);
|
|
|
|
if (r != 1) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return shutdownTime;
|
|
|
|
}
|
|
|
|
|
2013-01-31 13:11:38 -08:00
|
|
|
const int32_t kMaxFailedProfileLockFileSize = 10;
|
|
|
|
|
|
|
|
bool
|
|
|
|
GetFailedLockCount(nsIInputStream* inStream, uint32_t aCount,
|
|
|
|
unsigned int& result)
|
|
|
|
{
|
|
|
|
nsAutoCString bufStr;
|
|
|
|
nsresult rv;
|
|
|
|
rv = NS_ReadInputStreamToString(inStream, bufStr, aCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
result = bufStr.ToInteger(&rv);
|
|
|
|
return NS_SUCCEEDED(rv) && result > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-05-10 08:37:13 -07:00
|
|
|
GetFailedProfileLockFile(nsIFile* *aFile, nsIFile* aProfileDir)
|
2013-01-31 13:11:38 -08:00
|
|
|
{
|
2013-05-10 08:37:13 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aProfileDir);
|
|
|
|
|
|
|
|
nsresult rv = aProfileDir->Clone(aFile);
|
2013-01-31 13:11:38 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
(*aFile)->AppendNative(NS_LITERAL_CSTRING("Telemetry.FailedProfileLocks.txt"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-19 07:29:08 -08:00
|
|
|
class nsFetchTelemetryData : public nsRunnable
|
2012-12-13 20:13:03 -08:00
|
|
|
{
|
|
|
|
public:
|
2013-01-31 13:11:38 -08:00
|
|
|
nsFetchTelemetryData(const char* aShutdownTimeFilename,
|
2013-05-10 08:37:13 -07:00
|
|
|
nsIFile* aFailedProfileLockFile,
|
|
|
|
nsIFile* aProfileDir)
|
2013-01-31 13:11:38 -08:00
|
|
|
: mShutdownTimeFilename(aShutdownTimeFilename),
|
|
|
|
mFailedProfileLockFile(aFailedProfileLockFile),
|
2013-05-10 08:37:13 -07:00
|
|
|
mTelemetry(TelemetryImpl::sTelemetry),
|
|
|
|
mProfileDir(aProfileDir)
|
2013-01-31 13:11:38 -08:00
|
|
|
{
|
2012-12-13 20:13:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-01-31 13:11:38 -08:00
|
|
|
const char* mShutdownTimeFilename;
|
|
|
|
nsCOMPtr<nsIFile> mFailedProfileLockFile;
|
2013-11-06 21:35:30 -08:00
|
|
|
nsRefPtr<TelemetryImpl> mTelemetry;
|
2013-05-10 08:37:13 -07:00
|
|
|
nsCOMPtr<nsIFile> mProfileDir;
|
2012-12-13 20:13:03 -08:00
|
|
|
|
|
|
|
public:
|
|
|
|
void MainThread() {
|
2012-12-19 07:29:08 -08:00
|
|
|
mTelemetry->mCachedTelemetryData = true;
|
2013-01-07 11:45:25 -08:00
|
|
|
for (unsigned int i = 0, n = mTelemetry->mCallbacks.Count(); i < n; ++i) {
|
2012-12-13 20:13:03 -08:00
|
|
|
mTelemetry->mCallbacks[i]->Complete();
|
|
|
|
}
|
2013-01-07 11:45:25 -08:00
|
|
|
mTelemetry->mCallbacks.Clear();
|
2012-12-13 20:13:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
2013-01-31 13:11:38 -08:00
|
|
|
LoadFailedLockCount(mTelemetry->mFailedLockCount);
|
|
|
|
mTelemetry->mLastShutdownTime =
|
|
|
|
ReadLastShutdownDuration(mShutdownTimeFilename);
|
2013-05-10 08:37:13 -07:00
|
|
|
mTelemetry->ReadLateWritesStacks(mProfileDir);
|
2012-12-13 20:13:03 -08:00
|
|
|
nsCOMPtr<nsIRunnable> e =
|
2012-12-19 07:29:08 -08:00
|
|
|
NS_NewRunnableMethod(this, &nsFetchTelemetryData::MainThread);
|
2012-12-13 20:13:03 -08:00
|
|
|
NS_ENSURE_STATE(e);
|
|
|
|
NS_DispatchToMainThread(e, NS_DISPATCH_NORMAL);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-01-31 13:11:38 -08:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsresult
|
|
|
|
LoadFailedLockCount(uint32_t& failedLockCount)
|
|
|
|
{
|
|
|
|
failedLockCount = 0;
|
|
|
|
int64_t fileSize = 0;
|
|
|
|
nsresult rv = mFailedProfileLockFile->GetFileSize(&fileSize);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
NS_ENSURE_TRUE(fileSize <= kMaxFailedProfileLockFileSize,
|
|
|
|
NS_ERROR_UNEXPECTED);
|
|
|
|
nsCOMPtr<nsIInputStream> inStream;
|
|
|
|
rv = NS_NewLocalFileInputStream(getter_AddRefs(inStream),
|
|
|
|
mFailedProfileLockFile,
|
|
|
|
PR_RDONLY);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(GetFailedLockCount(inStream, fileSize, failedLockCount),
|
|
|
|
NS_ERROR_UNEXPECTED);
|
|
|
|
inStream->Close();
|
|
|
|
|
|
|
|
mFailedProfileLockFile->Remove(false);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-12-13 20:13:03 -08:00
|
|
|
};
|
|
|
|
|
2012-12-13 09:06:27 -08:00
|
|
|
static TimeStamp gRecordedShutdownStartTime;
|
|
|
|
static bool gAlreadyFreedShutdownTimeFileName = false;
|
|
|
|
static char *gRecordedShutdownTimeFileName = nullptr;
|
|
|
|
|
|
|
|
static char *
|
|
|
|
GetShutdownTimeFileName()
|
|
|
|
{
|
|
|
|
if (gAlreadyFreedShutdownTimeFileName) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gRecordedShutdownTimeFileName) {
|
|
|
|
nsCOMPtr<nsIFile> mozFile;
|
|
|
|
NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(mozFile));
|
|
|
|
if (!mozFile)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
mozFile->AppendNative(NS_LITERAL_CSTRING("Telemetry.ShutdownTime.txt"));
|
|
|
|
nsAutoCString nativePath;
|
|
|
|
nsresult rv = mozFile->GetNativePath(nativePath);
|
|
|
|
if (!NS_SUCCEEDED(rv))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
gRecordedShutdownTimeFileName = PL_strdup(nativePath.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return gRecordedShutdownTimeFileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TelemetryImpl::GetLastShutdownDuration(uint32_t *aResult)
|
|
|
|
{
|
2012-12-19 07:29:08 -08:00
|
|
|
// The user must call AsyncFetchTelemetryData first. We return zero instead of
|
2012-12-13 20:13:03 -08:00
|
|
|
// reporting a failure so that the rest of telemetry can uniformly handle
|
|
|
|
// the read not being available yet.
|
2012-12-19 07:29:08 -08:00
|
|
|
if (!mCachedTelemetryData) {
|
2012-12-13 09:06:27 -08:00
|
|
|
*aResult = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-13 20:13:03 -08:00
|
|
|
*aResult = mLastShutdownTime;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-12-13 09:06:27 -08:00
|
|
|
|
2013-01-31 13:11:38 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
TelemetryImpl::GetFailedProfileLockCount(uint32_t* aResult)
|
|
|
|
{
|
|
|
|
// The user must call AsyncFetchTelemetryData first. We return zero instead of
|
|
|
|
// reporting a failure so that the rest of telemetry can uniformly handle
|
|
|
|
// the read not being available yet.
|
|
|
|
if (!mCachedTelemetryData) {
|
|
|
|
*aResult = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = mFailedLockCount;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-13 20:13:03 -08:00
|
|
|
NS_IMETHODIMP
|
2012-12-19 07:29:08 -08:00
|
|
|
TelemetryImpl::AsyncFetchTelemetryData(nsIFetchTelemetryDataCallback *aCallback)
|
2012-12-13 20:13:03 -08:00
|
|
|
{
|
|
|
|
// We have finished reading the data already, just call the callback.
|
2012-12-19 07:29:08 -08:00
|
|
|
if (mCachedTelemetryData) {
|
2012-12-13 20:13:03 -08:00
|
|
|
aCallback->Complete();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-12-13 09:06:27 -08:00
|
|
|
|
2012-12-13 20:13:03 -08:00
|
|
|
// We already have a read request running, just remember the callback.
|
2013-01-07 11:45:25 -08:00
|
|
|
if (mCallbacks.Count() != 0) {
|
|
|
|
mCallbacks.AppendObject(aCallback);
|
2012-12-13 20:13:03 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-12-13 09:06:27 -08:00
|
|
|
|
2012-12-13 20:13:03 -08:00
|
|
|
// We make this check so that GetShutdownTimeFileName() doesn't get
|
|
|
|
// called; calling that function without telemetry enabled violates
|
|
|
|
// assumptions that the write-the-shutdown-timestamp machinery makes.
|
|
|
|
if (!Telemetry::CanRecord()) {
|
2012-12-19 07:29:08 -08:00
|
|
|
mCachedTelemetryData = true;
|
2012-12-13 20:13:03 -08:00
|
|
|
aCallback->Complete();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-12-13 09:06:27 -08:00
|
|
|
|
2012-12-13 20:13:03 -08:00
|
|
|
// Send the read to a background thread provided by the stream transport
|
|
|
|
// service to avoid a read in the main thread.
|
|
|
|
nsCOMPtr<nsIEventTarget> targetThread =
|
|
|
|
do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
|
|
|
|
if (!targetThread) {
|
2012-12-19 07:29:08 -08:00
|
|
|
mCachedTelemetryData = true;
|
2012-12-13 20:13:03 -08:00
|
|
|
aCallback->Complete();
|
|
|
|
return NS_OK;
|
2012-12-13 09:06:27 -08:00
|
|
|
}
|
|
|
|
|
2012-12-13 20:13:03 -08:00
|
|
|
// We have to get the filename from the main thread.
|
2013-01-31 13:11:38 -08:00
|
|
|
const char *shutdownTimeFilename = GetShutdownTimeFileName();
|
|
|
|
if (!shutdownTimeFilename) {
|
|
|
|
mCachedTelemetryData = true;
|
|
|
|
aCallback->Complete();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-10 08:37:13 -07:00
|
|
|
nsCOMPtr<nsIFile> profileDir;
|
|
|
|
nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
|
|
|
|
getter_AddRefs(profileDir));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mCachedTelemetryData = true;
|
|
|
|
aCallback->Complete();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-31 13:11:38 -08:00
|
|
|
nsCOMPtr<nsIFile> failedProfileLockFile;
|
2013-05-10 08:37:13 -07:00
|
|
|
rv = GetFailedProfileLockFile(getter_AddRefs(failedProfileLockFile),
|
|
|
|
profileDir);
|
2013-01-31 13:11:38 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
2012-12-19 07:29:08 -08:00
|
|
|
mCachedTelemetryData = true;
|
2012-12-13 20:13:03 -08:00
|
|
|
aCallback->Complete();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-07 11:45:25 -08:00
|
|
|
mCallbacks.AppendObject(aCallback);
|
2013-05-10 08:37:13 -07:00
|
|
|
|
2013-01-31 13:11:38 -08:00
|
|
|
nsCOMPtr<nsIRunnable> event = new nsFetchTelemetryData(shutdownTimeFilename,
|
2013-05-10 08:37:13 -07:00
|
|
|
failedProfileLockFile,
|
|
|
|
profileDir);
|
2012-12-13 20:13:03 -08:00
|
|
|
|
|
|
|
targetThread->Dispatch(event, NS_DISPATCH_NORMAL);
|
2012-12-13 09:06:27 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-28 16:57:44 -07:00
|
|
|
TelemetryImpl::TelemetryImpl():
|
2012-02-13 11:47:40 -08:00
|
|
|
mHistogramMap(Telemetry::HistogramCount),
|
2011-12-06 12:12:55 -08:00
|
|
|
mCanRecord(XRE_GetProcessType() == GeckoProcessType_Default),
|
2012-03-12 04:07:05 -07:00
|
|
|
mHashMutex("Telemetry::mHashMutex"),
|
2012-12-13 09:06:27 -08:00
|
|
|
mHangReportsMutex("Telemetry::mHangReportsMutex"),
|
2013-11-22 11:17:31 -08:00
|
|
|
mThreadHangStatsMutex("Telemetry::mThreadHangStatsMutex"),
|
2012-12-19 07:29:08 -08:00
|
|
|
mCachedTelemetryData(false),
|
2013-01-31 13:11:38 -08:00
|
|
|
mLastShutdownTime(0),
|
|
|
|
mFailedLockCount(0)
|
2011-06-28 16:57:44 -07:00
|
|
|
{
|
2011-12-06 12:12:55 -08:00
|
|
|
// A whitelist to prevent Telemetry reporting on Addon & Thunderbird DBs
|
|
|
|
const char *trackedDBs[] = {
|
2013-01-13 18:56:39 -08:00
|
|
|
"addons.sqlite", "content-prefs.sqlite", "cookies.sqlite",
|
|
|
|
"downloads.sqlite", "extensions.sqlite", "formhistory.sqlite",
|
2014-01-13 17:57:46 -08:00
|
|
|
"index.sqlite", "healthreport.sqlite", "netpredictions.sqlite",
|
|
|
|
"permissions.sqlite", "places.sqlite", "search.sqlite", "signons.sqlite",
|
2013-12-17 16:07:18 -08:00
|
|
|
"urlclassifier3.sqlite", "webappsstore.sqlite"
|
2011-12-06 12:12:55 -08:00
|
|
|
};
|
|
|
|
|
2012-01-09 10:01:52 -08:00
|
|
|
for (size_t i = 0; i < ArrayLength(trackedDBs); i++)
|
2011-12-06 12:12:55 -08:00
|
|
|
mTrackedDBs.PutEntry(nsDependentCString(trackedDBs[i]));
|
|
|
|
|
2012-01-10 12:31:34 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Mark immutable to prevent asserts on simultaneous access from multiple threads
|
|
|
|
mTrackedDBs.MarkImmutable();
|
|
|
|
#endif
|
2011-06-20 14:48:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TelemetryImpl::~TelemetryImpl() {
|
2013-11-06 21:35:30 -08:00
|
|
|
UnregisterWeakMemoryReporter(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TelemetryImpl::InitMemoryReporter() {
|
|
|
|
RegisterWeakMemoryReporter(this);
|
2011-06-20 14:48:03 -07:00
|
|
|
}
|
|
|
|
|
2011-04-27 11:07:02 -07:00
|
|
|
NS_IMETHODIMP
|
2014-01-03 09:02:48 -08:00
|
|
|
TelemetryImpl::NewHistogram(const nsACString &name, const nsACString &expiration, uint32_t min,
|
|
|
|
uint32_t max, uint32_t bucketCount, uint32_t histogramType,
|
2014-01-09 09:39:36 -08:00
|
|
|
JSContext *cx, JS::MutableHandle<JS::Value> ret)
|
2011-04-27 11:07:02 -07:00
|
|
|
{
|
2011-05-19 19:33:05 -07:00
|
|
|
Histogram *h;
|
2014-01-03 09:02:48 -08:00
|
|
|
nsresult rv = HistogramGet(PromiseFlatCString(name).get(), PromiseFlatCString(expiration).get(),
|
|
|
|
min, max, bucketCount, histogramType, &h);
|
2011-06-20 14:47:58 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2011-06-30 14:58:00 -07:00
|
|
|
h->ClearFlags(Histogram::kUmaTargetedHistogramFlag);
|
2013-02-13 07:51:24 -08:00
|
|
|
h->SetFlags(Histogram::kExtendedStatisticsFlag);
|
2011-04-27 11:07:02 -07:00
|
|
|
return WrapAndReturnHistogram(h, cx, ret);
|
|
|
|
}
|
|
|
|
|
2012-02-13 11:47:40 -08:00
|
|
|
bool
|
2012-08-21 12:29:28 -07:00
|
|
|
TelemetryImpl::ReflectSQL(const SlowSQLEntryType *entry,
|
|
|
|
const Stat *stat,
|
|
|
|
JSContext *cx,
|
2013-05-02 19:02:37 -07:00
|
|
|
JS::Handle<JSObject*> obj)
|
2011-12-06 12:12:55 -08:00
|
|
|
{
|
2012-08-21 12:29:28 -07:00
|
|
|
if (stat->hitCount == 0)
|
|
|
|
return true;
|
|
|
|
|
2011-12-14 12:04:25 -08:00
|
|
|
const nsACString &sql = entry->GetKey();
|
2011-12-06 12:12:55 -08:00
|
|
|
|
2014-02-12 02:50:46 -08:00
|
|
|
JS::Rooted<JSObject*> arrayObj(cx, JS_NewArrayObject(cx, 0));
|
2012-02-15 14:01:53 -08:00
|
|
|
if (!arrayObj) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-25 01:31:17 -08:00
|
|
|
return (JS_SetElement(cx, arrayObj, 0, stat->hitCount)
|
|
|
|
&& JS_SetElement(cx, arrayObj, 1, stat->totalTime)
|
2014-01-21 18:11:17 -08:00
|
|
|
&& JS_DefineProperty(cx, obj, sql.BeginReading(), arrayObj,
|
|
|
|
JSPROP_ENUMERATE));
|
2011-12-06 12:12:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-08-21 12:29:28 -07:00
|
|
|
TelemetryImpl::ReflectMainThreadSQL(SlowSQLEntryType *entry, JSContext *cx,
|
2013-05-02 19:02:37 -07:00
|
|
|
JS::Handle<JSObject*> obj)
|
2012-03-21 10:26:48 -07:00
|
|
|
{
|
2012-08-21 12:29:28 -07:00
|
|
|
return ReflectSQL(entry, &entry->mData.mainThread, cx, obj);
|
2012-03-21 10:26:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-08-21 12:29:28 -07:00
|
|
|
TelemetryImpl::ReflectOtherThreadsSQL(SlowSQLEntryType *entry, JSContext *cx,
|
2013-05-02 19:02:37 -07:00
|
|
|
JS::Handle<JSObject*> obj)
|
2012-03-21 10:26:48 -07:00
|
|
|
{
|
2012-08-21 12:29:28 -07:00
|
|
|
return ReflectSQL(entry, &entry->mData.otherThreads, cx, obj);
|
2012-03-21 10:26:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-05-02 19:02:37 -07:00
|
|
|
TelemetryImpl::AddSQLInfo(JSContext *cx, JS::Handle<JSObject*> rootObj, bool mainThread,
|
2012-08-21 12:29:28 -07:00
|
|
|
bool privateSQL)
|
2011-12-06 12:12:55 -08:00
|
|
|
{
|
2014-01-16 09:48:58 -08:00
|
|
|
JS::Rooted<JSObject*> statsObj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
|
2011-12-14 12:04:25 -08:00
|
|
|
if (!statsObj)
|
2011-12-06 12:12:55 -08:00
|
|
|
return false;
|
|
|
|
|
2012-03-21 10:26:48 -07:00
|
|
|
AutoHashtable<SlowSQLEntryType> &sqlMap =
|
2012-08-21 12:29:28 -07:00
|
|
|
(privateSQL ? mPrivateSQL : mSanitizedSQL);
|
2012-03-21 10:26:48 -07:00
|
|
|
AutoHashtable<SlowSQLEntryType>::ReflectEntryFunc reflectFunction =
|
2012-08-21 12:29:28 -07:00
|
|
|
(mainThread ? ReflectMainThreadSQL : ReflectOtherThreadsSQL);
|
2013-12-09 15:30:06 -08:00
|
|
|
if (!sqlMap.ReflectIntoJS(reflectFunction, cx, statsObj)) {
|
2012-02-15 14:01:53 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return JS_DefineProperty(cx, rootObj,
|
|
|
|
mainThread ? "mainThread" : "otherThreads",
|
2014-01-21 18:11:17 -08:00
|
|
|
statsObj, JSPROP_ENUMERATE);
|
2011-12-06 12:12:55 -08:00
|
|
|
}
|
|
|
|
|
2012-01-06 11:39:29 -08:00
|
|
|
nsresult
|
2012-01-09 12:42:34 -08:00
|
|
|
TelemetryImpl::GetHistogramEnumId(const char *name, Telemetry::ID *id)
|
2012-01-06 11:39:29 -08:00
|
|
|
{
|
2012-01-09 12:42:34 -08:00
|
|
|
if (!sTelemetry) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-01-06 11:39:29 -08:00
|
|
|
// Cache names
|
|
|
|
// Note the histogram names are statically allocated
|
2012-01-09 12:42:34 -08:00
|
|
|
TelemetryImpl::HistogramMapType *map = &sTelemetry->mHistogramMap;
|
|
|
|
if (!map->Count()) {
|
2012-05-16 04:39:21 -07:00
|
|
|
for (uint32_t i = 0; i < Telemetry::HistogramCount; i++) {
|
2012-08-28 09:55:32 -07:00
|
|
|
CharPtrEntryType *entry = map->PutEntry(gHistograms[i].id());
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(!entry)) {
|
2012-01-09 12:42:34 -08:00
|
|
|
map->Clear();
|
2012-01-06 11:39:29 -08:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
entry->mData = (Telemetry::ID) i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-09 12:42:34 -08:00
|
|
|
CharPtrEntryType *entry = map->GetEntry(name);
|
|
|
|
if (!entry) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
*id = entry->mData;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
TelemetryImpl::GetHistogramByName(const nsACString &name, Histogram **ret)
|
|
|
|
{
|
|
|
|
Telemetry::ID id;
|
|
|
|
nsresult rv = GetHistogramEnumId(PromiseFlatCString(name).get(), &id);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2012-01-06 11:39:29 -08:00
|
|
|
|
2012-01-09 12:42:34 -08:00
|
|
|
rv = GetHistogramByEnumId(id, ret);
|
2012-01-06 11:39:29 -08:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-06 11:40:04 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
TelemetryImpl::HistogramFrom(const nsACString &name, const nsACString &existing_name,
|
2014-01-09 09:39:36 -08:00
|
|
|
JSContext *cx, JS::MutableHandle<JS::Value> ret)
|
2012-01-06 11:40:04 -08:00
|
|
|
{
|
2014-01-03 09:02:48 -08:00
|
|
|
Telemetry::ID id;
|
|
|
|
nsresult rv = GetHistogramEnumId(PromiseFlatCString(existing_name).get(), &id);
|
|
|
|
if (NS_FAILED(rv)) {
|
2014-01-03 06:28:07 -08:00
|
|
|
return rv;
|
2014-01-03 09:02:48 -08:00
|
|
|
}
|
|
|
|
const TelemetryHistogram &p = gHistograms[id];
|
2014-01-03 08:31:17 -08:00
|
|
|
|
2014-01-03 09:02:48 -08:00
|
|
|
Histogram *existing;
|
|
|
|
rv = GetHistogramByEnumId(id, &existing);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2012-01-06 11:40:04 -08:00
|
|
|
|
|
|
|
Histogram *clone;
|
2014-01-03 09:02:48 -08:00
|
|
|
rv = HistogramGet(PromiseFlatCString(name).get(), p.expiration(),
|
|
|
|
existing->declared_min(), existing->declared_max(),
|
|
|
|
existing->bucket_count(), p.histogramType, &clone);
|
2012-01-06 11:40:04 -08:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
Histogram::SampleSet ss;
|
|
|
|
existing->SnapshotSample(&ss);
|
|
|
|
clone->AddSampleSet(ss);
|
|
|
|
return WrapAndReturnHistogram(clone, cx, ret);
|
|
|
|
}
|
|
|
|
|
2012-01-06 14:13:02 -08:00
|
|
|
void
|
|
|
|
TelemetryImpl::IdentifyCorruptHistograms(StatisticsRecorder::Histograms &hs)
|
|
|
|
{
|
|
|
|
for (HistogramIterator it = hs.begin(); it != hs.end(); ++it) {
|
|
|
|
Histogram *h = *it;
|
|
|
|
|
|
|
|
Telemetry::ID id;
|
|
|
|
nsresult rv = GetHistogramEnumId(h->histogram_name().c_str(), &id);
|
|
|
|
// This histogram isn't a static histogram, just ignore it.
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gCorruptHistograms[id]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Histogram::SampleSet ss;
|
|
|
|
h->SnapshotSample(&ss);
|
|
|
|
Histogram::Inconsistencies check = h->FindCorruption(ss);
|
|
|
|
bool corrupt = (check != Histogram::NO_INCONSISTENCIES);
|
|
|
|
|
|
|
|
if (corrupt) {
|
|
|
|
Telemetry::ID corruptID = Telemetry::HistogramCount;
|
|
|
|
if (check & Histogram::RANGE_CHECKSUM_ERROR) {
|
|
|
|
corruptID = Telemetry::RANGE_CHECKSUM_ERRORS;
|
|
|
|
} else if (check & Histogram::BUCKET_ORDER_ERROR) {
|
|
|
|
corruptID = Telemetry::BUCKET_ORDER_ERRORS;
|
|
|
|
} else if (check & Histogram::COUNT_HIGH_ERROR) {
|
|
|
|
corruptID = Telemetry::TOTAL_COUNT_HIGH_ERRORS;
|
|
|
|
} else if (check & Histogram::COUNT_LOW_ERROR) {
|
|
|
|
corruptID = Telemetry::TOTAL_COUNT_LOW_ERRORS;
|
|
|
|
}
|
|
|
|
Telemetry::Accumulate(corruptID, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
gCorruptHistograms[id] = corrupt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TelemetryImpl::ShouldReflectHistogram(Histogram *h)
|
|
|
|
{
|
|
|
|
const char *name = h->histogram_name().c_str();
|
|
|
|
Telemetry::ID id;
|
|
|
|
nsresult rv = GetHistogramEnumId(name, &id);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// GetHistogramEnumId generally should not fail. But a lookup
|
|
|
|
// failure shouldn't prevent us from reflecting histograms into JS.
|
|
|
|
//
|
|
|
|
// However, these two histograms are created by Histogram itself for
|
|
|
|
// tracking corruption. We have our own histograms for that, so
|
|
|
|
// ignore these two.
|
|
|
|
if (strcmp(name, "Histogram.InconsistentCountHigh") == 0
|
|
|
|
|| strcmp(name, "Histogram.InconsistentCountLow") == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return !gCorruptHistograms[id];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-20 13:56:48 -08:00
|
|
|
// Compute the name to pass into Histogram for the addon histogram
|
|
|
|
// 'name' from the addon 'id'. We can't use 'name' directly because it
|
|
|
|
// might conflict with other histograms in other addons or even with our
|
|
|
|
// own.
|
|
|
|
void
|
|
|
|
AddonHistogramName(const nsACString &id, const nsACString &name,
|
|
|
|
nsACString &ret)
|
|
|
|
{
|
|
|
|
ret.Append(id);
|
|
|
|
ret.Append(NS_LITERAL_CSTRING(":"));
|
|
|
|
ret.Append(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TelemetryImpl::RegisterAddonHistogram(const nsACString &id,
|
|
|
|
const nsACString &name,
|
2012-05-16 04:39:21 -07:00
|
|
|
uint32_t min, uint32_t max,
|
|
|
|
uint32_t bucketCount,
|
|
|
|
uint32_t histogramType)
|
2012-01-20 13:56:48 -08:00
|
|
|
{
|
|
|
|
AddonEntryType *addonEntry = mAddonMap.GetEntry(id);
|
|
|
|
if (!addonEntry) {
|
|
|
|
addonEntry = mAddonMap.PutEntry(id);
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(!addonEntry)) {
|
2012-01-20 13:56:48 -08:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
addonEntry->mData = new AddonHistogramMapType();
|
|
|
|
}
|
|
|
|
|
|
|
|
AddonHistogramMapType *histogramMap = addonEntry->mData;
|
|
|
|
AddonHistogramEntryType *histogramEntry = histogramMap->GetEntry(name);
|
|
|
|
// Can't re-register the same histogram.
|
|
|
|
if (histogramEntry) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
histogramEntry = histogramMap->PutEntry(name);
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(!histogramEntry)) {
|
2012-01-20 13:56:48 -08:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddonHistogramInfo &info = histogramEntry->mData;
|
|
|
|
info.min = min;
|
|
|
|
info.max = max;
|
|
|
|
info.bucketCount = bucketCount;
|
|
|
|
info.histogramType = histogramType;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TelemetryImpl::GetAddonHistogram(const nsACString &id, const nsACString &name,
|
2014-01-09 09:39:36 -08:00
|
|
|
JSContext *cx, JS::MutableHandle<JS::Value> ret)
|
2012-01-20 13:56:48 -08:00
|
|
|
{
|
|
|
|
AddonEntryType *addonEntry = mAddonMap.GetEntry(id);
|
|
|
|
// The given id has not been registered.
|
|
|
|
if (!addonEntry) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddonHistogramMapType *histogramMap = addonEntry->mData;
|
|
|
|
AddonHistogramEntryType *histogramEntry = histogramMap->GetEntry(name);
|
|
|
|
// The given histogram name has not been registered.
|
|
|
|
if (!histogramEntry) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddonHistogramInfo &info = histogramEntry->mData;
|
2012-03-02 06:59:38 -08:00
|
|
|
if (!info.h) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString actualName;
|
2012-01-20 13:56:48 -08:00
|
|
|
AddonHistogramName(id, name, actualName);
|
2012-03-02 06:59:38 -08:00
|
|
|
if (!CreateHistogramForAddon(actualName, info)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2012-01-20 13:56:48 -08:00
|
|
|
}
|
|
|
|
}
|
2012-03-02 06:59:38 -08:00
|
|
|
return WrapAndReturnHistogram(info.h, cx, ret);
|
2012-01-20 13:56:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TelemetryImpl::UnregisterAddonHistograms(const nsACString &id)
|
|
|
|
{
|
|
|
|
AddonEntryType *addonEntry = mAddonMap.GetEntry(id);
|
|
|
|
if (addonEntry) {
|
|
|
|
// Histogram's destructor is private, so this is the best we can do.
|
|
|
|
// The histograms the addon created *will* stick around, but they
|
|
|
|
// will be deleted if and when the addon registers histograms with
|
|
|
|
// the same names.
|
|
|
|
delete addonEntry->mData;
|
|
|
|
mAddonMap.RemoveEntry(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:07:02 -07:00
|
|
|
NS_IMETHODIMP
|
2014-01-09 09:39:36 -08:00
|
|
|
TelemetryImpl::GetHistogramSnapshots(JSContext *cx, JS::MutableHandle<JS::Value> ret)
|
2011-04-27 11:07:02 -07:00
|
|
|
{
|
2014-01-16 09:48:58 -08:00
|
|
|
JS::Rooted<JSObject*> root_obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
|
2011-04-27 11:07:02 -07:00
|
|
|
if (!root_obj)
|
|
|
|
return NS_ERROR_FAILURE;
|
2014-01-09 09:39:36 -08:00
|
|
|
ret.setObject(*root_obj);
|
2011-04-27 11:07:02 -07:00
|
|
|
|
2012-03-02 06:59:38 -08:00
|
|
|
// Ensure that all the HISTOGRAM_FLAG histograms have been created, so
|
|
|
|
// that their values are snapshotted.
|
|
|
|
for (size_t i = 0; i < Telemetry::HistogramCount; ++i) {
|
|
|
|
if (gHistograms[i].histogramType == nsITelemetry::HISTOGRAM_FLAG) {
|
|
|
|
Histogram *h;
|
|
|
|
DebugOnly<nsresult> rv = GetHistogramByEnumId(Telemetry::ID(i), &h);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-06 14:13:02 -08:00
|
|
|
StatisticsRecorder::Histograms hs;
|
|
|
|
StatisticsRecorder::GetHistograms(&hs);
|
|
|
|
|
|
|
|
// We identify corrupt histograms first, rather than interspersing it
|
|
|
|
// in the loop below, to ensure that our corruption statistics don't
|
|
|
|
// depend on histogram enumeration order.
|
|
|
|
//
|
|
|
|
// Of course, we hope that all of these corruption-statistics
|
|
|
|
// histograms are not themselves corrupt...
|
|
|
|
IdentifyCorruptHistograms(hs);
|
|
|
|
|
|
|
|
// OK, now we can actually reflect things.
|
2013-05-02 12:51:41 -07:00
|
|
|
JS::Rooted<JSObject*> hobj(cx);
|
2012-01-06 14:13:02 -08:00
|
|
|
for (HistogramIterator it = hs.begin(); it != hs.end(); ++it) {
|
2011-04-27 11:07:02 -07:00
|
|
|
Histogram *h = *it;
|
2014-01-03 09:02:48 -08:00
|
|
|
if (!ShouldReflectHistogram(h) || IsEmpty(h) || IsExpired(h)) {
|
2012-01-06 14:13:02 -08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-01-16 09:48:58 -08:00
|
|
|
hobj = JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr());
|
2012-01-06 14:13:02 -08:00
|
|
|
if (!hobj) {
|
2011-04-27 11:07:02 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2012-01-06 14:13:02 -08:00
|
|
|
switch (ReflectHistogramSnapshot(cx, hobj, h)) {
|
|
|
|
case REFLECT_CORRUPT:
|
|
|
|
// We can still hit this case even if ShouldReflectHistograms
|
|
|
|
// returns true. The histogram lies outside of our control
|
|
|
|
// somehow; just skip it.
|
|
|
|
continue;
|
|
|
|
case REFLECT_FAILURE:
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
case REFLECT_OK:
|
2014-01-21 18:11:17 -08:00
|
|
|
if (!JS_DefineProperty(cx, root_obj, h->histogram_name().c_str(), hobj,
|
|
|
|
JSPROP_ENUMERATE)) {
|
2012-01-06 14:13:02 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
2011-04-27 11:07:02 -07:00
|
|
|
}
|
2011-12-14 12:04:25 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-02 06:59:38 -08:00
|
|
|
bool
|
|
|
|
TelemetryImpl::CreateHistogramForAddon(const nsACString &name,
|
|
|
|
AddonHistogramInfo &info)
|
|
|
|
{
|
|
|
|
Histogram *h;
|
2014-01-03 09:02:48 -08:00
|
|
|
nsresult rv = HistogramGet(PromiseFlatCString(name).get(), "never",
|
2012-03-02 06:59:38 -08:00
|
|
|
info.min, info.max, info.bucketCount,
|
|
|
|
info.histogramType, &h);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Don't let this histogram be reported via the normal means
|
|
|
|
// (e.g. Telemetry.registeredHistograms); we'll make it available in
|
|
|
|
// other ways.
|
|
|
|
h->ClearFlags(Histogram::kUmaTargetedHistogramFlag);
|
|
|
|
info.h = h;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-20 13:56:48 -08:00
|
|
|
bool
|
|
|
|
TelemetryImpl::AddonHistogramReflector(AddonHistogramEntryType *entry,
|
2013-05-02 19:02:37 -07:00
|
|
|
JSContext *cx, JS::Handle<JSObject*> obj)
|
2012-01-20 13:56:48 -08:00
|
|
|
{
|
2012-03-02 06:59:38 -08:00
|
|
|
AddonHistogramInfo &info = entry->mData;
|
|
|
|
|
2012-01-20 13:56:48 -08:00
|
|
|
// Never even accessed the histogram.
|
2012-03-02 06:59:38 -08:00
|
|
|
if (!info.h) {
|
|
|
|
// Have to force creation of HISTOGRAM_FLAG histograms.
|
|
|
|
if (info.histogramType != nsITelemetry::HISTOGRAM_FLAG)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!CreateHistogramForAddon(entry->GetKey(), info)) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-01-20 13:56:48 -08:00
|
|
|
}
|
|
|
|
|
2012-05-08 07:58:20 -07:00
|
|
|
if (IsEmpty(info.h)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-16 09:48:58 -08:00
|
|
|
JS::Rooted<JSObject*> snapshot(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
|
2012-02-15 14:01:53 -08:00
|
|
|
if (!snapshot) {
|
|
|
|
// Just consider this to be skippable.
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-02 06:59:38 -08:00
|
|
|
switch (ReflectHistogramSnapshot(cx, snapshot, info.h)) {
|
2012-01-20 13:56:48 -08:00
|
|
|
case REFLECT_FAILURE:
|
|
|
|
case REFLECT_CORRUPT:
|
|
|
|
return false;
|
|
|
|
case REFLECT_OK:
|
|
|
|
const nsACString &histogramName = entry->GetKey();
|
2014-01-21 18:11:17 -08:00
|
|
|
if (!JS_DefineProperty(cx, obj, PromiseFlatCString(histogramName).get(),
|
|
|
|
snapshot, JSPROP_ENUMERATE)) {
|
2012-01-20 13:56:48 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TelemetryImpl::AddonReflector(AddonEntryType *entry,
|
2013-05-02 19:02:37 -07:00
|
|
|
JSContext *cx, JS::Handle<JSObject*> obj)
|
2012-01-20 13:56:48 -08:00
|
|
|
{
|
|
|
|
const nsACString &addonId = entry->GetKey();
|
2014-01-16 09:48:58 -08:00
|
|
|
JS::Rooted<JSObject*> subobj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
|
2012-01-20 13:56:48 -08:00
|
|
|
if (!subobj) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddonHistogramMapType *map = entry->mData;
|
2012-06-18 13:20:52 -07:00
|
|
|
if (!(map->ReflectIntoJS(AddonHistogramReflector, cx, subobj)
|
2014-01-21 18:11:17 -08:00
|
|
|
&& JS_DefineProperty(cx, obj, PromiseFlatCString(addonId).get(),
|
|
|
|
subobj, JSPROP_ENUMERATE))) {
|
2012-01-20 13:56:48 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-09 09:39:36 -08:00
|
|
|
TelemetryImpl::GetAddonHistogramSnapshots(JSContext *cx, JS::MutableHandle<JS::Value> ret)
|
2012-01-20 13:56:48 -08:00
|
|
|
{
|
2014-01-16 09:48:58 -08:00
|
|
|
JS::Rooted<JSObject*> obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
|
2012-01-20 13:56:48 -08:00
|
|
|
if (!obj) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-06-18 13:20:52 -07:00
|
|
|
if (!mAddonMap.ReflectIntoJS(AddonReflector, cx, obj)) {
|
2012-01-20 13:56:48 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2014-01-09 09:39:36 -08:00
|
|
|
ret.setObject(*obj);
|
2012-01-20 13:56:48 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-21 10:26:48 -07:00
|
|
|
bool
|
2014-01-09 09:39:36 -08:00
|
|
|
TelemetryImpl::GetSQLStats(JSContext *cx, JS::MutableHandle<JS::Value> ret, bool includePrivateSql)
|
2011-12-14 12:04:25 -08:00
|
|
|
{
|
2014-01-16 09:48:58 -08:00
|
|
|
JS::Rooted<JSObject*> root_obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
|
2011-12-14 12:04:25 -08:00
|
|
|
if (!root_obj)
|
2012-03-21 10:26:48 -07:00
|
|
|
return false;
|
2014-01-09 09:39:36 -08:00
|
|
|
ret.setObject(*root_obj);
|
2011-12-06 12:12:55 -08:00
|
|
|
|
|
|
|
MutexAutoLock hashMutex(mHashMutex);
|
|
|
|
// Add info about slow SQL queries on the main thread
|
2012-03-21 10:26:48 -07:00
|
|
|
if (!AddSQLInfo(cx, root_obj, true, includePrivateSql))
|
|
|
|
return false;
|
2011-12-06 12:12:55 -08:00
|
|
|
// Add info about slow SQL queries on other threads
|
2012-03-21 10:26:48 -07:00
|
|
|
if (!AddSQLInfo(cx, root_obj, false, includePrivateSql))
|
|
|
|
return false;
|
2013-05-01 15:43:53 -07:00
|
|
|
|
2012-03-21 10:26:48 -07:00
|
|
|
return true;
|
|
|
|
}
|
2011-12-06 12:12:55 -08:00
|
|
|
|
2012-03-21 10:26:48 -07:00
|
|
|
NS_IMETHODIMP
|
2014-01-09 09:39:36 -08:00
|
|
|
TelemetryImpl::GetSlowSQL(JSContext *cx, JS::MutableHandle<JS::Value> ret)
|
2012-03-21 10:26:48 -07:00
|
|
|
{
|
|
|
|
if (GetSQLStats(cx, ret, false))
|
|
|
|
return NS_OK;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-09 09:39:36 -08:00
|
|
|
TelemetryImpl::GetDebugSlowSQL(JSContext *cx, JS::MutableHandle<JS::Value> ret)
|
2012-03-21 10:26:48 -07:00
|
|
|
{
|
|
|
|
bool revealPrivateSql =
|
|
|
|
Preferences::GetBool("toolkit.telemetry.debugSlowSql", false);
|
|
|
|
if (GetSQLStats(cx, ret, revealPrivateSql))
|
|
|
|
return NS_OK;
|
|
|
|
return NS_ERROR_FAILURE;
|
2011-04-27 11:07:02 -07:00
|
|
|
}
|
|
|
|
|
2013-04-19 04:54:18 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
TelemetryImpl::GetMaximalNumberOfConcurrentThreads(uint32_t *ret)
|
|
|
|
{
|
|
|
|
*ret = nsThreadManager::get()->GetHighestNumberOfThreads();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-12 04:07:05 -07:00
|
|
|
NS_IMETHODIMP
|
2014-01-09 09:39:36 -08:00
|
|
|
TelemetryImpl::GetChromeHangs(JSContext *cx, JS::MutableHandle<JS::Value> ret)
|
2012-03-12 04:07:05 -07:00
|
|
|
{
|
|
|
|
MutexAutoLock hangReportMutex(mHangReportsMutex);
|
2012-11-20 06:45:14 -08:00
|
|
|
|
2012-11-27 05:52:25 -08:00
|
|
|
const CombinedStacks& stacks = mHangReports.GetStacks();
|
2013-05-01 15:43:53 -07:00
|
|
|
JS::Rooted<JSObject*> fullReportObj(cx, CreateJSStackObject(cx, stacks));
|
2012-11-20 06:45:14 -08:00
|
|
|
if (!fullReportObj) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-01-09 09:39:36 -08:00
|
|
|
ret.setObject(*fullReportObj);
|
2012-11-20 06:45:14 -08:00
|
|
|
|
2014-02-12 02:50:46 -08:00
|
|
|
JS::Rooted<JSObject*> durationArray(cx, JS_NewArrayObject(cx, 0));
|
|
|
|
JS::Rooted<JSObject*> systemUptimeArray(cx, JS_NewArrayObject(cx, 0));
|
|
|
|
JS::Rooted<JSObject*> firefoxUptimeArray(cx, JS_NewArrayObject(cx, 0));
|
2014-01-27 13:47:00 -08:00
|
|
|
if (!durationArray || !systemUptimeArray || !firefoxUptimeArray) {
|
2012-11-27 05:52:25 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2014-01-27 13:47:00 -08:00
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
bool ok = JS_DefineProperty(cx, fullReportObj, "durations",
|
2014-01-21 18:11:17 -08:00
|
|
|
durationArray, JSPROP_ENUMERATE);
|
2012-11-27 05:52:25 -08:00
|
|
|
if (!ok) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-01-27 13:47:00 -08:00
|
|
|
ok = JS_DefineProperty(cx, fullReportObj, "systemUptime",
|
2014-01-21 18:11:17 -08:00
|
|
|
systemUptimeArray, JSPROP_ENUMERATE);
|
2014-01-27 13:47:00 -08:00
|
|
|
if (!ok) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ok = JS_DefineProperty(cx, fullReportObj, "firefoxUptime",
|
2014-01-21 18:11:17 -08:00
|
|
|
firefoxUptimeArray, JSPROP_ENUMERATE);
|
2014-01-27 13:47:00 -08:00
|
|
|
if (!ok) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-11-27 05:52:25 -08:00
|
|
|
const size_t length = stacks.GetStackCount();
|
|
|
|
for (size_t i = 0; i < length; ++i) {
|
2014-01-25 01:31:17 -08:00
|
|
|
if (!JS_SetElement(cx, durationArray, i, mHangReports.GetDuration(i))) {
|
2012-11-27 05:52:25 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2014-01-27 13:47:00 -08:00
|
|
|
if (!JS_SetElement(cx, systemUptimeArray, i, mHangReports.GetSystemUptime(i))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
if (!JS_SetElement(cx, firefoxUptimeArray, i, mHangReports.GetFirefoxUptime(i))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2012-11-27 05:52:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSObject *
|
|
|
|
CreateJSStackObject(JSContext *cx, const CombinedStacks &stacks) {
|
2014-01-16 09:48:58 -08:00
|
|
|
JS::Rooted<JSObject*> ret(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
|
2012-11-27 05:52:25 -08:00
|
|
|
if (!ret) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-02-12 02:50:46 -08:00
|
|
|
JS::Rooted<JSObject*> moduleArray(cx, JS_NewArrayObject(cx, 0));
|
2012-11-20 06:45:14 -08:00
|
|
|
if (!moduleArray) {
|
2012-11-27 05:52:25 -08:00
|
|
|
return nullptr;
|
2012-11-20 06:45:14 -08:00
|
|
|
}
|
2014-01-21 18:11:17 -08:00
|
|
|
bool ok = JS_DefineProperty(cx, ret, "memoryMap", moduleArray,
|
|
|
|
JSPROP_ENUMERATE);
|
2012-11-20 06:45:14 -08:00
|
|
|
if (!ok) {
|
2012-11-27 05:52:25 -08:00
|
|
|
return nullptr;
|
2012-03-12 04:07:05 -07:00
|
|
|
}
|
|
|
|
|
2012-11-27 05:52:25 -08:00
|
|
|
const size_t moduleCount = stacks.GetModuleCount();
|
2012-11-20 06:45:14 -08:00
|
|
|
for (size_t moduleIndex = 0; moduleIndex < moduleCount; ++moduleIndex) {
|
|
|
|
// Current module
|
|
|
|
const Telemetry::ProcessedStack::Module& module =
|
2012-11-27 05:52:25 -08:00
|
|
|
stacks.GetModule(moduleIndex);
|
2012-11-20 06:45:14 -08:00
|
|
|
|
2014-02-12 02:50:46 -08:00
|
|
|
JS::Rooted<JSObject*> moduleInfoArray(cx, JS_NewArrayObject(cx, 0));
|
2012-11-20 06:45:14 -08:00
|
|
|
if (!moduleInfoArray) {
|
2012-11-27 05:52:25 -08:00
|
|
|
return nullptr;
|
2012-03-12 04:07:05 -07:00
|
|
|
}
|
2014-01-25 01:31:17 -08:00
|
|
|
if (!JS_SetElement(cx, moduleArray, moduleIndex, moduleInfoArray)) {
|
2012-11-27 05:52:25 -08:00
|
|
|
return nullptr;
|
2012-03-12 04:07:05 -07:00
|
|
|
}
|
|
|
|
|
2012-11-20 06:45:14 -08:00
|
|
|
unsigned index = 0;
|
2012-03-12 04:07:05 -07:00
|
|
|
|
2012-11-20 06:45:14 -08:00
|
|
|
// Module name
|
2014-01-25 01:31:17 -08:00
|
|
|
JS::Rooted<JSString*> str(cx, JS_NewStringCopyZ(cx, module.mName.c_str()));
|
2012-11-20 06:45:14 -08:00
|
|
|
if (!str) {
|
2012-11-27 05:52:25 -08:00
|
|
|
return nullptr;
|
2012-03-12 04:07:05 -07:00
|
|
|
}
|
2014-01-25 01:31:17 -08:00
|
|
|
if (!JS_SetElement(cx, moduleInfoArray, index++, str)) {
|
2012-11-27 05:52:25 -08:00
|
|
|
return nullptr;
|
2012-03-12 04:07:05 -07:00
|
|
|
}
|
|
|
|
|
2013-01-09 12:05:00 -08:00
|
|
|
// Module breakpad identifier
|
2014-01-25 01:31:17 -08:00
|
|
|
JS::Rooted<JSString*> id(cx, JS_NewStringCopyZ(cx, module.mBreakpadId.c_str()));
|
2013-01-09 12:05:00 -08:00
|
|
|
if (!id) {
|
2012-11-27 05:52:25 -08:00
|
|
|
return nullptr;
|
2012-03-12 04:07:05 -07:00
|
|
|
}
|
2014-01-25 01:31:17 -08:00
|
|
|
if (!JS_SetElement(cx, moduleInfoArray, index++, id)) {
|
2012-11-27 05:52:25 -08:00
|
|
|
return nullptr;
|
2012-11-20 06:45:14 -08:00
|
|
|
}
|
|
|
|
}
|
2012-03-12 04:07:05 -07:00
|
|
|
|
2014-02-12 02:50:46 -08:00
|
|
|
JS::Rooted<JSObject*> reportArray(cx, JS_NewArrayObject(cx, 0));
|
2012-11-20 06:45:14 -08:00
|
|
|
if (!reportArray) {
|
2012-11-27 05:52:25 -08:00
|
|
|
return nullptr;
|
2012-11-20 06:45:14 -08:00
|
|
|
}
|
2014-01-21 18:11:17 -08:00
|
|
|
ok = JS_DefineProperty(cx, ret, "stacks", reportArray, JSPROP_ENUMERATE);
|
2012-11-20 06:45:14 -08:00
|
|
|
if (!ok) {
|
2012-11-27 05:52:25 -08:00
|
|
|
return nullptr;
|
2012-11-20 06:45:14 -08:00
|
|
|
}
|
2012-03-12 04:07:05 -07:00
|
|
|
|
2012-11-27 05:52:25 -08:00
|
|
|
const size_t length = stacks.GetStackCount();
|
|
|
|
for (size_t i = 0; i < length; ++i) {
|
2012-11-20 06:45:14 -08:00
|
|
|
// Represent call stack PCs as (module index, offset) pairs.
|
2014-02-12 02:50:46 -08:00
|
|
|
JS::Rooted<JSObject*> pcArray(cx, JS_NewArrayObject(cx, 0));
|
2012-11-20 06:45:14 -08:00
|
|
|
if (!pcArray) {
|
2012-11-27 05:52:25 -08:00
|
|
|
return nullptr;
|
2012-11-20 06:45:14 -08:00
|
|
|
}
|
2012-03-12 04:07:05 -07:00
|
|
|
|
2014-01-25 01:31:17 -08:00
|
|
|
if (!JS_SetElement(cx, reportArray, i, pcArray)) {
|
2012-11-27 05:52:25 -08:00
|
|
|
return nullptr;
|
2012-11-20 06:45:14 -08:00
|
|
|
}
|
2012-03-12 04:07:05 -07:00
|
|
|
|
2012-11-27 05:52:25 -08:00
|
|
|
const CombinedStacks::Stack& stack = stacks.GetStack(i);
|
2012-11-20 06:45:14 -08:00
|
|
|
const uint32_t pcCount = stack.size();
|
|
|
|
for (size_t pcIndex = 0; pcIndex < pcCount; ++pcIndex) {
|
|
|
|
const Telemetry::ProcessedStack::Frame& frame = stack[pcIndex];
|
2014-02-12 02:50:46 -08:00
|
|
|
JS::Rooted<JSObject*> framePair(cx, JS_NewArrayObject(cx, 0));
|
2012-11-20 06:45:14 -08:00
|
|
|
if (!framePair) {
|
2012-11-27 05:52:25 -08:00
|
|
|
return nullptr;
|
2012-03-12 04:07:05 -07:00
|
|
|
}
|
2012-11-20 06:45:14 -08:00
|
|
|
int modIndex = (std::numeric_limits<uint16_t>::max() == frame.mModIndex) ?
|
|
|
|
-1 : frame.mModIndex;
|
2014-01-25 01:31:17 -08:00
|
|
|
if (!JS_SetElement(cx, framePair, 0, modIndex)) {
|
2012-11-27 05:52:25 -08:00
|
|
|
return nullptr;
|
2012-03-12 04:07:05 -07:00
|
|
|
}
|
2014-01-25 01:31:17 -08:00
|
|
|
if (!JS_SetElement(cx, framePair, 1, static_cast<double>(frame.mOffset))) {
|
2012-11-27 05:52:25 -08:00
|
|
|
return nullptr;
|
2012-03-19 16:05:25 -07:00
|
|
|
}
|
2014-01-25 01:31:17 -08:00
|
|
|
if (!JS_SetElement(cx, pcArray, pcIndex, framePair)) {
|
2012-11-27 05:52:25 -08:00
|
|
|
return nullptr;
|
2012-03-19 16:05:25 -07:00
|
|
|
}
|
2012-03-12 04:07:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-27 05:52:25 -08:00
|
|
|
return ret;
|
2012-03-12 04:07:05 -07:00
|
|
|
}
|
|
|
|
|
2013-01-15 15:55:35 -08:00
|
|
|
static bool
|
|
|
|
IsValidBreakpadId(const std::string &breakpadId) {
|
|
|
|
if (breakpadId.size() < 33) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (unsigned i = 0, n = breakpadId.size(); i < n; ++i) {
|
|
|
|
char c = breakpadId[i];
|
|
|
|
if ((c < '0' || c > '9') && (c < 'A' || c > 'F')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-08 06:04:37 -08:00
|
|
|
// Read a stack from the given file name. In case of any error, aStack is
|
|
|
|
// unchanged.
|
|
|
|
static void
|
|
|
|
ReadStack(const char *aFileName, Telemetry::ProcessedStack &aStack)
|
|
|
|
{
|
|
|
|
std::ifstream file(aFileName);
|
|
|
|
|
|
|
|
size_t numModules;
|
|
|
|
file >> numModules;
|
|
|
|
if (file.fail()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char newline = file.get();
|
|
|
|
if (file.fail() || newline != '\n') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Telemetry::ProcessedStack stack;
|
|
|
|
for (size_t i = 0; i < numModules; ++i) {
|
2013-01-15 15:55:35 -08:00
|
|
|
std::string breakpadId;
|
|
|
|
file >> breakpadId;
|
|
|
|
if (file.fail() || !IsValidBreakpadId(breakpadId)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char space = file.get();
|
|
|
|
if (file.fail() || space != ' ') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-08 06:04:37 -08:00
|
|
|
std::string moduleName;
|
|
|
|
getline(file, moduleName);
|
2013-01-15 15:55:35 -08:00
|
|
|
if (file.fail() || moduleName[0] == ' ') {
|
2013-01-08 06:04:37 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Telemetry::ProcessedStack::Module module = {
|
|
|
|
moduleName,
|
2013-01-15 15:55:35 -08:00
|
|
|
breakpadId
|
2013-01-08 06:04:37 -08:00
|
|
|
};
|
|
|
|
stack.AddModule(module);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t numFrames;
|
|
|
|
file >> numFrames;
|
|
|
|
if (file.fail()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
newline = file.get();
|
|
|
|
if (file.fail() || newline != '\n') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < numFrames; ++i) {
|
|
|
|
uint16_t index;
|
|
|
|
file >> index;
|
|
|
|
uintptr_t offset;
|
|
|
|
file >> std::hex >> offset >> std::dec;
|
|
|
|
if (file.fail()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Telemetry::ProcessedStack::Frame frame = {
|
|
|
|
offset,
|
|
|
|
index
|
|
|
|
};
|
|
|
|
stack.AddFrame(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
aStack = stack;
|
|
|
|
}
|
|
|
|
|
2013-11-22 11:17:31 -08:00
|
|
|
static JSObject*
|
|
|
|
CreateJSTimeHistogram(JSContext* cx, const Telemetry::TimeHistogram& time)
|
|
|
|
{
|
|
|
|
/* Create JS representation of TimeHistogram,
|
|
|
|
in the format of Chromium-style histograms. */
|
2014-01-16 09:48:58 -08:00
|
|
|
JS::RootedObject ret(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
|
2013-11-22 11:17:31 -08:00
|
|
|
if (!ret) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-01-21 18:11:17 -08:00
|
|
|
if (!JS_DefineProperty(cx, ret, "min", time.GetBucketMin(0),
|
|
|
|
JSPROP_ENUMERATE) ||
|
2013-11-22 11:17:31 -08:00
|
|
|
!JS_DefineProperty(cx, ret, "max",
|
2014-01-21 18:11:17 -08:00
|
|
|
time.GetBucketMax(ArrayLength(time) - 1),
|
|
|
|
JSPROP_ENUMERATE) ||
|
2013-11-22 11:17:31 -08:00
|
|
|
!JS_DefineProperty(cx, ret, "histogram_type",
|
2014-01-21 18:11:17 -08:00
|
|
|
nsITelemetry::HISTOGRAM_EXPONENTIAL,
|
|
|
|
JSPROP_ENUMERATE)) {
|
2013-11-22 11:17:31 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
// TODO: calculate "sum", "log_sum", and "log_sum_squares"
|
2014-01-21 18:11:17 -08:00
|
|
|
if (!JS_DefineProperty(cx, ret, "sum", 0, JSPROP_ENUMERATE) ||
|
|
|
|
!JS_DefineProperty(cx, ret, "log_sum", 0.0, JSPROP_ENUMERATE) ||
|
|
|
|
!JS_DefineProperty(cx, ret, "log_sum_squares", 0.0, JSPROP_ENUMERATE)) {
|
2013-11-22 11:17:31 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::RootedObject ranges(
|
2014-02-12 02:50:46 -08:00
|
|
|
cx, JS_NewArrayObject(cx, ArrayLength(time) + 1));
|
2013-11-22 11:17:31 -08:00
|
|
|
JS::RootedObject counts(
|
2014-02-12 02:50:46 -08:00
|
|
|
cx, JS_NewArrayObject(cx, ArrayLength(time) + 1));
|
2013-11-22 11:17:31 -08:00
|
|
|
if (!ranges || !counts) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
/* In a Chromium-style histogram, the first bucket is an "under" bucket
|
|
|
|
that represents all values below the histogram's range. */
|
2014-01-25 01:31:17 -08:00
|
|
|
if (!JS_SetElement(cx, ranges, 0, time.GetBucketMin(0)) ||
|
|
|
|
!JS_SetElement(cx, counts, 0, 0)) {
|
2013-11-22 11:17:31 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
for (size_t i = 0; i < ArrayLength(time); i++) {
|
2014-01-25 01:31:17 -08:00
|
|
|
if (!JS_SetElement(cx, ranges, i + 1, time.GetBucketMax(i)) ||
|
|
|
|
!JS_SetElement(cx, counts, i + 1, time[i])) {
|
2013-11-22 11:17:31 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
2014-01-21 18:11:17 -08:00
|
|
|
if (!JS_DefineProperty(cx, ret, "ranges", ranges, JSPROP_ENUMERATE) ||
|
|
|
|
!JS_DefineProperty(cx, ret, "counts", counts, JSPROP_ENUMERATE)) {
|
2013-11-22 11:17:31 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSObject*
|
|
|
|
CreateJSHangHistogram(JSContext* cx, const Telemetry::HangHistogram& hang)
|
|
|
|
{
|
2014-01-16 09:48:58 -08:00
|
|
|
JS::RootedObject ret(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
|
2013-11-22 11:17:31 -08:00
|
|
|
if (!ret) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Telemetry::HangHistogram::Stack& hangStack = hang.GetStack();
|
|
|
|
JS::RootedObject stack(cx,
|
2014-02-12 02:50:46 -08:00
|
|
|
JS_NewArrayObject(cx, hangStack.length()));
|
2013-11-22 11:17:31 -08:00
|
|
|
if (!ret) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
for (size_t i = 0; i < hangStack.length(); i++) {
|
|
|
|
JS::RootedString string(cx, JS_NewStringCopyZ(cx, hangStack[i]));
|
2014-01-25 01:31:17 -08:00
|
|
|
if (!JS_SetElement(cx, stack, i, string)) {
|
2013-11-22 11:17:31 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::RootedObject time(cx, CreateJSTimeHistogram(cx, hang));
|
|
|
|
if (!time ||
|
2014-01-21 18:11:17 -08:00
|
|
|
!JS_DefineProperty(cx, ret, "stack", stack, JSPROP_ENUMERATE) ||
|
|
|
|
!JS_DefineProperty(cx, ret, "histogram", time, JSPROP_ENUMERATE)) {
|
2013-11-22 11:17:31 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSObject*
|
|
|
|
CreateJSThreadHangStats(JSContext* cx, const Telemetry::ThreadHangStats& thread)
|
|
|
|
{
|
2014-01-16 09:48:58 -08:00
|
|
|
JS::RootedObject ret(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
|
2013-11-22 11:17:31 -08:00
|
|
|
if (!ret) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
JS::RootedString name(cx, JS_NewStringCopyZ(cx, thread.GetName()));
|
|
|
|
if (!name ||
|
2014-01-21 18:11:17 -08:00
|
|
|
!JS_DefineProperty(cx, ret, "name", name, JSPROP_ENUMERATE)) {
|
2013-11-22 11:17:31 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::RootedObject activity(cx, CreateJSTimeHistogram(cx, thread.mActivity));
|
|
|
|
if (!activity ||
|
2014-01-21 18:11:17 -08:00
|
|
|
!JS_DefineProperty(cx, ret, "activity", activity, JSPROP_ENUMERATE)) {
|
2013-11-22 11:17:31 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-02-12 02:50:46 -08:00
|
|
|
JS::RootedObject hangs(cx, JS_NewArrayObject(cx, 0));
|
2013-11-22 11:17:31 -08:00
|
|
|
if (!hangs) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
for (size_t i = 0; i < thread.mHangs.length(); i++) {
|
|
|
|
JS::RootedObject obj(cx, CreateJSHangHistogram(cx, thread.mHangs[i]));
|
2014-01-25 01:31:17 -08:00
|
|
|
if (!JS_SetElement(cx, hangs, i, obj)) {
|
2013-11-22 11:17:31 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
2014-01-21 18:11:17 -08:00
|
|
|
if (!JS_DefineProperty(cx, ret, "hangs", hangs, JSPROP_ENUMERATE)) {
|
2013-11-22 11:17:31 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-09 09:39:36 -08:00
|
|
|
TelemetryImpl::GetThreadHangStats(JSContext* cx, JS::MutableHandle<JS::Value> ret)
|
2013-11-22 11:17:31 -08:00
|
|
|
{
|
2014-02-12 02:50:46 -08:00
|
|
|
JS::RootedObject retObj(cx, JS_NewArrayObject(cx, 0));
|
2013-11-22 11:17:31 -08:00
|
|
|
if (!retObj) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
size_t threadIndex = 0;
|
|
|
|
|
2014-02-12 07:24:21 -08:00
|
|
|
#ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR
|
2013-11-22 11:17:31 -08:00
|
|
|
/* First add active threads; we need to hold |iter| (and its lock)
|
|
|
|
throughout this method to avoid a race condition where a thread can
|
|
|
|
be recorded twice if the thread is destroyed while this method is
|
|
|
|
running */
|
|
|
|
BackgroundHangMonitor::ThreadHangStatsIterator iter;
|
|
|
|
for (Telemetry::ThreadHangStats* histogram = iter.GetNext();
|
|
|
|
histogram; histogram = iter.GetNext()) {
|
|
|
|
JS::RootedObject obj(cx,
|
|
|
|
CreateJSThreadHangStats(cx, *histogram));
|
2014-01-25 01:31:17 -08:00
|
|
|
if (!JS_SetElement(cx, retObj, threadIndex++, obj)) {
|
2013-11-22 11:17:31 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
2014-02-12 07:24:21 -08:00
|
|
|
#endif
|
2013-11-22 11:17:31 -08:00
|
|
|
|
|
|
|
// Add saved threads next
|
|
|
|
MutexAutoLock autoLock(mThreadHangStatsMutex);
|
|
|
|
for (size_t i = 0; i < mThreadHangStats.length(); i++) {
|
|
|
|
JS::RootedObject obj(cx,
|
|
|
|
CreateJSThreadHangStats(cx, mThreadHangStats[i]));
|
2014-01-25 01:31:17 -08:00
|
|
|
if (!JS_SetElement(cx, retObj, threadIndex++, obj)) {
|
2013-11-22 11:17:31 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
2014-01-09 09:39:36 -08:00
|
|
|
ret.setObject(*retObj);
|
2013-11-22 11:17:31 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-08 06:04:37 -08:00
|
|
|
void
|
2013-05-10 08:37:13 -07:00
|
|
|
TelemetryImpl::ReadLateWritesStacks(nsIFile* aProfileDir)
|
2013-01-08 06:04:37 -08:00
|
|
|
{
|
|
|
|
nsAutoCString nativePath;
|
2013-05-10 08:37:13 -07:00
|
|
|
nsresult rv = aProfileDir->GetNativePath(nativePath);
|
2013-01-08 06:04:37 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *name = nativePath.get();
|
|
|
|
PRDir *dir = PR_OpenDir(name);
|
|
|
|
if (!dir) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRDirEntry *ent;
|
|
|
|
const char *prefix = "Telemetry.LateWriteFinal-";
|
|
|
|
unsigned int prefixLen = strlen(prefix);
|
|
|
|
while ((ent = PR_ReadDir(dir, PR_SKIP_NONE))) {
|
|
|
|
if (strncmp(prefix, ent->name, prefixLen) != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString stackNativePath = nativePath;
|
|
|
|
stackNativePath += XPCOM_FILE_PATH_SEPARATOR;
|
|
|
|
stackNativePath += nsDependentCString(ent->name);
|
|
|
|
|
|
|
|
Telemetry::ProcessedStack stack;
|
|
|
|
ReadStack(stackNativePath.get(), stack);
|
|
|
|
if (stack.GetStackSize() != 0) {
|
|
|
|
mLateWritesStacks.AddStack(stack);
|
|
|
|
}
|
|
|
|
// Delete the file so that we don't report it again on the next run.
|
|
|
|
PR_Delete(stackNativePath.get());
|
|
|
|
}
|
|
|
|
PR_CloseDir(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-09 09:39:36 -08:00
|
|
|
TelemetryImpl::GetLateWrites(JSContext *cx, JS::MutableHandle<JS::Value> ret)
|
2013-01-08 06:04:37 -08:00
|
|
|
{
|
|
|
|
// The user must call AsyncReadTelemetryData first. We return an empty list
|
|
|
|
// instead of reporting a failure so that the rest of telemetry can uniformly
|
|
|
|
// handle the read not being available yet.
|
|
|
|
|
|
|
|
// FIXME: we allocate the js object again and again in the getter. We should
|
|
|
|
// figure out a way to cache it. In order to do that we have to call
|
|
|
|
// JS_AddNamedObjectRoot. A natural place to do so is in the TelemetryImpl
|
|
|
|
// constructor, but it is not clear how to get a JSContext in there.
|
|
|
|
// Another option would be to call it in here when we first call
|
|
|
|
// CreateJSStackObject, but we would still need to figure out where to call
|
|
|
|
// JS_RemoveObjectRoot. Would it be ok to never call JS_RemoveObjectRoot
|
|
|
|
// and just set the pointer to nullptr is the telemetry destructor?
|
|
|
|
|
|
|
|
JSObject *report;
|
|
|
|
if (!mCachedTelemetryData) {
|
|
|
|
CombinedStacks empty;
|
|
|
|
report = CreateJSStackObject(cx, empty);
|
|
|
|
} else {
|
|
|
|
report = CreateJSStackObject(cx, mLateWritesStacks);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (report == nullptr) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-01-09 09:39:36 -08:00
|
|
|
ret.setObject(*report);
|
2013-01-08 06:04:37 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-06 11:40:45 -08:00
|
|
|
NS_IMETHODIMP
|
2013-12-13 09:56:11 -08:00
|
|
|
TelemetryImpl::RegisteredHistograms(uint32_t *aCount, char*** aHistograms)
|
2012-01-06 11:40:45 -08:00
|
|
|
{
|
|
|
|
size_t count = ArrayLength(gHistograms);
|
2014-01-03 09:02:48 -08:00
|
|
|
size_t offset = 0;
|
2013-12-13 09:56:11 -08:00
|
|
|
char** histograms = static_cast<char**>(nsMemory::Alloc(count * sizeof(char*)));
|
2012-01-06 11:40:45 -08:00
|
|
|
|
|
|
|
for (size_t i = 0; i < count; ++i) {
|
2014-01-03 09:02:48 -08:00
|
|
|
if (IsExpired(gHistograms[i].expiration())) {
|
|
|
|
offset++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-12-13 09:56:11 -08:00
|
|
|
const char* h = gHistograms[i].id();
|
|
|
|
size_t len = strlen(h);
|
2014-01-03 09:02:48 -08:00
|
|
|
histograms[i - offset] = static_cast<char*>(nsMemory::Clone(h, len+1));
|
2012-01-06 11:40:45 -08:00
|
|
|
}
|
|
|
|
|
2014-01-03 09:02:48 -08:00
|
|
|
*aCount = count - offset;
|
2013-12-13 09:56:11 -08:00
|
|
|
*aHistograms = histograms;
|
2012-01-06 11:40:45 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-16 12:33:18 -08:00
|
|
|
NS_IMETHODIMP
|
2014-01-09 09:39:36 -08:00
|
|
|
TelemetryImpl::GetHistogramById(const nsACString &name, JSContext *cx,
|
|
|
|
JS::MutableHandle<JS::Value> ret)
|
2011-11-16 12:33:18 -08:00
|
|
|
{
|
2011-06-20 14:47:58 -07:00
|
|
|
Histogram *h;
|
2012-01-06 11:39:29 -08:00
|
|
|
nsresult rv = GetHistogramByName(name, &h);
|
2011-06-20 14:47:58 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return WrapAndReturnHistogram(h, cx, ret);
|
2011-04-27 11:07:02 -07:00
|
|
|
}
|
|
|
|
|
2011-06-28 16:57:44 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
TelemetryImpl::GetCanRecord(bool *ret) {
|
2011-06-28 16:57:44 -07:00
|
|
|
*ret = mCanRecord;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
TelemetryImpl::SetCanRecord(bool canRecord) {
|
2011-06-28 16:57:44 -07:00
|
|
|
mCanRecord = !!canRecord;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TelemetryImpl::CanRecord() {
|
|
|
|
return !sTelemetry || sTelemetry->mCanRecord;
|
|
|
|
}
|
2011-06-20 14:47:58 -07:00
|
|
|
|
2012-02-01 20:42:20 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
TelemetryImpl::GetCanSend(bool *ret) {
|
|
|
|
#if defined(MOZILLA_OFFICIAL) && defined(MOZ_TELEMETRY_REPORTING)
|
|
|
|
*ret = true;
|
|
|
|
#else
|
|
|
|
*ret = false;
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-20 14:47:58 -07:00
|
|
|
already_AddRefed<nsITelemetry>
|
2011-06-28 16:57:44 -07:00
|
|
|
TelemetryImpl::CreateTelemetryInstance()
|
|
|
|
{
|
2013-10-10 13:38:05 -07:00
|
|
|
NS_ABORT_IF_FALSE(sTelemetry == nullptr, "CreateTelemetryInstance may only be called once, via GetService()");
|
2013-01-17 16:45:11 -08:00
|
|
|
sTelemetry = new TelemetryImpl();
|
2011-06-28 16:57:44 -07:00
|
|
|
// AddRef for the local reference
|
|
|
|
NS_ADDREF(sTelemetry);
|
|
|
|
// AddRef for the caller
|
2013-04-22 04:15:59 -07:00
|
|
|
nsCOMPtr<nsITelemetry> ret = sTelemetry;
|
2013-11-06 21:35:30 -08:00
|
|
|
|
|
|
|
sTelemetry->InitMemoryReporter();
|
|
|
|
|
2013-04-22 04:15:59 -07:00
|
|
|
return ret.forget();
|
2011-06-28 16:57:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TelemetryImpl::ShutdownTelemetry()
|
2011-04-27 11:07:02 -07:00
|
|
|
{
|
2013-12-09 15:30:06 -08:00
|
|
|
// No point in collecting IO beyond this point
|
|
|
|
ClearIOReporting();
|
2011-06-28 16:57:44 -07:00
|
|
|
NS_IF_RELEASE(sTelemetry);
|
2011-04-27 11:07:02 -07:00
|
|
|
}
|
|
|
|
|
2011-12-06 12:12:55 -08:00
|
|
|
void
|
2012-05-16 04:39:21 -07:00
|
|
|
TelemetryImpl::StoreSlowSQL(const nsACString &sql, uint32_t delay,
|
2012-08-21 12:29:28 -07:00
|
|
|
SanitizedState state)
|
2011-12-06 12:12:55 -08:00
|
|
|
{
|
2013-10-10 13:38:05 -07:00
|
|
|
AutoHashtable<SlowSQLEntryType> *slowSQLMap = nullptr;
|
2012-08-21 12:29:28 -07:00
|
|
|
if (state == Sanitized)
|
|
|
|
slowSQLMap = &(sTelemetry->mSanitizedSQL);
|
2011-12-06 12:12:55 -08:00
|
|
|
else
|
2012-08-21 12:29:28 -07:00
|
|
|
slowSQLMap = &(sTelemetry->mPrivateSQL);
|
2011-12-06 12:12:55 -08:00
|
|
|
|
|
|
|
MutexAutoLock hashMutex(sTelemetry->mHashMutex);
|
2012-03-21 10:26:48 -07:00
|
|
|
|
|
|
|
SlowSQLEntryType *entry = slowSQLMap->GetEntry(sql);
|
2011-12-06 12:12:55 -08:00
|
|
|
if (!entry) {
|
2012-03-21 10:26:48 -07:00
|
|
|
entry = slowSQLMap->PutEntry(sql);
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(!entry))
|
2011-12-06 12:12:55 -08:00
|
|
|
return;
|
2012-08-21 12:29:28 -07:00
|
|
|
entry->mData.mainThread.hitCount = 0;
|
|
|
|
entry->mData.mainThread.totalTime = 0;
|
|
|
|
entry->mData.otherThreads.hitCount = 0;
|
|
|
|
entry->mData.otherThreads.totalTime = 0;
|
|
|
|
}
|
2012-03-21 10:26:48 -07:00
|
|
|
|
2012-08-21 12:29:28 -07:00
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
entry->mData.mainThread.hitCount++;
|
|
|
|
entry->mData.mainThread.totalTime += delay;
|
|
|
|
} else {
|
|
|
|
entry->mData.otherThreads.hitCount++;
|
|
|
|
entry->mData.otherThreads.totalTime += delay;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method replaces string literals in SQL strings with the word :private
|
|
|
|
*
|
|
|
|
* States used in this state machine:
|
|
|
|
*
|
|
|
|
* NORMAL:
|
|
|
|
* - This is the active state when not iterating over a string literal or
|
|
|
|
* comment
|
|
|
|
*
|
|
|
|
* SINGLE_QUOTE:
|
|
|
|
* - Defined here: http://www.sqlite.org/lang_expr.html
|
|
|
|
* - This state represents iterating over a string literal opened with
|
|
|
|
* a single quote.
|
|
|
|
* - A single quote within the string can be encoded by putting 2 single quotes
|
|
|
|
* in a row, e.g. 'This literal contains an escaped quote '''
|
|
|
|
* - Any double quotes found within a single-quoted literal are ignored
|
|
|
|
* - This state covers BLOB literals, e.g. X'ABC123'
|
|
|
|
* - The string literal and the enclosing quotes will be replaced with
|
|
|
|
* the text :private
|
|
|
|
*
|
|
|
|
* DOUBLE_QUOTE:
|
|
|
|
* - Same rules as the SINGLE_QUOTE state.
|
|
|
|
* - According to http://www.sqlite.org/lang_keywords.html,
|
|
|
|
* SQLite interprets text in double quotes as an identifier unless it's used in
|
|
|
|
* a context where it cannot be resolved to an identifier and a string literal
|
|
|
|
* is allowed. This method removes text in double-quotes for safety.
|
|
|
|
*
|
|
|
|
* DASH_COMMENT:
|
|
|
|
* - http://www.sqlite.org/lang_comment.html
|
|
|
|
* - A dash comment starts with two dashes in a row,
|
|
|
|
* e.g. DROP TABLE foo -- a comment
|
|
|
|
* - Any text following two dashes in a row is interpreted as a comment until
|
|
|
|
* end of input or a newline character
|
|
|
|
* - Any quotes found within the comment are ignored and no replacements made
|
|
|
|
*
|
|
|
|
* C_STYLE_COMMENT:
|
|
|
|
* - http://www.sqlite.org/lang_comment.html
|
|
|
|
* - A C-style comment starts with a forward slash and an asterisk, and ends
|
|
|
|
* with an asterisk and a forward slash
|
|
|
|
* - Any text following comment start is interpreted as a comment up to end of
|
|
|
|
* input or comment end
|
|
|
|
* - Any quotes found within the comment are ignored and no replacements made
|
|
|
|
*/
|
|
|
|
nsCString
|
|
|
|
TelemetryImpl::SanitizeSQL(const nsACString &sql) {
|
|
|
|
nsCString output;
|
|
|
|
int length = sql.Length();
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
NORMAL,
|
|
|
|
SINGLE_QUOTE,
|
|
|
|
DOUBLE_QUOTE,
|
|
|
|
DASH_COMMENT,
|
|
|
|
C_STYLE_COMMENT,
|
|
|
|
} State;
|
|
|
|
|
|
|
|
State state = NORMAL;
|
|
|
|
int fragmentStart = 0;
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
char character = sql[i];
|
|
|
|
char nextCharacter = (i + 1 < length) ? sql[i + 1] : '\0';
|
|
|
|
|
|
|
|
switch (character) {
|
|
|
|
case '\'':
|
|
|
|
case '"':
|
|
|
|
if (state == NORMAL) {
|
|
|
|
state = (character == '\'') ? SINGLE_QUOTE : DOUBLE_QUOTE;
|
|
|
|
output += nsDependentCSubstring(sql, fragmentStart, i - fragmentStart);
|
|
|
|
output += ":private";
|
|
|
|
fragmentStart = -1;
|
|
|
|
} else if ((state == SINGLE_QUOTE && character == '\'') ||
|
|
|
|
(state == DOUBLE_QUOTE && character == '"')) {
|
|
|
|
if (nextCharacter == character) {
|
|
|
|
// Two consecutive quotes within a string literal are a single escaped quote
|
|
|
|
i++;
|
|
|
|
} else {
|
|
|
|
state = NORMAL;
|
|
|
|
fragmentStart = i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
if (state == NORMAL) {
|
|
|
|
if (nextCharacter == '-') {
|
|
|
|
state = DASH_COMMENT;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
if (state == DASH_COMMENT) {
|
|
|
|
state = NORMAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '/':
|
|
|
|
if (state == NORMAL) {
|
|
|
|
if (nextCharacter == '*') {
|
|
|
|
state = C_STYLE_COMMENT;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '*':
|
|
|
|
if (state == C_STYLE_COMMENT) {
|
|
|
|
if (nextCharacter == '/') {
|
|
|
|
state = NORMAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
2011-12-06 12:12:55 -08:00
|
|
|
}
|
2012-03-21 10:26:48 -07:00
|
|
|
|
2012-08-21 12:29:28 -07:00
|
|
|
if ((fragmentStart >= 0) && fragmentStart < length)
|
|
|
|
output += nsDependentCSubstring(sql, fragmentStart, length - fragmentStart);
|
|
|
|
|
|
|
|
return output;
|
2011-12-06 12:12:55 -08:00
|
|
|
}
|
|
|
|
|
2013-09-03 14:41:27 -07:00
|
|
|
// Slow SQL statements will be automatically
|
|
|
|
// trimmed to kMaxSlowStatementLength characters.
|
|
|
|
// This limit doesn't include the ellipsis and DB name,
|
|
|
|
// that are appended at the end of the stored statement.
|
|
|
|
const uint32_t kMaxSlowStatementLength = 1000;
|
|
|
|
|
2012-03-21 10:26:48 -07:00
|
|
|
void
|
2012-08-21 12:29:28 -07:00
|
|
|
TelemetryImpl::RecordSlowStatement(const nsACString &sql,
|
|
|
|
const nsACString &dbName,
|
|
|
|
uint32_t delay)
|
2012-03-21 10:26:48 -07:00
|
|
|
{
|
2012-08-31 12:20:20 -07:00
|
|
|
if (!sTelemetry || !sTelemetry->mCanRecord)
|
2012-03-21 10:26:48 -07:00
|
|
|
return;
|
2013-12-17 16:07:18 -08:00
|
|
|
|
2012-08-21 12:29:28 -07:00
|
|
|
bool isFirefoxDB = sTelemetry->mTrackedDBs.Contains(dbName);
|
|
|
|
if (isFirefoxDB) {
|
2013-09-03 14:41:27 -07:00
|
|
|
nsAutoCString sanitizedSQL(SanitizeSQL(sql));
|
|
|
|
if (sanitizedSQL.Length() > kMaxSlowStatementLength) {
|
|
|
|
sanitizedSQL.SetLength(kMaxSlowStatementLength);
|
|
|
|
sanitizedSQL += "...";
|
|
|
|
}
|
2013-12-17 16:07:18 -08:00
|
|
|
sanitizedSQL.AppendPrintf(" /* %s */", nsPromiseFlatCString(dbName).get());
|
2012-08-21 12:29:28 -07:00
|
|
|
StoreSlowSQL(sanitizedSQL, delay, Sanitized);
|
|
|
|
} else {
|
|
|
|
// Report aggregate DB-level statistics for addon DBs
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString aggregate;
|
2013-12-17 16:07:18 -08:00
|
|
|
aggregate.AppendPrintf("Untracked SQL for %s",
|
|
|
|
nsPromiseFlatCString(dbName).get());
|
2012-08-21 12:29:28 -07:00
|
|
|
StoreSlowSQL(aggregate, delay, Sanitized);
|
2012-03-21 10:26:48 -07:00
|
|
|
}
|
|
|
|
|
2013-12-17 16:07:18 -08:00
|
|
|
nsAutoCString fullSQL;
|
|
|
|
fullSQL.AppendPrintf("%s /* %s */",
|
|
|
|
nsPromiseFlatCString(sql).get(),
|
|
|
|
nsPromiseFlatCString(dbName).get());
|
2012-08-21 12:29:28 -07:00
|
|
|
StoreSlowSQL(fullSQL, delay, Unsanitized);
|
2012-03-21 10:26:48 -07:00
|
|
|
}
|
|
|
|
|
2012-03-14 19:57:04 -07:00
|
|
|
#if defined(MOZ_ENABLE_PROFILER_SPS)
|
2012-03-12 04:07:05 -07:00
|
|
|
void
|
2014-01-27 13:47:00 -08:00
|
|
|
TelemetryImpl::RecordChromeHang(uint32_t aDuration,
|
|
|
|
Telemetry::ProcessedStack &aStack,
|
|
|
|
int32_t aSystemUptime,
|
|
|
|
int32_t aFirefoxUptime)
|
2012-03-12 04:07:05 -07:00
|
|
|
{
|
2012-08-31 12:20:20 -07:00
|
|
|
if (!sTelemetry || !sTelemetry->mCanRecord)
|
2012-03-12 04:07:05 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
MutexAutoLock hangReportMutex(sTelemetry->mHangReportsMutex);
|
|
|
|
|
2014-01-27 13:47:00 -08:00
|
|
|
sTelemetry->mHangReports.AddHang(aStack, aDuration,
|
|
|
|
aSystemUptime, aFirefoxUptime);
|
2012-03-12 04:07:05 -07:00
|
|
|
}
|
2012-03-14 19:57:04 -07:00
|
|
|
#endif
|
2012-03-12 04:07:05 -07:00
|
|
|
|
2013-11-22 11:17:31 -08:00
|
|
|
void
|
|
|
|
TelemetryImpl::RecordThreadHangStats(Telemetry::ThreadHangStats& aStats)
|
|
|
|
{
|
|
|
|
if (!sTelemetry || !sTelemetry->mCanRecord)
|
|
|
|
return;
|
|
|
|
|
|
|
|
MutexAutoLock autoLock(sTelemetry->mThreadHangStatsMutex);
|
|
|
|
|
|
|
|
sTelemetry->mThreadHangStats.append(Move(aStats));
|
|
|
|
}
|
|
|
|
|
2013-12-07 22:09:10 -08:00
|
|
|
NS_IMPL_ISUPPORTS2(TelemetryImpl, nsITelemetry, nsIMemoryReporter)
|
2011-06-28 16:57:44 -07:00
|
|
|
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsITelemetry, TelemetryImpl::CreateTelemetryInstance)
|
2011-04-27 11:07:02 -07:00
|
|
|
|
|
|
|
#define NS_TELEMETRY_CID \
|
2011-05-19 19:33:05 -07:00
|
|
|
{0xaea477f2, 0xb3a2, 0x469c, {0xaa, 0x29, 0x0a, 0x82, 0xd1, 0x32, 0xb8, 0x29}}
|
2011-04-27 11:07:02 -07:00
|
|
|
NS_DEFINE_NAMED_CID(NS_TELEMETRY_CID);
|
|
|
|
|
2011-06-20 14:47:58 -07:00
|
|
|
const Module::CIDEntry kTelemetryCIDs[] = {
|
2013-10-10 13:38:05 -07:00
|
|
|
{ &kNS_TELEMETRY_CID, false, nullptr, nsITelemetryConstructor },
|
|
|
|
{ nullptr }
|
2011-04-27 11:07:02 -07:00
|
|
|
};
|
|
|
|
|
2011-06-20 14:47:58 -07:00
|
|
|
const Module::ContractIDEntry kTelemetryContracts[] = {
|
2011-04-27 11:07:02 -07:00
|
|
|
{ "@mozilla.org/base/telemetry;1", &kNS_TELEMETRY_CID },
|
2013-10-10 13:38:05 -07:00
|
|
|
{ nullptr }
|
2011-04-27 11:07:02 -07:00
|
|
|
};
|
|
|
|
|
2011-06-20 14:47:58 -07:00
|
|
|
const Module kTelemetryModule = {
|
|
|
|
Module::kVersion,
|
2011-04-27 11:07:02 -07:00
|
|
|
kTelemetryCIDs,
|
|
|
|
kTelemetryContracts,
|
2013-10-10 13:38:05 -07:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2011-06-28 16:57:44 -07:00
|
|
|
TelemetryImpl::ShutdownTelemetry
|
2011-04-27 11:07:02 -07:00
|
|
|
};
|
|
|
|
|
2013-12-09 15:30:06 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
TelemetryImpl::GetFileIOReports(JSContext *cx, JS::MutableHandleValue ret)
|
|
|
|
{
|
|
|
|
if (sTelemetryIOObserver) {
|
|
|
|
JS::Rooted<JSObject*> obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(),
|
|
|
|
JS::NullPtr()));
|
|
|
|
if (!obj) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sTelemetryIOObserver->ReflectIntoJS(cx, obj)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
ret.setObject(*obj);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
ret.setNull();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-03-14 06:24:02 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
TelemetryImpl::MsSinceProcessStart(double* aResult)
|
|
|
|
{
|
|
|
|
bool error;
|
|
|
|
*aResult = (TimeStamp::NowLoRes() -
|
|
|
|
TimeStamp::ProcessCreation(error)).ToMilliseconds();
|
|
|
|
if (error) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-31 19:14:51 -08:00
|
|
|
size_t
|
|
|
|
TelemetryImpl::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
|
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
// Ignore the hashtables in mAddonMap; they are not significant.
|
|
|
|
n += mAddonMap.SizeOfExcludingThis(nullptr, aMallocSizeOf);
|
|
|
|
n += mHistogramMap.SizeOfExcludingThis(nullptr, aMallocSizeOf);
|
2014-03-24 09:24:51 -07:00
|
|
|
{ // Scope for mHashMutex lock
|
|
|
|
MutexAutoLock lock(mHashMutex);
|
|
|
|
n += mPrivateSQL.SizeOfExcludingThis(nullptr, aMallocSizeOf);
|
|
|
|
n += mSanitizedSQL.SizeOfExcludingThis(nullptr, aMallocSizeOf);
|
|
|
|
}
|
2014-01-31 19:14:51 -08:00
|
|
|
n += mTrackedDBs.SizeOfExcludingThis(nullptr, aMallocSizeOf);
|
2014-03-24 09:24:51 -07:00
|
|
|
{ // Scope for mHangReportsMutex lock
|
|
|
|
MutexAutoLock lock(mHangReportsMutex);
|
|
|
|
n += mHangReports.SizeOfExcludingThis();
|
|
|
|
}
|
|
|
|
{ // Scope for mThreadHangStatsMutex lock
|
|
|
|
MutexAutoLock lock(mThreadHangStatsMutex);
|
|
|
|
n += mThreadHangStats.sizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
2014-01-31 19:14:51 -08:00
|
|
|
|
|
|
|
// It's a bit gross that we measure this other stuff that lives outside of
|
|
|
|
// TelemetryImpl... oh well.
|
|
|
|
if (sTelemetryIOObserver) {
|
|
|
|
n += sTelemetryIOObserver->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
StatisticsRecorder::Histograms hs;
|
|
|
|
StatisticsRecorder::GetHistograms(&hs);
|
|
|
|
for (HistogramIterator it = hs.begin(); it != hs.end(); ++it) {
|
|
|
|
Histogram *h = *it;
|
|
|
|
n += h->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2011-05-19 19:33:05 -07:00
|
|
|
} // anonymous namespace
|
|
|
|
|
2011-06-20 14:47:58 -07:00
|
|
|
namespace mozilla {
|
2012-12-13 09:06:27 -08:00
|
|
|
void
|
|
|
|
RecordShutdownStartTimeStamp() {
|
2013-01-17 08:40:14 -08:00
|
|
|
#ifdef DEBUG
|
2013-01-18 08:14:31 -08:00
|
|
|
// FIXME: this function should only be called once, since it should be called
|
|
|
|
// at the earliest point we *know* we are shutting down. Unfortunately
|
|
|
|
// this assert has been firing. Given that if we are called multiple times
|
|
|
|
// we just keep the last timestamp, the assert is commented for now.
|
2013-01-17 08:40:14 -08:00
|
|
|
static bool recorded = false;
|
2013-01-18 08:14:31 -08:00
|
|
|
// MOZ_ASSERT(!recorded);
|
2013-03-14 22:33:14 -07:00
|
|
|
(void)recorded; // Silence unused-var warnings (remove when assert re-enabled)
|
2013-01-17 08:40:14 -08:00
|
|
|
recorded = true;
|
|
|
|
#endif
|
|
|
|
|
2012-12-13 09:06:27 -08:00
|
|
|
if (!Telemetry::CanRecord())
|
|
|
|
return;
|
|
|
|
|
|
|
|
gRecordedShutdownStartTime = TimeStamp::Now();
|
|
|
|
|
|
|
|
GetShutdownTimeFileName();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RecordShutdownEndTimeStamp() {
|
|
|
|
if (!gRecordedShutdownTimeFileName || gAlreadyFreedShutdownTimeFileName)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCString name(gRecordedShutdownTimeFileName);
|
|
|
|
PL_strfree(gRecordedShutdownTimeFileName);
|
|
|
|
gRecordedShutdownTimeFileName = nullptr;
|
|
|
|
gAlreadyFreedShutdownTimeFileName = true;
|
|
|
|
|
|
|
|
nsCString tmpName = name;
|
|
|
|
tmpName += ".tmp";
|
|
|
|
FILE *f = fopen(tmpName.get(), "w");
|
|
|
|
if (!f)
|
|
|
|
return;
|
|
|
|
// On a normal release build this should be called just before
|
|
|
|
// calling _exit, but on a debug build or when the user forces a full
|
|
|
|
// shutdown this is called as late as possible, so we have to
|
|
|
|
// white list this write as write poisoning will be enabled.
|
2013-11-18 10:21:26 -08:00
|
|
|
MozillaRegisterDebugFILE(f);
|
2012-12-13 09:06:27 -08:00
|
|
|
|
|
|
|
TimeStamp now = TimeStamp::Now();
|
|
|
|
MOZ_ASSERT(now >= gRecordedShutdownStartTime);
|
|
|
|
TimeDuration diff = now - gRecordedShutdownStartTime;
|
|
|
|
uint32_t diff2 = diff.ToMilliseconds();
|
|
|
|
int written = fprintf(f, "%d\n", diff2);
|
|
|
|
MozillaUnRegisterDebugFILE(f);
|
|
|
|
int rv = fclose(f);
|
|
|
|
if (written < 0 || rv != 0) {
|
|
|
|
PR_Delete(tmpName.get());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PR_Delete(name.get());
|
|
|
|
PR_Rename(tmpName.get(), name.get());
|
|
|
|
}
|
|
|
|
|
2011-06-20 14:47:58 -07:00
|
|
|
namespace Telemetry {
|
|
|
|
|
|
|
|
void
|
2012-05-16 04:39:21 -07:00
|
|
|
Accumulate(ID aHistogram, uint32_t aSample)
|
2011-06-20 14:47:58 -07:00
|
|
|
{
|
2011-06-28 16:57:44 -07:00
|
|
|
if (!TelemetryImpl::CanRecord()) {
|
|
|
|
return;
|
|
|
|
}
|
2011-06-20 14:47:58 -07:00
|
|
|
Histogram *h;
|
|
|
|
nsresult rv = GetHistogramByEnumId(aHistogram, &h);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
h->Add(aSample);
|
|
|
|
}
|
|
|
|
|
2013-08-15 12:04:15 -07:00
|
|
|
void
|
|
|
|
Accumulate(const char* name, uint32_t sample)
|
|
|
|
{
|
|
|
|
if (!TelemetryImpl::CanRecord()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ID id;
|
|
|
|
nsresult rv = TelemetryImpl::GetHistogramEnumId(name, &id);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Histogram *h;
|
|
|
|
rv = GetHistogramByEnumId(id, &h);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
h->Add(sample);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-10 10:04:57 -07:00
|
|
|
void
|
|
|
|
AccumulateTimeDelta(ID aHistogram, TimeStamp start, TimeStamp end)
|
|
|
|
{
|
|
|
|
Accumulate(aHistogram,
|
2012-05-16 04:39:21 -07:00
|
|
|
static_cast<uint32_t>((end - start).ToMilliseconds()));
|
2011-10-10 10:04:57 -07:00
|
|
|
}
|
|
|
|
|
2012-01-18 09:08:18 -08:00
|
|
|
bool
|
|
|
|
CanRecord()
|
|
|
|
{
|
|
|
|
return TelemetryImpl::CanRecord();
|
|
|
|
}
|
|
|
|
|
2011-08-05 06:53:48 -07:00
|
|
|
base::Histogram*
|
|
|
|
GetHistogramById(ID id)
|
|
|
|
{
|
2013-10-10 13:38:05 -07:00
|
|
|
Histogram *h = nullptr;
|
2011-08-05 06:53:48 -07:00
|
|
|
GetHistogramByEnumId(id, &h);
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2011-12-06 12:12:55 -08:00
|
|
|
void
|
|
|
|
RecordSlowSQLStatement(const nsACString &statement,
|
|
|
|
const nsACString &dbName,
|
2012-08-21 12:29:28 -07:00
|
|
|
uint32_t delay)
|
2011-12-06 12:12:55 -08:00
|
|
|
{
|
2012-08-21 12:29:28 -07:00
|
|
|
TelemetryImpl::RecordSlowStatement(statement, dbName, delay);
|
2011-12-06 12:12:55 -08:00
|
|
|
}
|
|
|
|
|
2012-01-10 12:29:58 -08:00
|
|
|
void Init()
|
|
|
|
{
|
|
|
|
// Make the service manager hold a long-lived reference to the service
|
|
|
|
nsCOMPtr<nsITelemetry> telemetryService =
|
|
|
|
do_GetService("@mozilla.org/base/telemetry;1");
|
|
|
|
MOZ_ASSERT(telemetryService);
|
|
|
|
}
|
|
|
|
|
2012-03-14 19:57:04 -07:00
|
|
|
#if defined(MOZ_ENABLE_PROFILER_SPS)
|
2012-05-16 04:39:21 -07:00
|
|
|
void RecordChromeHang(uint32_t duration,
|
2014-01-27 13:47:00 -08:00
|
|
|
ProcessedStack &aStack,
|
|
|
|
int32_t aSystemUptime,
|
|
|
|
int32_t aFirefoxUptime)
|
2012-08-21 14:14:38 -07:00
|
|
|
{
|
2014-01-27 13:47:00 -08:00
|
|
|
TelemetryImpl::RecordChromeHang(duration, aStack,
|
|
|
|
aSystemUptime, aFirefoxUptime);
|
2012-08-21 14:14:38 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-11-22 11:17:31 -08:00
|
|
|
void RecordThreadHangStats(ThreadHangStats& aStats)
|
|
|
|
{
|
|
|
|
TelemetryImpl::RecordThreadHangStats(aStats);
|
|
|
|
}
|
|
|
|
|
2012-08-21 14:14:38 -07:00
|
|
|
ProcessedStack::ProcessedStack()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t ProcessedStack::GetStackSize() const
|
|
|
|
{
|
|
|
|
return mStack.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
const ProcessedStack::Frame &ProcessedStack::GetFrame(unsigned aIndex) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aIndex < mStack.size());
|
|
|
|
return mStack[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessedStack::AddFrame(const Frame &aFrame)
|
|
|
|
{
|
|
|
|
mStack.push_back(aFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t ProcessedStack::GetNumModules() const
|
|
|
|
{
|
|
|
|
return mModules.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
const ProcessedStack::Module &ProcessedStack::GetModule(unsigned aIndex) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aIndex < mModules.size());
|
|
|
|
return mModules[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessedStack::AddModule(const Module &aModule)
|
|
|
|
{
|
|
|
|
mModules.push_back(aModule);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessedStack::Clear() {
|
|
|
|
mModules.clear();
|
|
|
|
mStack.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProcessedStack::Module::operator==(const Module& aOther) const {
|
|
|
|
return mName == aOther.mName &&
|
2013-01-09 12:05:00 -08:00
|
|
|
mBreakpadId == aOther.mBreakpadId;
|
2012-08-21 14:14:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
struct StackFrame
|
|
|
|
{
|
|
|
|
uintptr_t mPC; // The program counter at this position in the call stack.
|
|
|
|
uint16_t mIndex; // The number of this frame in the call stack.
|
|
|
|
uint16_t mModIndex; // The index of module that has this program counter.
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef MOZ_ENABLE_PROFILER_SPS
|
|
|
|
static bool CompareByPC(const StackFrame &a, const StackFrame &b)
|
2012-03-12 04:07:05 -07:00
|
|
|
{
|
2012-08-21 14:14:38 -07:00
|
|
|
return a.mPC < b.mPC;
|
2012-03-12 04:07:05 -07:00
|
|
|
}
|
2012-08-21 14:14:38 -07:00
|
|
|
|
|
|
|
static bool CompareByIndex(const StackFrame &a, const StackFrame &b)
|
|
|
|
{
|
|
|
|
return a.mIndex < b.mIndex;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-11-20 06:45:14 -08:00
|
|
|
ProcessedStack
|
|
|
|
GetStackAndModules(const std::vector<uintptr_t>& aPCs)
|
2012-08-21 14:14:38 -07:00
|
|
|
{
|
|
|
|
std::vector<StackFrame> rawStack;
|
|
|
|
for (std::vector<uintptr_t>::const_iterator i = aPCs.begin(),
|
|
|
|
e = aPCs.end(); i != e; ++i) {
|
|
|
|
uintptr_t aPC = *i;
|
|
|
|
StackFrame Frame = {aPC, static_cast<uint16_t>(rawStack.size()),
|
|
|
|
std::numeric_limits<uint16_t>::max()};
|
|
|
|
rawStack.push_back(Frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_ENABLE_PROFILER_SPS
|
|
|
|
// Remove all modules not referenced by a PC on the stack
|
|
|
|
std::sort(rawStack.begin(), rawStack.end(), CompareByPC);
|
|
|
|
|
|
|
|
size_t moduleIndex = 0;
|
|
|
|
size_t stackIndex = 0;
|
|
|
|
size_t stackSize = rawStack.size();
|
|
|
|
|
|
|
|
SharedLibraryInfo rawModules = SharedLibraryInfo::GetInfoForSelf();
|
|
|
|
rawModules.SortByAddress();
|
|
|
|
|
|
|
|
while (moduleIndex < rawModules.GetSize()) {
|
|
|
|
const SharedLibrary& module = rawModules.GetEntry(moduleIndex);
|
|
|
|
uintptr_t moduleStart = module.GetStart();
|
|
|
|
uintptr_t moduleEnd = module.GetEnd() - 1;
|
|
|
|
// the interval is [moduleStart, moduleEnd)
|
|
|
|
|
|
|
|
bool moduleReferenced = false;
|
|
|
|
for (;stackIndex < stackSize; ++stackIndex) {
|
|
|
|
uintptr_t pc = rawStack[stackIndex].mPC;
|
|
|
|
if (pc >= moduleEnd)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (pc >= moduleStart) {
|
|
|
|
// If the current PC is within the current module, mark
|
|
|
|
// module as used
|
|
|
|
moduleReferenced = true;
|
2012-11-20 06:45:14 -08:00
|
|
|
rawStack[stackIndex].mPC -= moduleStart;
|
2012-08-21 14:14:38 -07:00
|
|
|
rawStack[stackIndex].mModIndex = moduleIndex;
|
|
|
|
} else {
|
|
|
|
// PC does not belong to any module. It is probably from
|
|
|
|
// the JIT. Use a fixed mPC so that we don't get different
|
|
|
|
// stacks on different runs.
|
|
|
|
rawStack[stackIndex].mPC =
|
|
|
|
std::numeric_limits<uintptr_t>::max();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (moduleReferenced) {
|
|
|
|
++moduleIndex;
|
|
|
|
} else {
|
|
|
|
// Remove module if no PCs within its address range
|
|
|
|
rawModules.RemoveEntries(moduleIndex, moduleIndex + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;stackIndex < stackSize; ++stackIndex) {
|
|
|
|
// These PCs are past the last module.
|
|
|
|
rawStack[stackIndex].mPC = std::numeric_limits<uintptr_t>::max();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort(rawStack.begin(), rawStack.end(), CompareByIndex);
|
2012-03-14 19:57:04 -07:00
|
|
|
#endif
|
2012-03-12 04:07:05 -07:00
|
|
|
|
2012-08-21 14:14:38 -07:00
|
|
|
// Copy the information to the return value.
|
|
|
|
ProcessedStack Ret;
|
|
|
|
for (std::vector<StackFrame>::iterator i = rawStack.begin(),
|
|
|
|
e = rawStack.end(); i != e; ++i) {
|
|
|
|
const StackFrame &rawFrame = *i;
|
|
|
|
ProcessedStack::Frame frame = { rawFrame.mPC, rawFrame.mModIndex };
|
|
|
|
Ret.AddFrame(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_ENABLE_PROFILER_SPS
|
|
|
|
for (unsigned i = 0, n = rawModules.GetSize(); i != n; ++i) {
|
|
|
|
const SharedLibrary &info = rawModules.GetEntry(i);
|
2013-01-16 18:02:32 -08:00
|
|
|
const std::string &name = info.GetName();
|
|
|
|
std::string basename = name;
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// FIXME: We want to use just the basename as the libname, but the
|
|
|
|
// current profiler addon needs the full path name, so we compute the
|
|
|
|
// basename in here.
|
|
|
|
size_t pos = name.rfind('/');
|
|
|
|
if (pos != std::string::npos) {
|
|
|
|
basename = name.substr(pos + 1);
|
|
|
|
}
|
|
|
|
#endif
|
2012-08-21 14:14:38 -07:00
|
|
|
ProcessedStack::Module module = {
|
2013-01-16 18:02:32 -08:00
|
|
|
basename,
|
2013-01-09 12:05:00 -08:00
|
|
|
info.GetBreakpadId()
|
2012-08-21 14:14:38 -07:00
|
|
|
};
|
|
|
|
Ret.AddModule(module);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
2013-01-31 13:11:38 -08:00
|
|
|
void
|
|
|
|
WriteFailedProfileLock(nsIFile* aProfileDir)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
nsresult rv = GetFailedProfileLockFile(getter_AddRefs(file), aProfileDir);
|
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
|
|
|
int64_t fileSize = 0;
|
|
|
|
rv = file->GetFileSize(&fileSize);
|
|
|
|
// It's expected that the file might not exist yet
|
|
|
|
if (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIFileStream> fileStream;
|
|
|
|
rv = NS_NewLocalFileStream(getter_AddRefs(fileStream), file,
|
|
|
|
PR_RDWR | PR_CREATE_FILE, 0640);
|
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
|
|
|
NS_ENSURE_TRUE_VOID(fileSize <= kMaxFailedProfileLockFileSize);
|
|
|
|
unsigned int failedLockCount = 0;
|
|
|
|
if (fileSize > 0) {
|
|
|
|
nsCOMPtr<nsIInputStream> inStream = do_QueryInterface(fileStream);
|
|
|
|
NS_ENSURE_TRUE_VOID(inStream);
|
|
|
|
if (!GetFailedLockCount(inStream, fileSize, failedLockCount)) {
|
|
|
|
failedLockCount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++failedLockCount;
|
|
|
|
nsAutoCString bufStr;
|
|
|
|
bufStr.AppendInt(static_cast<int>(failedLockCount));
|
|
|
|
nsCOMPtr<nsISeekableStream> seekStream = do_QueryInterface(fileStream);
|
|
|
|
NS_ENSURE_TRUE_VOID(seekStream);
|
|
|
|
// If we read in an existing failed lock count, we need to reset the file ptr
|
|
|
|
if (fileSize > 0) {
|
|
|
|
rv = seekStream->Seek(nsISeekableStream::NS_SEEK_SET, 0);
|
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIOutputStream> outStream = do_QueryInterface(fileStream);
|
|
|
|
uint32_t bytesLeft = bufStr.Length();
|
|
|
|
const char* bytes = bufStr.get();
|
|
|
|
do {
|
|
|
|
uint32_t written = 0;
|
|
|
|
rv = outStream->Write(bytes, bytesLeft, &written);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bytes += written;
|
|
|
|
bytesLeft -= written;
|
|
|
|
} while (bytesLeft > 0);
|
|
|
|
seekStream->SetEOF();
|
|
|
|
}
|
|
|
|
|
2013-12-09 15:30:06 -08:00
|
|
|
void
|
|
|
|
InitIOReporting(nsIFile* aXreDir)
|
|
|
|
{
|
|
|
|
// Never initialize twice
|
|
|
|
if (sTelemetryIOObserver) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sTelemetryIOObserver = new TelemetryIOInterposeObserver(aXreDir);
|
|
|
|
IOInterposer::Register(IOInterposeObserver::OpAll, sTelemetryIOObserver);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetProfileDir(nsIFile* aProfD)
|
|
|
|
{
|
|
|
|
if (!sTelemetryIOObserver || !aProfD) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsAutoString profDirPath;
|
|
|
|
nsresult rv = aProfD->GetPath(profDirPath);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-11 13:24:49 -08:00
|
|
|
sTelemetryIOObserver->AddPath(profDirPath, NS_LITERAL_STRING("{profile}"));
|
2013-12-09 15:30:06 -08:00
|
|
|
}
|
2013-11-22 11:17:30 -08:00
|
|
|
|
2014-03-18 15:07:35 -07:00
|
|
|
void
|
|
|
|
LeavingStartupStage()
|
|
|
|
{
|
|
|
|
if (!sTelemetryIOObserver) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sTelemetryIOObserver->SetStage(TelemetryIOInterposeObserver::STAGE_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EnteringShutdownStage()
|
|
|
|
{
|
|
|
|
if (!sTelemetryIOObserver) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sTelemetryIOObserver->SetStage(TelemetryIOInterposeObserver::STAGE_SHUTDOWN);
|
|
|
|
}
|
|
|
|
|
2013-11-22 11:17:30 -08:00
|
|
|
void
|
|
|
|
TimeHistogram::Add(PRIntervalTime aTime)
|
|
|
|
{
|
|
|
|
uint32_t timeMs = PR_IntervalToMilliseconds(aTime);
|
|
|
|
size_t index = mozilla::FloorLog2(timeMs);
|
|
|
|
operator[](index)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
HangHistogram::GetHash(const Stack& aStack)
|
|
|
|
{
|
|
|
|
uint32_t hash = 0;
|
|
|
|
for (const char* const* label = aStack.begin();
|
|
|
|
label != aStack.end(); label++) {
|
|
|
|
/* We only need to hash the pointer instead of the text content
|
|
|
|
because we are assuming constant pointers */
|
|
|
|
hash = AddToHash(hash, *label);
|
|
|
|
}
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HangHistogram::operator==(const HangHistogram& aOther) const
|
|
|
|
{
|
|
|
|
if (mHash != aOther.mHash) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (mStack.length() != aOther.mStack.length()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return PodEqual(mStack.begin(), aOther.mStack.begin(), mStack.length());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-20 14:47:58 -07:00
|
|
|
} // namespace Telemetry
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2011-04-27 11:07:02 -07:00
|
|
|
NSMODULE_DEFN(nsTelemetryModule) = &kTelemetryModule;
|
2011-05-21 23:23:20 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The XRE_TelemetryAdd function is to be used by embedding applications
|
|
|
|
* that can't use mozilla::Telemetry::Accumulate() directly.
|
|
|
|
*/
|
|
|
|
void
|
2012-05-16 04:39:21 -07:00
|
|
|
XRE_TelemetryAccumulate(int aID, uint32_t aSample)
|
2011-05-21 23:23:20 -07:00
|
|
|
{
|
|
|
|
mozilla::Telemetry::Accumulate((mozilla::Telemetry::ID) aID, aSample);
|
|
|
|
}
|