summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-01-28 23:01:47 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-01-28 23:01:47 +0100
commitad53f6afd3de86fa927a2f8cdacdcbf5134af916 (patch)
tree4e1b41093fcfd73eb0add3cc6e27cd7215ce8907
parentcc906a2897277d057c80f501c2a4e29c0c36b9f3 (diff)
downloadserenity-ad53f6afd3de86fa927a2f8cdacdcbf5134af916.zip
LibC: Move Stopwatch thingy into a <serenity.h> header.
This thing is extremely useful for performance testing so let's put it here.
-rw-r--r--LibC/serenity.h34
-rw-r--r--Terminal/Terminal.cpp28
2 files changed, 34 insertions, 28 deletions
diff --git a/LibC/serenity.h b/LibC/serenity.h
new file mode 100644
index 0000000000..0854941942
--- /dev/null
+++ b/LibC/serenity.h
@@ -0,0 +1,34 @@
+#pragma once
+
+#include <stdio.h>
+#include <unistd.h>
+
+#ifdef __cplusplus
+
+struct Stopwatch {
+public:
+ Stopwatch(const char* name)
+ : m_name(name)
+ {
+ read_tsc(&m_start_lsw, &m_start_msw);
+ }
+
+ ~Stopwatch()
+ {
+ unsigned end_lsw;
+ unsigned end_msw;
+ read_tsc(&end_lsw, &end_msw);
+ if (m_start_msw != end_msw) {
+ dbgprintf("Stopwatch: differing msw, no result for %s\n", m_name);
+ }
+ unsigned diff = end_lsw - m_start_lsw;
+ dbgprintf("Stopwatch(%s): %u ticks\n", m_name, diff);
+ }
+
+private:
+ const char* m_name { nullptr };
+ unsigned m_start_lsw { 0 };
+ unsigned m_start_msw { 0 };
+};
+
+#endif // __cplusplus
diff --git a/Terminal/Terminal.cpp b/Terminal/Terminal.cpp
index b4decc8ef1..b98d44d6b9 100644
--- a/Terminal/Terminal.cpp
+++ b/Terminal/Terminal.cpp
@@ -10,33 +10,6 @@
//#define TERMINAL_DEBUG
-struct Stopwatch {
-public:
- Stopwatch(const char* name)
- : m_name(name)
- {
- read_tsc(&m_start_lsw, &m_start_msw);
- }
-
- ~Stopwatch()
- {
- dword end_lsw;
- dword end_msw;
- read_tsc(&end_lsw, &end_msw);
- if (m_start_msw != end_msw) {
- dbgprintf("stopwatch: differing msw, no result for %s\n", m_name);
- }
- dword diff = end_lsw - m_start_lsw;
- dbgprintf("Stopwatch(%s): %u ticks\n", m_name, diff);
- }
-
-private:
- const char* m_name { nullptr };
- dword m_start_lsw { 0 };
- dword m_start_msw { 0 };
-};
-
-
void Terminal::create_window()
{
m_pixel_width = m_columns * font().glyph_width() + m_inset * 2;
@@ -598,7 +571,6 @@ bool Terminal::Line::has_only_one_background_color() const
void Terminal::paint()
{
- Stopwatch sw("Terminal::paint");
Rect rect { 0, 0, m_pixel_width, m_pixel_height };
Painter painter(*m_backing);