ScummVM API documentation
lingo-profiler.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef DIRECTOR_LINGO_LINGO_PROFILER_H
23 #define DIRECTOR_LINGO_LINGO_PROFILER_H
24 
25 #include "common/array.h"
26 #include "common/hashmap.h"
27 #include "common/hash-str.h"
28 #include "common/str.h"
29 #include "common/str-array.h"
30 
31 namespace Director {
32 
33 enum ProfilerEventType {
34  kProfBegin = 0,
35  kProfEnd,
36  kProfFrame,
37  kProfFreeze,
38  kProfThaw
39 };
40 
41 struct ProfilerEvent {
42  uint8 type; // ProfilerEventType
43  uint32 seq; // monotonic event order, used for stable ordering
44  uint32 ts; // wall-clock milliseconds at emit time (getMillis)
45  uint32 frame; // score frame number at emit time
46  uint16 depth; // Lingo callstack depth at emit time
47  uint32 nameId; // interned handler name (kProfBegin), else 0
48  uint32 movieId; // interned movie name (owning window's movie)
49 };
50 
52 public:
53  LingoProfiler();
54 
55  bool isEnabled() const { return _enabled; }
56  void setEnabled(bool enabled) { _enabled = enabled; }
57 
58  void onPushContext();
59  void onPopContext();
60  void onFreeze();
61  void onThaw();
62 
63  void clear();
64 
65  const Common::Array<ProfilerEvent> &events() const { return _events; }
66  const Common::String &internedName(uint32 id) const;
67  bool isFull() const { return _full; }
68  uint32 maxEvents() const { return _maxEvents; }
69 
70 private:
71  uint32 intern(const Common::String &s);
72  void record(uint8 type, uint32 nameId);
73 
74  bool _enabled;
75  bool _full;
76  uint32 _seq;
77  uint32 _maxEvents;
78 
79  bool _haveLast;
80  uint32 _lastFrame;
81  uint32 _lastMovieId;
82 
83  // Cache the interned movie id per movie, so the hot path skips the
84  // name copy + hashmap lookup on every event.
85  const void *_lastMoviePtr;
86  uint32 _curMovieId;
87 
89  Common::StringArray _strings;
91 };
92 
93 } // End of namespace Director
94 
95 #endif
Definition: str.h:59
Definition: array.h:52
Definition: archive.h:36
Definition: lingo-profiler.h:41
Definition: lingo-profiler.h:51