toolkit/components/telemetry/ThreadHangStats.h
author B2G Bumper Bot <release+b2gbumper@mozilla.com>
Fri, 31 Jan 2014 14:05:12 -0800
changeset 182343 4c86e7c1f546598713e5e1565b033562b4ed2be8
parent 171784 4c31b0875e214c33a4abce64b9e8e27d2ef135f6
child 210679 5cc1bec060f9ef4ab0ee8d07dfc3a1d781ff0345
permissions -rw-r--r--
Bumping gaia.json for 4 gaia revision(s) a=gaia-bump ======== https://hg.mozilla.org/integration/gaia-central/rev/4188cf82dc3f Author: Miller Medeiros <miller@millermedeiros.com> Desc: Merge pull request #15630 from millermedeiros/803238-two-months-week-view Bug 803238 - Week view: If the text to display by default in the title (e.g. dow, month, year) exceeds the view length, use short names for day of week, month, year, etc r=gaye ======== https://hg.mozilla.org/integration/gaia-central/rev/41feabe49307 Author: Miller Medeiros <miller@millermedeiros.com> Desc: Bug 803238 - Week view: If the text to display by default in the title (e.g. dow, month, year) exceeds the view length, use short names for day of week, month, year, etc ======== https://hg.mozilla.org/integration/gaia-central/rev/c5b6fcb663c7 Author: Miller Medeiros <miller@millermedeiros.com> Desc: Merge pull request #15384 from millermedeiros/916411-long-title Bug 916411 - [fugu][Buri][Calendar]The event display abnormally when title/where/notes is long r=gaye ======== https://hg.mozilla.org/integration/gaia-central/rev/a1ecc59659e1 Author: millermedeiros <miller@millermedeiros.com> Desc: Bug 916411 - [fugu][Buri][Calendar]The event display abnormally when title/where/notes is long

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
/* 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/. */

#ifndef mozilla_BackgroundHangTelemetry_h
#define mozilla_BackgroundHangTelemetry_h

#include "mozilla/Array.h"
#include "mozilla/Assertions.h"
#include "mozilla/Move.h"
#include "mozilla/Mutex.h"
#include "mozilla/PodOperations.h"
#include "mozilla/Vector.h"

#include "nsString.h"
#include "prinrval.h"

namespace mozilla {
namespace Telemetry {

static const size_t kTimeHistogramBuckets = 8 * sizeof(PRIntervalTime);

/* TimeHistogram is an efficient histogram that puts time durations into
   exponential (base 2) buckets; times are accepted in PRIntervalTime and
   stored in milliseconds. */
class TimeHistogram : public mozilla::Array<uint32_t, kTimeHistogramBuckets>
{
public:
  TimeHistogram()
  {
    mozilla::PodArrayZero(*this);
  }
  // Get minimum (inclusive) range of bucket in milliseconds
  uint32_t GetBucketMin(size_t aBucket) const {
    MOZ_ASSERT(aBucket < ArrayLength(*this));
    return (1u << aBucket) & ~1u; // Bucket 0 starts at 0, not 1
  }
  // Get maximum (inclusive) range of bucket in milliseconds
  uint32_t GetBucketMax(size_t aBucket) const {
    MOZ_ASSERT(aBucket < ArrayLength(*this));
    return (1u << (aBucket + 1u)) - 1u;
  }
  void Add(PRIntervalTime aTime);
};

/* A hang histogram consists of a stack associated with the
   hang, along with a time histogram of the hang times. */
class HangHistogram : public TimeHistogram
{
public:
  typedef mozilla::Vector<const char*, 8> Stack;

private:
  static uint32_t GetHash(const Stack& aStack);

  Stack mStack;
  // Use a hash to speed comparisons
  const uint32_t mHash;

public:
  explicit HangHistogram(Stack&& aStack)
    : mStack(mozilla::Move(aStack))
    , mHash(GetHash(mStack))
  {
  }
  HangHistogram(HangHistogram&& aOther)
    : TimeHistogram(mozilla::Move(aOther))
    , mStack(mozilla::Move(aOther.mStack))
    , mHash(mozilla::Move(aOther.mHash))
  {
  }
  bool operator==(const HangHistogram& aOther) const;
  bool operator!=(const HangHistogram& aOther) const
  {
    return !operator==(aOther);
  }
  const Stack& GetStack() const {
    return mStack;
  }
};

/* Thread hang stats consist of
 - thread name
 - time histogram of all task run times
 - hang histograms of individual hangs. */
class ThreadHangStats
{
private:
  nsAutoCString mName;

public:
  TimeHistogram mActivity;
  mozilla::Vector<HangHistogram, 4> mHangs;

  explicit ThreadHangStats(const char* aName)
    : mName(aName)
  {
  }
  ThreadHangStats(ThreadHangStats&& aOther)
    : mName(mozilla::Move(aOther.mName))
    , mActivity(mozilla::Move(aOther.mActivity))
    , mHangs(mozilla::Move(aOther.mHangs))
  {
  }
  const char* GetName() const {
    return mName.get();
  }
};

} // namespace Telemetry
} // namespace mozilla
#endif // mozilla_BackgroundHangTelemetry_h