blob: 3342790e4391e5e62c927b03591bfa7bb595633f [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"
Calin Juravleb4eddd22016-01-13 15:52:33 -080023#include "safe_map.h"
Calin Juravle4d77b6a2015-12-01 18:38:09 +000024
25namespace art {
26
27class ProfileSaver {
28 public:
Calin Juravleb4eddd22016-01-13 15:52:33 -080029 // Starts the profile saver thread if not already started.
30 // If the saver is already running it adds (output_filename, code_paths) to its tracked locations.
Calin Juravle4d77b6a2015-12-01 18:38:09 +000031 static void Start(const std::string& output_filename,
32 jit::JitCodeCache* jit_code_cache,
33 const std::vector<std::string>& code_paths)
34 REQUIRES(!Locks::profiler_lock_, !wait_lock_);
35
36 // Stops the profile saver thread.
37 // NO_THREAD_SAFETY_ANALYSIS for static function calling into member function with excludes lock.
38 static void Stop()
39 REQUIRES(!Locks::profiler_lock_, !wait_lock_)
40 NO_THREAD_SAFETY_ANALYSIS;
41
42 // Returns true if the profile saver is started.
43 static bool IsStarted() REQUIRES(!Locks::profiler_lock_);
44
45 private:
46 ProfileSaver(const std::string& output_filename,
47 jit::JitCodeCache* jit_code_cache,
48 const std::vector<std::string>& code_paths);
49
50 // NO_THREAD_SAFETY_ANALYSIS for static function calling into member function with excludes lock.
51 static void* RunProfileSaverThread(void* arg)
52 REQUIRES(!Locks::profiler_lock_, !wait_lock_)
53 NO_THREAD_SAFETY_ANALYSIS;
54
55 // The run loop for the saver.
56 void Run() REQUIRES(!Locks::profiler_lock_, !wait_lock_);
57 // Processes the existing profiling info from the jit code cache and returns
58 // true if it needed to be saved to disk.
59 bool ProcessProfilingInfo();
60 // Returns true if the saver is shutting down (ProfileSaver::Stop() has been called).
61 bool ShuttingDown(Thread* self) REQUIRES(!Locks::profiler_lock_);
62
Calin Juravleb4eddd22016-01-13 15:52:33 -080063 void AddTrackedLocations(const std::string& output_filename,
64 const std::vector<std::string>& code_paths)
65 REQUIRES(Locks::profiler_lock_);
66
Calin Juravle4d77b6a2015-12-01 18:38:09 +000067 // The only instance of the saver.
68 static ProfileSaver* instance_ GUARDED_BY(Locks::profiler_lock_);
69 // Profile saver thread.
70 static pthread_t profiler_pthread_ GUARDED_BY(Locks::profiler_lock_);
71
Calin Juravle4d77b6a2015-12-01 18:38:09 +000072 jit::JitCodeCache* jit_code_cache_;
Calin Juravleb4eddd22016-01-13 15:52:33 -080073 SafeMap<std::string, std::set<std::string>> tracked_dex_base_locations_
74 GUARDED_BY(Locks::profiler_lock_);
Calin Juravle4d77b6a2015-12-01 18:38:09 +000075 uint64_t code_cache_last_update_time_ns_;
76 bool shutting_down_ GUARDED_BY(Locks::profiler_lock_);
77
78 // Save period condition support.
79 Mutex wait_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
80 ConditionVariable period_condition_ GUARDED_BY(wait_lock_);
81
82 DISALLOW_COPY_AND_ASSIGN(ProfileSaver);
83};
84
85} // namespace art
86
87#endif // ART_RUNTIME_JIT_PROFILE_SAVER_H_