2011-06-20 14:47:58 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
|
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-06-20 14:47:58 -07:00
|
|
|
|
|
|
|
#ifndef Telemetry_h__
|
|
|
|
#define Telemetry_h__
|
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
#include "mozilla/GuardObjects.h"
|
2011-07-01 12:06:09 -07:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2011-11-17 23:54:27 -08:00
|
|
|
#include "mozilla/StartupTimeline.h"
|
2012-03-12 04:07:05 -07:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsStringGlue.h"
|
2012-03-14 19:57:04 -07:00
|
|
|
#if defined(MOZ_ENABLE_PROFILER_SPS)
|
2012-03-12 04:07:05 -07:00
|
|
|
#include "shared-libraries.h"
|
2012-03-14 19:57:04 -07:00
|
|
|
#endif
|
2011-07-01 12:06:09 -07:00
|
|
|
|
2011-08-05 06:53:48 -07:00
|
|
|
namespace base {
|
|
|
|
class Histogram;
|
|
|
|
}
|
|
|
|
|
2011-06-20 14:47:58 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace Telemetry {
|
|
|
|
|
2012-08-24 12:54:55 -07:00
|
|
|
#include "TelemetryHistogramEnums.h"
|
2011-06-20 14:47:58 -07:00
|
|
|
|
2012-08-26 21:11:55 -07:00
|
|
|
enum TimerResolution {
|
|
|
|
Millisecond,
|
|
|
|
Microsecond
|
|
|
|
};
|
|
|
|
|
2012-01-10 12:29:58 -08:00
|
|
|
/**
|
|
|
|
* Initialize the Telemetry service on the main thread at startup.
|
|
|
|
*/
|
|
|
|
void Init();
|
|
|
|
|
2011-06-20 14:47:58 -07:00
|
|
|
/**
|
|
|
|
* Adds sample to a histogram defined in TelemetryHistograms.h
|
|
|
|
*
|
|
|
|
* @param id - histogram id
|
|
|
|
* @param sample - value to record.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
void Accumulate(ID id, uint32_t sample);
|
2011-06-20 14:47:58 -07:00
|
|
|
|
2011-10-10 10:04:57 -07:00
|
|
|
/**
|
|
|
|
* Adds time delta in milliseconds to a histogram defined in TelemetryHistograms.h
|
|
|
|
*
|
|
|
|
* @param id - histogram id
|
|
|
|
* @param start - start time
|
|
|
|
* @param end - end time
|
|
|
|
*/
|
|
|
|
void AccumulateTimeDelta(ID id, TimeStamp start, TimeStamp end = TimeStamp::Now());
|
|
|
|
|
2011-08-05 06:53:48 -07:00
|
|
|
/**
|
|
|
|
* Return a raw Histogram for direct manipulation for users who can not use Accumulate().
|
|
|
|
*/
|
|
|
|
base::Histogram* GetHistogramById(ID id);
|
|
|
|
|
2012-08-26 21:11:55 -07:00
|
|
|
/**
|
|
|
|
* Those wrappers are needed because the VS versions we use do not support free
|
|
|
|
* functions with default template arguments.
|
|
|
|
*/
|
|
|
|
template<TimerResolution res>
|
|
|
|
struct AccumulateDelta_impl
|
|
|
|
{
|
|
|
|
static void compute(ID id, TimeStamp start, TimeStamp end = TimeStamp::Now());
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct AccumulateDelta_impl<Millisecond>
|
|
|
|
{
|
|
|
|
static void compute(ID id, TimeStamp start, TimeStamp end = TimeStamp::Now()) {
|
|
|
|
Accumulate(id, static_cast<uint32_t>((end - start).ToMilliseconds()));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct AccumulateDelta_impl<Microsecond>
|
|
|
|
{
|
|
|
|
static void compute(ID id, TimeStamp start, TimeStamp end = TimeStamp::Now()) {
|
|
|
|
Accumulate(id, static_cast<uint32_t>((end - start).ToMicroseconds()));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template<ID id, TimerResolution res = Millisecond>
|
2011-07-01 14:39:17 -07:00
|
|
|
class AutoTimer {
|
2011-07-01 12:06:09 -07:00
|
|
|
public:
|
2012-01-09 21:29:30 -08:00
|
|
|
AutoTimer(TimeStamp aStart = TimeStamp::Now() MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2011-10-13 01:48:40 -07:00
|
|
|
: start(aStart)
|
2011-07-01 12:06:09 -07:00
|
|
|
{
|
2012-01-09 21:29:30 -08:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2011-07-01 12:06:09 -07:00
|
|
|
}
|
|
|
|
|
2011-07-01 14:39:17 -07:00
|
|
|
~AutoTimer() {
|
2012-08-26 21:11:55 -07:00
|
|
|
AccumulateDelta_impl<res>::compute(id, start);
|
2011-07-01 12:06:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const TimeStamp start;
|
2012-01-09 21:29:30 -08:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2011-07-01 12:06:09 -07:00
|
|
|
};
|
2011-12-06 12:12:55 -08:00
|
|
|
|
2012-01-09 15:21:28 -08:00
|
|
|
template<ID id>
|
|
|
|
class AutoCounter {
|
|
|
|
public:
|
2012-08-22 08:56:38 -07:00
|
|
|
AutoCounter(uint32_t counterStart = 0 MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2012-01-09 15:21:28 -08:00
|
|
|
: counter(counterStart)
|
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoCounter() {
|
|
|
|
Accumulate(id, counter);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prefix increment only, to encourage good habits.
|
|
|
|
void operator++() {
|
|
|
|
++counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Chaining doesn't make any sense, don't return anything.
|
|
|
|
void operator+=(int increment) {
|
|
|
|
counter += increment;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t counter;
|
2012-01-09 15:21:28 -08:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2012-01-18 09:08:18 -08:00
|
|
|
/**
|
|
|
|
* Indicates whether Telemetry recording is turned on. This is intended
|
|
|
|
* to guard calls to Accumulate when the statistic being recorded is
|
|
|
|
* expensive to compute.
|
|
|
|
*/
|
|
|
|
bool CanRecord();
|
|
|
|
|
2011-12-06 12:12:55 -08:00
|
|
|
/**
|
|
|
|
* Records slow SQL statements for Telemetry reporting.
|
|
|
|
*
|
|
|
|
* @param statement - offending SQL statement to record
|
2012-03-21 10:26:48 -07:00
|
|
|
* @param dbName - DB filename
|
2011-12-06 12:12:55 -08:00
|
|
|
* @param delay - execution time in milliseconds
|
|
|
|
*/
|
|
|
|
void RecordSlowSQLStatement(const nsACString &statement,
|
|
|
|
const nsACString &dbName,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t delay);
|
2011-12-06 12:12:55 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Threshold for a statement to be considered slow, in milliseconds
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint32_t kSlowStatementThreshold = 100;
|
2011-12-06 12:12:55 -08:00
|
|
|
|
2012-08-21 14:14:38 -07:00
|
|
|
class ProcessedStack;
|
2012-03-12 04:07:05 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Record the main thread's call stack after it hangs.
|
|
|
|
*
|
|
|
|
* @param duration - Approximate duration of main thread hang in seconds
|
|
|
|
* @param callStack - Array of PCs from the hung call stack
|
|
|
|
* @param moduleMap - Array of info about modules in memory (for symbolication)
|
|
|
|
*/
|
2012-03-14 19:57:04 -07:00
|
|
|
#if defined(MOZ_ENABLE_PROFILER_SPS)
|
2012-08-22 08:56:38 -07:00
|
|
|
void RecordChromeHang(uint32_t duration,
|
2012-08-21 14:14:38 -07:00
|
|
|
ProcessedStack &aStack);
|
2012-03-14 19:57:04 -07:00
|
|
|
#endif
|
2012-03-12 04:07:05 -07:00
|
|
|
|
2011-06-20 14:47:58 -07:00
|
|
|
} // namespace Telemetry
|
|
|
|
} // namespace mozilla
|
|
|
|
#endif // Telemetry_h__
|