summaryrefslogtreecommitdiff
path: root/base/profiler/tracked_time.cc
blob: 7e0040c03c85cdb64a2f5bbf35438ed804ded254 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/profiler/tracked_time.h"

#include "build/build_config.h"

#if defined(OS_WIN)
#include <mmsystem.h>  // Declare timeGetTime()... after including build_config.
#endif

namespace tracked_objects {

Duration::Duration() : ms_(0) {}
Duration::Duration(int32_t duration) : ms_(duration) {}

Duration& Duration::operator+=(const Duration& other) {
  ms_ += other.ms_;
  return *this;
}

Duration Duration::operator+(const Duration& other) const {
  return Duration(ms_ + other.ms_);
}

bool Duration::operator==(const Duration& other) const {
  return ms_ == other.ms_;
}

bool Duration::operator!=(const Duration& other) const {
  return ms_ != other.ms_;
}

bool Duration::operator>(const Duration& other) const {
  return ms_ > other.ms_;
}

// static
Duration Duration::FromMilliseconds(int ms) { return Duration(ms); }

int32_t Duration::InMilliseconds() const {
  return ms_;
}

//------------------------------------------------------------------------------

TrackedTime::TrackedTime() : ms_(0) {}
TrackedTime::TrackedTime(int32_t ms) : ms_(ms) {}
TrackedTime::TrackedTime(const base::TimeTicks& time)
    : ms_(static_cast<int32_t>((time - base::TimeTicks()).InMilliseconds())) {}

// static
TrackedTime TrackedTime::Now() {
  return TrackedTime(base::TimeTicks::Now());
}

Duration TrackedTime::operator-(const TrackedTime& other) const {
  return Duration(ms_ - other.ms_);
}

TrackedTime TrackedTime::operator+(const Duration& other) const {
  return TrackedTime(ms_ + other.ms_);
}

bool TrackedTime::is_null() const { return ms_ == 0; }

}  // namespace tracked_objects