gecko-dev/gfx/layers/composite/FPSCounter.h

115 строки
4.1 KiB
C
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 20; 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_layers_opengl_FPSCounter_h_
#define mozilla_layers_opengl_FPSCounter_h_
#include <algorithm> // for min
#include <stddef.h> // for size_t
#include <map> // for std::map
#include "GLDefs.h" // for GLuint
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
#include "mozilla/RefPtr.h" // for already_AddRefed, RefCounted
#include "mozilla/TimeStamp.h" // for TimeStamp, TimeDuration
#include "nsTArray.h" // for nsAutoTArray, nsTArray_Impl, etc
#include "prio.h" // for NSPR file i/o
namespace mozilla {
namespace layers {
class DataTextureSource;
class Compositor;
// Dump the FPS histogram every 10 seconds or kMaxFrameFPS
const int kFpsDumpInterval = 10;
// On desktop, we can have 240 hz monitors, so 10 seconds
// times 240 frames = 2400
const int kMaxFrames = 2400;
/**
* The FPSCounter tracks how often we composite or have a layer transaction.
* At each composite / layer transaction, we record the timestamp.
* After kFpsDumpInterval number of composites / transactions, we calculate
* the average and standard deviation of frames composited. We dump a histogram,
* which allows for more statistically significant measurements. We also dump
* absolute frame composite times to a file on the device.
* The FPS counters displayed on screen are based on how many frames we
* composited within the last ~1 second. The more accurate measurement is to
* grab the histogram from stderr or grab the FPS timestamp dumps written to file.
*
* To enable dumping to file, enable
* layers.acceleration.draw-fps.write-to-file pref.
double AddFrameAndGetFps(TimeStamp aCurrentFrame) {
AddFrame(aCurrentFrame);
return EstimateFps(aCurrentFrame);
}
* To enable printing histogram data to logcat,
* enable layers.acceleration.draw-fps.print-histogram
*
* Use the HasNext(), GetNextTimeStamp() like an iterator to read the data,
* backwards in time. This abstracts away the mechanics of reading the data.
*/
class FPSCounter {
public:
explicit FPSCounter(const char* aName);
~FPSCounter();
void AddFrame(TimeStamp aTimestamp);
double AddFrameAndGetFps(TimeStamp aTimestamp);
double GetFPS(TimeStamp aTimestamp);
private:
void Init();
bool CapturedFullInterval(TimeStamp aTimestamp);
// Used while iterating backwards over the data
void ResetReverseIterator();
bool HasNext(TimeStamp aTimestamp, double aDuration = kFpsDumpInterval);
TimeStamp GetNextTimeStamp();
int GetLatestReadIndex();
TimeStamp GetLatestTimeStamp();
void WriteFrameTimeStamps(PRFileDesc* fd);
bool IteratedFullInterval(TimeStamp aTimestamp, double aDuration);
void PrintFPS();
int BuildHistogram(std::map<int, int>& aHistogram);
void PrintHistogram(std::map<int, int>& aHistogram);
double GetMean(std::map<int,int> aHistogram);
double GetStdDev(std::map<int, int> aHistogram);
nsresult WriteFrameTimeStamps();
/***
* mFrameTimestamps is a psuedo circular buffer
* Since we have a constant write time and don't
* read at an offset except our latest write
* we don't need an explicit read pointer.
*/
nsAutoTArray<TimeStamp, kMaxFrames> mFrameTimestamps;
int mWriteIndex; // points to next open write slot
int mIteratorIndex; // used only when iterating
const char* mFPSName;
TimeStamp mLastInterval;
};
struct FPSState {
FPSState();
void DrawFPS(TimeStamp, int offsetX, int offsetY, unsigned, Compositor* aCompositor);
void NotifyShadowTreeTransaction() {
mTransactionFps.AddFrame(TimeStamp::Now());
}
FPSCounter mCompositionFps;
FPSCounter mTransactionFps;
private:
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<DataTextureSource> mFPSTextureSource;
};
} // namespace layers
} // namespace mozilla
#endif // mozilla_layers_opengl_FPSCounter_h_