blob: e0a6a60a0a4086eb9478afe491d42593026c2cc2 [file] [log] [blame]
jkummerow@chromium.org28583c92012-07-16 11:31:55 +00001// Copyright 2012 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#include "v8.h"
29
30#include "counters.h"
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000031#include "isolate.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000032#include "platform.h"
33
kasperl@chromium.org71affb52009-05-26 05:44:31 +000034namespace v8 {
35namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000036
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000037StatsTable::StatsTable()
38 : lookup_function_(NULL),
39 create_histogram_function_(NULL),
40 add_histogram_sample_function_(NULL) {}
41
42
43int* StatsCounter::FindLocationInStatsTable() const {
mstarzinger@chromium.orge9000182013-09-03 11:25:39 +000044 return isolate_->stats_table()->FindLocation(name_);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000045}
46
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000047
jkummerow@chromium.org28583c92012-07-16 11:31:55 +000048void Histogram::AddSample(int sample) {
49 if (Enabled()) {
danno@chromium.orgca29dd82013-04-26 11:59:48 +000050 isolate()->stats_table()->AddHistogramSample(histogram_, sample);
jkummerow@chromium.org28583c92012-07-16 11:31:55 +000051 }
52}
53
54void* Histogram::CreateHistogram() const {
danno@chromium.orgca29dd82013-04-26 11:59:48 +000055 return isolate()->stats_table()->
jkummerow@chromium.org28583c92012-07-16 11:31:55 +000056 CreateHistogram(name_, min_, max_, num_buckets_);
57}
58
mstarzinger@chromium.orge0e1b0d2013-07-08 08:38:06 +000059
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000060// Start the timer.
61void HistogramTimer::Start() {
danno@chromium.orgca29dd82013-04-26 11:59:48 +000062 if (Enabled()) {
jkummerow@chromium.orgdc94e192013-08-30 11:35:42 +000063 timer_.Start();
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000064 }
mstarzinger@chromium.org068ea0a2013-01-30 09:39:44 +000065 if (FLAG_log_internal_timer_events) {
danno@chromium.orgca29dd82013-04-26 11:59:48 +000066 LOG(isolate(), TimerEvent(Logger::START, name()));
mstarzinger@chromium.org068ea0a2013-01-30 09:39:44 +000067 }
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000068}
69
mstarzinger@chromium.orge0e1b0d2013-07-08 08:38:06 +000070
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000071// Stop the timer and record the results.
72void HistogramTimer::Stop() {
danno@chromium.orgca29dd82013-04-26 11:59:48 +000073 if (Enabled()) {
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000074 // Compute the delta between start and stop, in milliseconds.
jkummerow@chromium.orgdc94e192013-08-30 11:35:42 +000075 AddSample(static_cast<int>(timer_.Elapsed().InMilliseconds()));
76 timer_.Stop();
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000077 }
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +000078 if (FLAG_log_internal_timer_events) {
danno@chromium.orgca29dd82013-04-26 11:59:48 +000079 LOG(isolate(), TimerEvent(Logger::END, name()));
ulan@chromium.org8e8d8822012-11-23 14:36:46 +000080 }
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000081}
82
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000083} } // namespace v8::internal