2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2019-03-25 01:42:15 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2021-09-11 20:24:37 -07:00
|
|
|
#include <AK/Time.h>
|
2019-05-28 13:48:06 +02:00
|
|
|
#include <sys/time.h>
|
2019-03-25 01:42:15 +01:00
|
|
|
|
2020-02-02 12:34:39 +01:00
|
|
|
namespace Core {
|
|
|
|
|
|
|
|
|
|
class ElapsedTimer {
|
2019-03-25 01:42:15 +01:00
|
|
|
public:
|
2021-09-12 08:21:16 -07:00
|
|
|
static ElapsedTimer start_new();
|
|
|
|
|
|
2020-12-03 22:12:50 -07:00
|
|
|
ElapsedTimer(bool precise = false)
|
|
|
|
|
: m_precise(precise)
|
|
|
|
|
{
|
|
|
|
|
}
|
2019-03-25 01:42:15 +01:00
|
|
|
|
2019-04-01 22:03:32 +02:00
|
|
|
bool is_valid() const { return m_valid; }
|
2019-03-25 01:42:15 +01:00
|
|
|
void start();
|
2021-10-27 23:41:32 +02:00
|
|
|
void reset();
|
2019-03-25 01:42:15 +01:00
|
|
|
int elapsed() const;
|
2021-09-11 20:24:37 -07:00
|
|
|
Time elapsed_time() const;
|
2019-03-25 01:42:15 +01:00
|
|
|
|
2020-09-29 18:22:53 +02:00
|
|
|
const struct timeval& origin_time() const { return m_origin_time; }
|
|
|
|
|
|
2019-03-25 01:42:15 +01:00
|
|
|
private:
|
2020-12-03 22:12:50 -07:00
|
|
|
bool m_precise { false };
|
2019-04-01 22:03:32 +02:00
|
|
|
bool m_valid { false };
|
2020-09-29 18:22:53 +02:00
|
|
|
struct timeval m_origin_time {
|
2019-05-28 11:53:16 +02:00
|
|
|
0, 0
|
|
|
|
|
};
|
2019-03-25 01:42:15 +01:00
|
|
|
};
|
2020-02-02 12:34:39 +01:00
|
|
|
|
|
|
|
|
}
|