blob: 88efd41156b83bc97778c9f46b1787a864a79d3b [file] [log] [blame]
Calin Juravle4d77b6a2015-12-01 18:38:09 +00001/*
2 * Copyright (C) 2015 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_RUNTIME_JIT_PROFILE_SAVER_H_
18#define ART_RUNTIME_JIT_PROFILE_SAVER_H_
19
20#include "base/mutex.h"
21#include "jit_code_cache.h"
22#include "offline_profiling_info.h"
23
24namespace art {
25
26class ProfileSaver {
27 public:
28 // Starts the profile saver thread.
29 static void Start(const std::string& output_filename,
30 jit::JitCodeCache* jit_code_cache,
31 const std::vector<std::string>& code_paths)
32 REQUIRES(!Locks::profiler_lock_, !wait_lock_);
33
34 // Stops the profile saver thread.
35 // NO_THREAD_SAFETY_ANALYSIS for static function calling into member function with excludes lock.
36 static void Stop()
37 REQUIRES(!Locks::profiler_lock_, !wait_lock_)
38 NO_THREAD_SAFETY_ANALYSIS;
39
40 // Returns true if the profile saver is started.
41 static bool IsStarted() REQUIRES(!Locks::profiler_lock_);
42
43 private:
44 ProfileSaver(const std::string& output_filename,
45 jit::JitCodeCache* jit_code_cache,
46 const std::vector<std::string>& code_paths);
47
48 // NO_THREAD_SAFETY_ANALYSIS for static function calling into member function with excludes lock.
49 static void* RunProfileSaverThread(void* arg)
50 REQUIRES(!Locks::profiler_lock_, !wait_lock_)
51 NO_THREAD_SAFETY_ANALYSIS;
52
53 // The run loop for the saver.
54 void Run() REQUIRES(!Locks::profiler_lock_, !wait_lock_);
55 // Processes the existing profiling info from the jit code cache and returns
56 // true if it needed to be saved to disk.
57 bool ProcessProfilingInfo();
58 // Returns true if the saver is shutting down (ProfileSaver::Stop() has been called).
59 bool ShuttingDown(Thread* self) REQUIRES(!Locks::profiler_lock_);
60
61 // The only instance of the saver.
62 static ProfileSaver* instance_ GUARDED_BY(Locks::profiler_lock_);
63 // Profile saver thread.
64 static pthread_t profiler_pthread_ GUARDED_BY(Locks::profiler_lock_);
65
66 const std::string output_filename_;
67 jit::JitCodeCache* jit_code_cache_;
68 const std::set<const std::string> tracked_dex_base_locations_;
69 OfflineProfilingInfo offline_profiling_info_;
70 uint64_t code_cache_last_update_time_ns_;
71 bool shutting_down_ GUARDED_BY(Locks::profiler_lock_);
72
73 // Save period condition support.
74 Mutex wait_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
75 ConditionVariable period_condition_ GUARDED_BY(wait_lock_);
76
77 DISALLOW_COPY_AND_ASSIGN(ProfileSaver);
78};
79
80} // namespace art
81
82#endif // ART_RUNTIME_JIT_PROFILE_SAVER_H_