blob: b8e545e673e6aed04b567594ba844fba5b64db55 [file] [log] [blame]
Elliott Hughes307f75d2011-10-12 18:04:40 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_SRC_TIMING_LOGGER_H_
18#define ART_SRC_TIMING_LOGGER_H_
19
20#include "logging.h"
21#include "utils.h"
22
23#include <stdint.h>
24
25#include <string>
26#include <vector>
27
28namespace art {
29
30class TimingLogger {
Elliott Hughesff17f1f2012-01-24 18:12:29 -080031 public:
Elliott Hughesa51a3dd2011-10-17 15:19:26 -070032 explicit TimingLogger(const char* name) : name_(name) {
Elliott Hughes307f75d2011-10-12 18:04:40 -070033 AddSplit("");
34 }
35
36 void AddSplit(const std::string& label) {
37 times_.push_back(NanoTime());
38 labels_.push_back(label);
39 }
40
41 void Dump() {
42 LOG(INFO) << name_ << ": begin";
43 for (size_t i = 1; i < times_.size(); ++i) {
Ian Rogers3bb17a62012-01-27 23:56:44 -080044 LOG(INFO) << name_ << ": " << PrettyDuration(times_[i] - times_[i-1]) << labels_[i];
Elliott Hughes307f75d2011-10-12 18:04:40 -070045 }
Ian Rogers3bb17a62012-01-27 23:56:44 -080046 LOG(INFO) << name_ << ": end, " << PrettyDuration(times_.back() - times_.front());
Elliott Hughes307f75d2011-10-12 18:04:40 -070047 }
48
Elliott Hughesff17f1f2012-01-24 18:12:29 -080049 private:
Elliott Hughes307f75d2011-10-12 18:04:40 -070050 std::string name_;
51 std::vector<uint64_t> times_;
52 std::vector<std::string> labels_;
53};
54
55} // namespace art
56
57#endif // ART_SRC_TIMING_LOGGER_H_