blob: 7171f759c98e5bc27f2da76cf6b27c1f359d636b [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 */
jeffhaoe343b762011-12-05 16:36:44 -080016
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_TRACE_H_
18#define ART_RUNTIME_TRACE_H_
jeffhaoe343b762011-12-05 16:36:44 -080019
Andreas Gampe40da2862015-02-27 12:49:04 -080020#include <bitset>
21#include <map>
Ian Rogers700a4022014-05-19 16:49:03 -070022#include <memory>
jeffhaoa9ef3fd2011-12-13 18:33:43 -080023#include <ostream>
24#include <set>
25#include <string>
Mathieu Chartier4d64cd42015-06-02 16:38:29 -070026#include <unordered_map>
Jeff Hao0abc72e2013-08-13 13:45:14 -070027#include <vector>
jeffhaoe343b762011-12-05 16:36:44 -080028
David Sehrc431b9d2018-03-02 12:01:51 -080029#include "base/atomic.h"
Elliott Hughes76160052012-12-12 16:31:20 -080030#include "base/macros.h"
David Sehrc431b9d2018-03-02 12:01:51 -080031#include "base/os.h"
David Sehr67bf42e2018-02-26 16:43:04 -080032#include "base/safe_map.h"
jeffhaoe343b762011-12-05 16:36:44 -080033#include "globals.h"
Ian Rogers62d6c772013-02-27 08:32:07 -080034#include "instrumentation.h"
jeffhaoe343b762011-12-05 16:36:44 -080035
Andreas Gampe6ff3b372018-03-15 08:53:16 -070036namespace unix_file {
37class FdFile;
38} // namespace unix_file
39
jeffhaoe343b762011-12-05 16:36:44 -080040namespace art {
41
Mathieu Chartierc7853442015-03-27 14:35:38 -070042class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070043class ArtMethod;
Andreas Gampe7526d782015-06-22 22:53:45 -070044class DexFile;
Alex Light05f47742017-09-14 00:34:44 +000045class ShadowFrame;
jeffhaoa9ef3fd2011-12-13 18:33:43 -080046class Thread;
jeffhaoe343b762011-12-05 16:36:44 -080047
Andreas Gampe40da2862015-02-27 12:49:04 -080048using DexIndexBitSet = std::bitset<65536>;
Alex Lighta344f6a2016-07-20 10:43:39 -070049
50constexpr size_t kMaxThreadIdNumber = kIsTargetBuild ? 65536U : 1048576U;
51using ThreadIDBitSet = std::bitset<kMaxThreadIdNumber>;
Andreas Gampe40da2862015-02-27 12:49:04 -080052
Jeff Hao64caa7d2013-08-29 11:18:01 -070053enum TracingMode {
54 kTracingInactive,
55 kMethodTracingActive,
56 kSampleProfilingActive,
57};
58
Mathieu Chartier4d64cd42015-06-02 16:38:29 -070059// File format:
60// header
61// record 0
62// record 1
63// ...
64//
65// Header format:
66// u4 magic ('SLOW')
67// u2 version
68// u2 offset to data
69// u8 start date/time in usec
70// u2 record size in bytes (version >= 2 only)
71// ... padding to 32 bytes
72//
73// Record format v1:
74// u1 thread ID
75// u4 method ID | method action
76// u4 time delta since start, in usec
77//
78// Record format v2:
79// u2 thread ID
80// u4 method ID | method action
81// u4 time delta since start, in usec
82//
83// Record format v3:
84// u2 thread ID
85// u4 method ID | method action
86// u4 time delta since start, in usec
87// u4 wall time since start, in usec (when clock == "dual" only)
88//
89// 32 bits of microseconds is 70 minutes.
90//
91// All values are stored in little-endian order.
92
93enum TraceAction {
94 kTraceMethodEnter = 0x00, // method entry
95 kTraceMethodExit = 0x01, // method exit
96 kTraceUnroll = 0x02, // method exited by exception unrolling
97 // 0x03 currently unused
98 kTraceMethodActionMask = 0x03, // two bits
99};
100
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200101class Trace FINAL : public instrumentation::InstrumentationListener {
jeffhaoe343b762011-12-05 16:36:44 -0800102 public:
jeffhao0791adc2012-04-04 11:14:32 -0700103 enum TraceFlag {
104 kTraceCountAllocs = 1,
105 };
106
Andreas Gampe7e7e0f42015-03-29 15:26:23 -0700107 enum class TraceOutputMode {
108 kFile,
Andreas Gampe40da2862015-02-27 12:49:04 -0800109 kDDMS,
110 kStreaming
Andreas Gampe7e7e0f42015-03-29 15:26:23 -0700111 };
112
113 enum class TraceMode {
114 kMethodTracing,
115 kSampling
116 };
117
Andreas Gampe40da2862015-02-27 12:49:04 -0800118 ~Trace();
119
Ian Rogerse63db272014-07-15 15:36:11 -0700120 static void SetDefaultClockSource(TraceClockSource clock_source);
Elliott Hughescfbe73d2012-05-22 17:37:06 -0700121
Andreas Gampe6ff3b372018-03-15 08:53:16 -0700122 static void Start(const char* trace_filename,
123 size_t buffer_size,
124 int flags,
125 TraceOutputMode output_mode,
126 TraceMode trace_mode,
127 int interval_us)
Mathieu Chartier90443472015-07-16 20:32:27 -0700128 REQUIRES(!Locks::mutator_lock_, !Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_,
129 !Locks::trace_lock_);
Andreas Gampe6ff3b372018-03-15 08:53:16 -0700130 static void Start(int trace_fd,
131 size_t buffer_size,
132 int flags,
133 TraceOutputMode output_mode,
134 TraceMode trace_mode,
135 int interval_us)
136 REQUIRES(!Locks::mutator_lock_, !Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_,
137 !Locks::trace_lock_);
138 static void Start(std::unique_ptr<unix_file::FdFile>&& file,
139 size_t buffer_size,
140 int flags,
141 TraceOutputMode output_mode,
142 TraceMode trace_mode,
143 int interval_us)
144 REQUIRES(!Locks::mutator_lock_, !Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_,
145 !Locks::trace_lock_);
146 static void StartDDMS(size_t buffer_size,
147 int flags,
148 TraceMode trace_mode,
149 int interval_us)
150 REQUIRES(!Locks::mutator_lock_, !Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_,
151 !Locks::trace_lock_);
152
Mathieu Chartier90443472015-07-16 20:32:27 -0700153 static void Pause() REQUIRES(!Locks::trace_lock_, !Locks::thread_list_lock_);
154 static void Resume() REQUIRES(!Locks::trace_lock_);
Andreas Gampe40da2862015-02-27 12:49:04 -0800155
156 // Stop tracing. This will finish the trace and write it to file/send it via DDMS.
Sebastien Hertzbae182c2013-12-17 10:42:03 +0100157 static void Stop()
Mathieu Chartier90443472015-07-16 20:32:27 -0700158 REQUIRES(!Locks::mutator_lock_, !Locks::thread_list_lock_, !Locks::trace_lock_);
Andreas Gampe40da2862015-02-27 12:49:04 -0800159 // Abort tracing. This will just stop tracing and *not* write/send the collected data.
160 static void Abort()
Mathieu Chartier90443472015-07-16 20:32:27 -0700161 REQUIRES(!Locks::mutator_lock_, !Locks::thread_list_lock_, !Locks::trace_lock_);
Andreas Gampe7526d782015-06-22 22:53:45 -0700162 static void Shutdown()
Mathieu Chartier90443472015-07-16 20:32:27 -0700163 REQUIRES(!Locks::mutator_lock_, !Locks::thread_list_lock_, !Locks::trace_lock_);
164 static TracingMode GetMethodTracingMode() REQUIRES(!Locks::trace_lock_);
jeffhaoe343b762011-12-05 16:36:44 -0800165
Elliott Hughescfbe73d2012-05-22 17:37:06 -0700166 bool UseWallClock();
167 bool UseThreadCpuClock();
Jeff Haoc5d824a2014-07-28 18:35:38 -0700168 void MeasureClockOverhead();
169 uint32_t GetClockOverheadNanoSeconds();
Elliott Hughescfbe73d2012-05-22 17:37:06 -0700170
Mathieu Chartiere401d142015-04-22 13:56:20 -0700171 void CompareAndUpdateStackTrace(Thread* thread, std::vector<ArtMethod*>* stack_trace)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700172 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!*unique_methods_lock_, !*streaming_lock_);
Jeff Hao0abc72e2013-08-13 13:45:14 -0700173
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200174 // InstrumentationListener implementation.
Alex Lightd7661582017-05-01 13:48:16 -0700175 void MethodEntered(Thread* thread,
176 Handle<mirror::Object> this_object,
177 ArtMethod* method,
178 uint32_t dex_pc)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700179 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!*unique_methods_lock_, !*streaming_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700180 OVERRIDE;
Alex Lightd7661582017-05-01 13:48:16 -0700181 void MethodExited(Thread* thread,
182 Handle<mirror::Object> this_object,
183 ArtMethod* method,
184 uint32_t dex_pc,
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200185 const JValue& return_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700186 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!*unique_methods_lock_, !*streaming_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700187 OVERRIDE;
Alex Lightd7661582017-05-01 13:48:16 -0700188 void MethodUnwind(Thread* thread,
189 Handle<mirror::Object> this_object,
190 ArtMethod* method,
191 uint32_t dex_pc)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700192 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!*unique_methods_lock_, !*streaming_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700193 OVERRIDE;
Alex Lightd7661582017-05-01 13:48:16 -0700194 void DexPcMoved(Thread* thread,
195 Handle<mirror::Object> this_object,
196 ArtMethod* method,
197 uint32_t new_dex_pc)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700198 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!*unique_methods_lock_, !*streaming_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700199 OVERRIDE;
Alex Lightd7661582017-05-01 13:48:16 -0700200 void FieldRead(Thread* thread,
201 Handle<mirror::Object> this_object,
202 ArtMethod* method,
203 uint32_t dex_pc,
204 ArtField* field)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700205 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!*unique_methods_lock_) OVERRIDE;
Alex Lightd7661582017-05-01 13:48:16 -0700206 void FieldWritten(Thread* thread,
207 Handle<mirror::Object> this_object,
208 ArtMethod* method,
209 uint32_t dex_pc,
210 ArtField* field,
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200211 const JValue& field_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700212 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!*unique_methods_lock_) OVERRIDE;
Alex Light6e1607e2017-08-23 10:06:18 -0700213 void ExceptionThrown(Thread* thread,
Alex Lightd7661582017-05-01 13:48:16 -0700214 Handle<mirror::Throwable> exception_object)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700215 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!*unique_methods_lock_) OVERRIDE;
Alex Light798eab02017-08-23 12:54:53 -0700216 void ExceptionHandled(Thread* thread, Handle<mirror::Throwable> exception_object)
217 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!*unique_methods_lock_) OVERRIDE;
Alex Lightd7661582017-05-01 13:48:16 -0700218 void Branch(Thread* thread,
219 ArtMethod* method,
220 uint32_t dex_pc,
221 int32_t dex_pc_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700222 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!*unique_methods_lock_) OVERRIDE;
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100223 void InvokeVirtualOrInterface(Thread* thread,
Alex Lightd7661582017-05-01 13:48:16 -0700224 Handle<mirror::Object> this_object,
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100225 ArtMethod* caller,
226 uint32_t dex_pc,
227 ArtMethod* callee)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700228 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!*unique_methods_lock_) OVERRIDE;
Alex Light05f47742017-09-14 00:34:44 +0000229 void WatchedFramePop(Thread* thread, const ShadowFrame& frame)
230 REQUIRES_SHARED(Locks::mutator_lock_) OVERRIDE;
Jeff Hao5ce4b172013-08-16 16:27:18 -0700231 // Reuse an old stack trace if it exists, otherwise allocate a new one.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700232 static std::vector<ArtMethod*>* AllocStackTrace();
Jeff Hao5ce4b172013-08-16 16:27:18 -0700233 // Clear and store an old stack trace for later use.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700234 static void FreeStackTrace(std::vector<ArtMethod*>* stack_trace);
Jeff Haoe094b872014-10-14 13:12:01 -0700235 // Save id and name of a thread before it exits.
236 static void StoreExitingThreadInfo(Thread* thread);
Jeff Hao5ce4b172013-08-16 16:27:18 -0700237
Mathieu Chartier90443472015-07-16 20:32:27 -0700238 static TraceOutputMode GetOutputMode() REQUIRES(!Locks::trace_lock_);
239 static TraceMode GetMode() REQUIRES(!Locks::trace_lock_);
240 static size_t GetBufferSize() REQUIRES(!Locks::trace_lock_);
Andreas Gampe40da2862015-02-27 12:49:04 -0800241
Mathieu Chartier7778b882015-10-05 16:41:10 -0700242 // Used by class linker to prevent class unloading.
243 static bool IsTracingEnabled() REQUIRES(!Locks::trace_lock_);
244
jeffhaoe343b762011-12-05 16:36:44 -0800245 private:
Andreas Gampe6ff3b372018-03-15 08:53:16 -0700246 Trace(File* trace_file,
247 size_t buffer_size,
248 int flags,
249 TraceOutputMode output_mode,
250 TraceMode trace_mode);
jeffhao2692b572011-12-16 15:42:28 -0800251
Jeff Hao23009dc2013-08-22 15:36:42 -0700252 // The sampling interval in microseconds is passed as an argument.
Mathieu Chartier90443472015-07-16 20:32:27 -0700253 static void* RunSamplingThread(void* arg) REQUIRES(!Locks::trace_lock_);
Jeff Hao0abc72e2013-08-13 13:45:14 -0700254
Andreas Gampe7526d782015-06-22 22:53:45 -0700255 static void StopTracing(bool finish_tracing, bool flush_file)
Mathieu Chartier90443472015-07-16 20:32:27 -0700256 REQUIRES(!Locks::mutator_lock_, !Locks::thread_list_lock_, !Locks::trace_lock_)
257 // There is an annoying issue with static functions that create a new object and call into
258 // that object that causes them to not be able to tell that we don't currently hold the lock.
259 // This causes the negative annotations to incorrectly have a false positive. TODO: Figure out
260 // how to annotate this.
261 NO_THREAD_SAFETY_ANALYSIS;
Shukang Zhou8a5ab912017-01-20 11:40:16 -0800262 void FinishTracing()
263 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!*unique_methods_lock_, !*streaming_lock_);
jeffhao2692b572011-12-16 15:42:28 -0800264
Jeff Haoc1ff4b72013-08-19 11:33:10 -0700265 void ReadClocks(Thread* thread, uint32_t* thread_clock_diff, uint32_t* wall_clock_diff);
266
Mathieu Chartiere401d142015-04-22 13:56:20 -0700267 void LogMethodTraceEvent(Thread* thread, ArtMethod* method,
Jeff Haoc1ff4b72013-08-19 11:33:10 -0700268 instrumentation::Instrumentation::InstrumentationEvent event,
Andreas Gampe40da2862015-02-27 12:49:04 -0800269 uint32_t thread_clock_diff, uint32_t wall_clock_diff)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700270 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!*unique_methods_lock_, !*streaming_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800271
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800272 // Methods to output traced methods and threads.
Mathieu Chartier90443472015-07-16 20:32:27 -0700273 void GetVisitedMethods(size_t end_offset, std::set<ArtMethod*>* visited_methods)
274 REQUIRES(!*unique_methods_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700275 void DumpMethodList(std::ostream& os, const std::set<ArtMethod*>& visited_methods)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700276 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!*unique_methods_lock_);
Mathieu Chartier90443472015-07-16 20:32:27 -0700277 void DumpThreadList(std::ostream& os) REQUIRES(!Locks::thread_list_lock_);
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800278
Andreas Gampe40da2862015-02-27 12:49:04 -0800279 // Methods to register seen entitites in streaming mode. The methods return true if the entity
280 // is newly discovered.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700281 bool RegisterMethod(ArtMethod* method)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700282 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(streaming_lock_);
Andreas Gampe40da2862015-02-27 12:49:04 -0800283 bool RegisterThread(Thread* thread)
Mathieu Chartier90443472015-07-16 20:32:27 -0700284 REQUIRES(streaming_lock_);
Andreas Gampe40da2862015-02-27 12:49:04 -0800285
286 // Copy a temporary buffer to the main buffer. Used for streaming. Exposed here for lock
287 // annotation.
288 void WriteToBuf(const uint8_t* src, size_t src_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700289 REQUIRES(streaming_lock_);
Shukang Zhou8a5ab912017-01-20 11:40:16 -0800290 // Flush the main buffer to file. Used for streaming. Exposed here for lock annotation.
291 void FlushBuf()
292 REQUIRES(streaming_lock_);
Andreas Gampe40da2862015-02-27 12:49:04 -0800293
Mathieu Chartier90443472015-07-16 20:32:27 -0700294 uint32_t EncodeTraceMethod(ArtMethod* method) REQUIRES(!*unique_methods_lock_);
Mathieu Chartier4d64cd42015-06-02 16:38:29 -0700295 uint32_t EncodeTraceMethodAndAction(ArtMethod* method, TraceAction action)
Mathieu Chartier90443472015-07-16 20:32:27 -0700296 REQUIRES(!*unique_methods_lock_);
297 ArtMethod* DecodeTraceMethod(uint32_t tmid) REQUIRES(!*unique_methods_lock_);
298 std::string GetMethodLine(ArtMethod* method) REQUIRES(!*unique_methods_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700299 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier4d64cd42015-06-02 16:38:29 -0700300
301 void DumpBuf(uint8_t* buf, size_t buf_size, TraceClockSource clock_source)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700302 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!*unique_methods_lock_);
Mathieu Chartier4d64cd42015-06-02 16:38:29 -0700303
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700304 // Singleton instance of the Trace or null when no method tracing is active.
Jeff Hao0abc72e2013-08-13 13:45:14 -0700305 static Trace* volatile the_trace_ GUARDED_BY(Locks::trace_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800306
307 // The default profiler clock source.
Ian Rogerse63db272014-07-15 15:36:11 -0700308 static TraceClockSource default_clock_source_;
jeffhaoe343b762011-12-05 16:36:44 -0800309
Jeff Hao0abc72e2013-08-13 13:45:14 -0700310 // Sampling thread, non-zero when sampling.
311 static pthread_t sampling_pthread_;
312
Jeff Hao5ce4b172013-08-16 16:27:18 -0700313 // Used to remember an unused stack trace to avoid re-allocation during sampling.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700314 static std::unique_ptr<std::vector<ArtMethod*>> temp_stack_trace_;
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800315
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700316 // File to write trace data out to, null if direct to ddms.
Ian Rogers700a4022014-05-19 16:49:03 -0700317 std::unique_ptr<File> trace_file_;
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800318
jeffhao2692b572011-12-16 15:42:28 -0800319 // Buffer to store trace data.
Christopher Ferris241a9582015-04-27 15:19:41 -0700320 std::unique_ptr<uint8_t[]> buf_;
jeffhao2692b572011-12-16 15:42:28 -0800321
jeffhao0791adc2012-04-04 11:14:32 -0700322 // Flags enabling extra tracing of things such as alloc counts.
Ian Rogers62d6c772013-02-27 08:32:07 -0800323 const int flags_;
jeffhao0791adc2012-04-04 11:14:32 -0700324
Andreas Gampe40da2862015-02-27 12:49:04 -0800325 // The kind of output for this tracing.
326 const TraceOutputMode trace_output_mode_;
327
328 // The tracing method.
Andreas Gampe7e7e0f42015-03-29 15:26:23 -0700329 const TraceMode trace_mode_;
Jeff Hao23009dc2013-08-22 15:36:42 -0700330
Ian Rogerse63db272014-07-15 15:36:11 -0700331 const TraceClockSource clock_source_;
Elliott Hughescfbe73d2012-05-22 17:37:06 -0700332
Ian Rogers62d6c772013-02-27 08:32:07 -0800333 // Size of buf_.
Andreas Gampee34a42c2015-04-25 14:44:29 -0700334 const size_t buffer_size_;
jeffhao2692b572011-12-16 15:42:28 -0800335
Ian Rogers62d6c772013-02-27 08:32:07 -0800336 // Time trace was created.
337 const uint64_t start_time_;
338
Jeff Haoc5d824a2014-07-28 18:35:38 -0700339 // Clock overhead.
340 const uint32_t clock_overhead_ns_;
341
Ian Rogers62d6c772013-02-27 08:32:07 -0800342 // Offset into buf_.
Ian Rogers8ab25ef2014-07-09 18:00:50 -0700343 AtomicInteger cur_offset_;
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800344
Ian Rogers62d6c772013-02-27 08:32:07 -0800345 // Did we overflow the buffer recording traces?
346 bool overflow_;
347
Jeff Haoe094b872014-10-14 13:12:01 -0700348 // Map of thread ids and names that have already exited.
349 SafeMap<pid_t, std::string> exited_threads_;
350
Andreas Gampe40da2862015-02-27 12:49:04 -0800351 // Sampling profiler sampling interval.
352 int interval_us_;
353
354 // Streaming mode data.
Andreas Gampe40da2862015-02-27 12:49:04 -0800355 Mutex* streaming_lock_;
Andreas Gampe7526d782015-06-22 22:53:45 -0700356 std::map<const DexFile*, DexIndexBitSet*> seen_methods_;
Andreas Gampe40da2862015-02-27 12:49:04 -0800357 std::unique_ptr<ThreadIDBitSet> seen_threads_;
358
Mathieu Chartier4d64cd42015-06-02 16:38:29 -0700359 // Bijective map from ArtMethod* to index.
360 // Map from ArtMethod* to index in unique_methods_;
Andreas Gampe7526d782015-06-22 22:53:45 -0700361 Mutex* unique_methods_lock_ ACQUIRED_AFTER(streaming_lock_);
Mathieu Chartier4d64cd42015-06-02 16:38:29 -0700362 std::unordered_map<ArtMethod*, uint32_t> art_method_id_map_ GUARDED_BY(unique_methods_lock_);
363 std::vector<ArtMethod*> unique_methods_ GUARDED_BY(unique_methods_lock_);
364
jeffhaoe343b762011-12-05 16:36:44 -0800365 DISALLOW_COPY_AND_ASSIGN(Trace);
366};
367
368} // namespace art
369
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700370#endif // ART_RUNTIME_TRACE_H_