profile_saver.h revision 8913fc1a27df8cf3b37fd99e94d87f290591328e
1/* 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#include "safe_map.h" 24 25namespace art { 26 27class ProfileSaver { 28 public: 29 // 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. 31 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 63 void AddTrackedLocations(const std::string& output_filename, 64 const std::vector<std::string>& code_paths) 65 REQUIRES(Locks::profiler_lock_); 66 67 // 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 72 jit::JitCodeCache* jit_code_cache_; 73 SafeMap<std::string, std::set<std::string>> tracked_dex_base_locations_ 74 GUARDED_BY(Locks::profiler_lock_); 75 uint64_t code_cache_last_update_time_ns_; 76 bool shutting_down_ GUARDED_BY(Locks::profiler_lock_); 77 bool first_profile_ = true; 78 79 // Save period condition support. 80 Mutex wait_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; 81 ConditionVariable period_condition_ GUARDED_BY(wait_lock_); 82 83 DISALLOW_COPY_AND_ASSIGN(ProfileSaver); 84}; 85 86} // namespace art 87 88#endif // ART_RUNTIME_JIT_PROFILE_SAVER_H_ 89