blob: f91b830db5e099ae875c910d1328fa8c0d75d573 [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 {
31public:
32 TimingLogger(const char* name) : name_(name) {
33 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) {
44 LOG(INFO) << name_ << StringPrintf(": %8lld ms, ", ToMs(times_[i] - times_[i-1])) << labels_[i];
45 }
46 LOG(INFO) << name_ << ": end, " << ToMs(times_.back() - times_.front()) << " ms";
47 }
48
49private:
50 static uint64_t ToMs(uint64_t ns) {
51 return ns/1000/1000;
52 }
53
54 std::string name_;
55 std::vector<uint64_t> times_;
56 std::vector<std::string> labels_;
57};
58
59} // namespace art
60
61#endif // ART_SRC_TIMING_LOGGER_H_