blob: f7803dc67fdd76687ab17d5e477b53ff119404ce [file] [log] [blame]
mtklein@google.comd36522d2013-10-16 13:02:15 +00001#ifndef DMReporter_DEFINED
2#define DMReporter_DEFINED
3
4#include "SkString.h"
5#include "SkTArray.h"
6#include "SkThread.h"
commit-bot@chromium.orga39874b2014-03-03 15:44:56 +00007#include "SkTime.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00008#include "SkTypes.h"
9
10// Used to report status changes including failures. All public methods are threadsafe.
mtklein@google.comd36522d2013-10-16 13:02:15 +000011namespace DM {
12
13class Reporter : SkNoncopyable {
14public:
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +000015 Reporter() : fPending(0), fFailed(0) {}
mtklein@google.comd36522d2013-10-16 13:02:15 +000016
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +000017 void taskCreated() { sk_atomic_inc(&fPending); }
18 void taskDestroyed() { sk_atomic_dec(&fPending); }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000019 void fail(SkString msg);
mtklein@google.comd36522d2013-10-16 13:02:15 +000020
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +000021 void printStatus(SkString name, SkMSec timeMs) const;
mtklein@google.comd36522d2013-10-16 13:02:15 +000022
mtklein@google.comd36522d2013-10-16 13:02:15 +000023 void getFailures(SkTArray<SkString>*) const;
24
25private:
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +000026 int32_t fPending; // atomic
27 int32_t fFailed; // atomic, == fFailures.count().
mtklein@google.comd36522d2013-10-16 13:02:15 +000028
29 mutable SkMutex fMutex; // Guards fFailures.
30 SkTArray<SkString> fFailures;
31};
32
33
34} // namespace DM
35
36#endif // DMReporter_DEFINED