summaryrefslogtreecommitdiffstats
path: root/base/profiler/scoped_profile.cc
blob: 93c86e92cce5452e81e3b5d16e71e82e99c443a0 (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
// Copyright (c) 2011 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/scoped_profile.h"

#include "base/location.h"
#include "base/tracked_objects.h"


namespace tracked_objects {


ScopedProfile::ScopedProfile(const Location& location)
    : birth_(ThreadData::TallyABirthIfActive(location)),
      start_of_run_(ThreadData::NowForStartOfRun(birth_)) {
}

ScopedProfile::~ScopedProfile() {
  StopClockAndTally();
}

void ScopedProfile::StopClockAndTally() {
  if (!birth_)
    return;
  ThreadData::TallyRunInAScopedRegionIfTracking(birth_, start_of_run_,
                                                ThreadData::NowForEndOfRun());
  birth_ = NULL;
}

}  // namespace tracked_objects