blob: 3d3f3dd0bf8b370733e4076da650162f60df3be2 [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#include "profile_saver.h"
18
Calin Juravle86a9ebe2016-02-24 10:13:09 +000019#include <sys/types.h>
20#include <sys/stat.h>
21#include <fcntl.h>
22
Calin Juravle4d77b6a2015-12-01 18:38:09 +000023#include "art_method-inl.h"
Mathieu Chartierdabdc0f2016-03-04 14:58:03 -080024#include "base/systrace.h"
Calin Juravle4d77b6a2015-12-01 18:38:09 +000025#include "scoped_thread_state_change.h"
26#include "oat_file_manager.h"
27
28namespace art {
29
Calin Juravle932a0512016-01-19 14:32:26 -080030// An arbitrary value to throttle save requests. Set to 2s for now.
Calin Juravle4d77b6a2015-12-01 18:38:09 +000031static constexpr const uint64_t kMilisecondsToNano = 1000000;
Calin Juravle932a0512016-01-19 14:32:26 -080032static constexpr const uint64_t kMinimumTimeBetweenCodeCacheUpdatesNs = 2000 * kMilisecondsToNano;
Calin Juravle4d77b6a2015-12-01 18:38:09 +000033
34// TODO: read the constants from ProfileOptions,
35// Add a random delay each time we go to sleep so that we don't hammer the CPU
36// with all profile savers running at the same time.
Calin Juravle815759a2016-03-14 17:32:49 +000037static constexpr const uint64_t kRandomDelayMaxMs = 40 * 1000; // 40 seconds
Calin Juravle932a0512016-01-19 14:32:26 -080038static constexpr const uint64_t kMaxBackoffMs = 5 * 60 * 1000; // 5 minutes
Calin Juravle815759a2016-03-14 17:32:49 +000039static constexpr const uint64_t kSavePeriodMs = 40 * 1000; // 40 seconds
Calin Juravlec15e5662016-03-17 17:07:52 +000040static constexpr const uint64_t kSaveResolvedClassesDelayMs = 2 * 1000; // 2 seconds
Calin Juravle4d77b6a2015-12-01 18:38:09 +000041static constexpr const double kBackoffCoef = 1.5;
42
43static constexpr const uint32_t kMinimumNrOrMethodsToSave = 10;
44
45ProfileSaver* ProfileSaver::instance_ = nullptr;
46pthread_t ProfileSaver::profiler_pthread_ = 0U;
47
48ProfileSaver::ProfileSaver(const std::string& output_filename,
49 jit::JitCodeCache* jit_code_cache,
Calin Juravle86a9ebe2016-02-24 10:13:09 +000050 const std::vector<std::string>& code_paths,
51 const std::string& foreign_dex_profile_path,
52 const std::string& app_data_dir)
Calin Juravleb4eddd22016-01-13 15:52:33 -080053 : jit_code_cache_(jit_code_cache),
Calin Juravle86a9ebe2016-02-24 10:13:09 +000054 foreign_dex_profile_path_(foreign_dex_profile_path),
Calin Juravle4d77b6a2015-12-01 18:38:09 +000055 code_cache_last_update_time_ns_(0),
56 shutting_down_(false),
57 wait_lock_("ProfileSaver wait lock"),
Calin Juravlec19c1c22016-03-09 15:37:48 +000058 period_condition_("ProfileSaver period condition", wait_lock_),
59 total_bytes_written_(0),
60 total_number_of_writes_(0),
61 total_number_of_code_cache_queries_(0),
62 total_number_of_skipped_writes_(0),
63 total_number_of_failed_writes_(0),
64 total_ns_of_sleep_(0),
65 total_ns_of_work_(0),
66 total_number_of_foreign_dex_marks_(0) {
Calin Juravleb4eddd22016-01-13 15:52:33 -080067 AddTrackedLocations(output_filename, code_paths);
Calin Juravlec15e5662016-03-17 17:07:52 +000068 // We only need to save the resolved classes if the profile file is empty.
69 // Otherwise we must have already save them (we always do it during the first
70 // ever profile save).
71 // TODO(calin) This only considers the case of the primary profile file.
72 // Anything that gets loaded in the same VM will not have their resolved
73 // classes save (unless they started before the initial saving was done).
74 save_resolved_classes_ = !FileExistsAndNotEmpty(output_filename);
Calin Juravle86a9ebe2016-02-24 10:13:09 +000075 app_data_dir_ = "";
76 if (!app_data_dir.empty()) {
77 // The application directory is used to determine which dex files are owned by app.
78 // Since it could be a symlink (e.g. /data/data instead of /data/user/0), and we
79 // don't have control over how the dex files are actually loaded (symlink or canonical path),
80 // store it's canonical form to be sure we use the same base when comparing.
81 UniqueCPtr<const char[]> app_data_dir_real_path(realpath(app_data_dir.c_str(), nullptr));
82 if (app_data_dir_real_path != nullptr) {
83 app_data_dir_.assign(app_data_dir_real_path.get());
84 } else {
85 LOG(WARNING) << "Failed to get the real path for app dir: " << app_data_dir_
86 << ". The app dir will not be used to determine which dex files belong to the app";
87 }
88 }
Calin Juravle4d77b6a2015-12-01 18:38:09 +000089}
90
91void ProfileSaver::Run() {
92 srand(MicroTime() * getpid());
93 Thread* self = Thread::Current();
94
95 uint64_t save_period_ms = kSavePeriodMs;
96 VLOG(profiler) << "Save profiling information every " << save_period_ms << " ms";
Mathieu Chartier8913fc12015-12-09 16:38:30 -080097 while (!ShuttingDown(self)) {
98 uint64_t sleep_time_ms;
Calin Juravlec15e5662016-03-17 17:07:52 +000099 if (save_resolved_classes_) {
Mathieu Chartier8913fc12015-12-09 16:38:30 -0800100 // Sleep less long for the first iteration since we want to record loaded classes shortly
101 // after app launch.
Calin Juravlec15e5662016-03-17 17:07:52 +0000102 sleep_time_ms = kSaveResolvedClassesDelayMs;
Mathieu Chartier8913fc12015-12-09 16:38:30 -0800103 } else {
104 const uint64_t random_sleep_delay_ms = rand() % kRandomDelayMaxMs;
105 sleep_time_ms = save_period_ms + random_sleep_delay_ms;
106 }
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000107 {
108 MutexLock mu(self, wait_lock_);
109 period_condition_.TimedWait(self, sleep_time_ms, 0);
110 }
Calin Juravlec19c1c22016-03-09 15:37:48 +0000111 total_ns_of_sleep_ += sleep_time_ms;
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000112 if (ShuttingDown(self)) {
113 break;
114 }
115
Calin Juravlec19c1c22016-03-09 15:37:48 +0000116 uint64_t start = NanoTime();
117
Calin Juravlec15e5662016-03-17 17:07:52 +0000118 if (!ProcessProfilingInfo(save_resolved_classes_) && save_period_ms < kMaxBackoffMs) {
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000119 // If we don't need to save now it is less likely that we will need to do
120 // so in the future. Increase the time between saves according to the
121 // kBackoffCoef, but make it no larger than kMaxBackoffMs.
122 save_period_ms = static_cast<uint64_t>(kBackoffCoef * save_period_ms);
123 } else {
124 // Reset the period to the initial value as it's highly likely to JIT again.
125 save_period_ms = kSavePeriodMs;
126 }
Calin Juravlec15e5662016-03-17 17:07:52 +0000127 save_resolved_classes_ = false;
Calin Juravlec19c1c22016-03-09 15:37:48 +0000128
129 total_ns_of_work_ += (NanoTime() - start);
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000130 }
131}
132
Calin Juravlec15e5662016-03-17 17:07:52 +0000133bool ProfileSaver::ProcessProfilingInfo(bool save_resolved_classes) {
Mathieu Chartierdabdc0f2016-03-04 14:58:03 -0800134 ScopedTrace trace(__PRETTY_FUNCTION__);
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000135 uint64_t last_update_time_ns = jit_code_cache_->GetLastUpdateTimeNs();
Calin Juravlec15e5662016-03-17 17:07:52 +0000136 if (!save_resolved_classes && last_update_time_ns - code_cache_last_update_time_ns_
Mathieu Chartier8913fc12015-12-09 16:38:30 -0800137 < kMinimumTimeBetweenCodeCacheUpdatesNs) {
Calin Juravle877fd962016-01-05 14:29:29 +0000138 VLOG(profiler) << "Not enough time has passed since the last code cache update."
139 << "Last update: " << last_update_time_ns
140 << " Last save: " << code_cache_last_update_time_ns_;
Calin Juravlec19c1c22016-03-09 15:37:48 +0000141 total_number_of_skipped_writes_++;
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000142 return false;
143 }
144
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000145 code_cache_last_update_time_ns_ = last_update_time_ns;
Calin Juravleb4eddd22016-01-13 15:52:33 -0800146 SafeMap<std::string, std::set<std::string>> tracked_locations;
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000147 {
Calin Juravleb4eddd22016-01-13 15:52:33 -0800148 // Make a copy so that we don't hold the lock while doing I/O.
149 MutexLock mu(Thread::Current(), *Locks::profiler_lock_);
150 tracked_locations = tracked_dex_base_locations_;
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000151 }
Calin Juravlec15e5662016-03-17 17:07:52 +0000152
153 std::set<DexCacheResolvedClasses> resolved_classes;
154 if (save_resolved_classes) {
155 ClassLinker* const class_linker = Runtime::Current()->GetClassLinker();
156 resolved_classes = class_linker->GetResolvedClasses(/*ignore boot classes*/true);
157 }
Calin Juravleb4eddd22016-01-13 15:52:33 -0800158 for (const auto& it : tracked_locations) {
159 if (ShuttingDown(Thread::Current())) {
160 return true;
161 }
162 const std::string& filename = it.first;
163 const std::set<std::string>& locations = it.second;
164 std::vector<ArtMethod*> methods;
165 {
166 ScopedObjectAccess soa(Thread::Current());
167 jit_code_cache_->GetCompiledArtMethods(locations, methods);
Calin Juravlec19c1c22016-03-09 15:37:48 +0000168 total_number_of_code_cache_queries_++;
Calin Juravleb4eddd22016-01-13 15:52:33 -0800169 }
Calin Juravlec15e5662016-03-17 17:07:52 +0000170
171 std::set<DexCacheResolvedClasses> resolved_classes_for_location;
172 if (save_resolved_classes) {
173 bool resolved_classes_already_in_file = FileExistsAndNotEmpty(filename);
174 if (!resolved_classes_already_in_file) {
175 for (const DexCacheResolvedClasses& classes : resolved_classes) {
176 if (locations.find(classes.GetDexLocation()) != locations.end()) {
177 resolved_classes_for_location.insert(classes);
178 }
179 }
180 }
181 }
Mathieu Chartier8913fc12015-12-09 16:38:30 -0800182 // Always save for the first one for loaded classes profile.
Calin Juravlec15e5662016-03-17 17:07:52 +0000183 if (methods.size() < kMinimumNrOrMethodsToSave && !save_resolved_classes) {
Calin Juravleb4eddd22016-01-13 15:52:33 -0800184 VLOG(profiler) << "Not enough information to save to: " << filename
185 <<" Nr of methods: " << methods.size();
Calin Juravlec19c1c22016-03-09 15:37:48 +0000186 total_number_of_skipped_writes_++;
Calin Juravleb4eddd22016-01-13 15:52:33 -0800187 return false;
188 }
Calin Juravlec19c1c22016-03-09 15:37:48 +0000189 uint64_t bytes_written;
Calin Juravlec15e5662016-03-17 17:07:52 +0000190 if (!ProfileCompilationInfo::SaveProfilingInfo(
191 filename,
192 methods,
193 resolved_classes_for_location,
194 &bytes_written)) {
Calin Juravleb4eddd22016-01-13 15:52:33 -0800195 LOG(WARNING) << "Could not save profiling info to " << filename;
Calin Juravlec19c1c22016-03-09 15:37:48 +0000196 total_number_of_failed_writes_++;
Calin Juravleb4eddd22016-01-13 15:52:33 -0800197 return false;
Calin Juravlec19c1c22016-03-09 15:37:48 +0000198 } else {
199 if (bytes_written > 0) {
200 total_number_of_writes_++;
201 total_bytes_written_ += bytes_written;
202 }
Calin Juravleb4eddd22016-01-13 15:52:33 -0800203 }
Calin Juravleb4eddd22016-01-13 15:52:33 -0800204 }
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000205 return true;
206}
207
208void* ProfileSaver::RunProfileSaverThread(void* arg) {
209 Runtime* runtime = Runtime::Current();
210 ProfileSaver* profile_saver = reinterpret_cast<ProfileSaver*>(arg);
211
212 CHECK(runtime->AttachCurrentThread("Profile Saver",
213 /*as_daemon*/true,
214 runtime->GetSystemThreadGroup(),
215 /*create_peer*/true));
216 profile_saver->Run();
217
218 runtime->DetachCurrentThread();
219 VLOG(profiler) << "Profile saver shutdown";
220 return nullptr;
221}
222
223void ProfileSaver::Start(const std::string& output_filename,
224 jit::JitCodeCache* jit_code_cache,
Calin Juravle86a9ebe2016-02-24 10:13:09 +0000225 const std::vector<std::string>& code_paths,
226 const std::string& foreign_dex_profile_path,
227 const std::string& app_data_dir) {
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000228 DCHECK(Runtime::Current()->UseJit());
229 DCHECK(!output_filename.empty());
230 DCHECK(jit_code_cache != nullptr);
231
232 MutexLock mu(Thread::Current(), *Locks::profiler_lock_);
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000233 if (instance_ != nullptr) {
Calin Juravleb4eddd22016-01-13 15:52:33 -0800234 // If we already have an instance, make sure it uses the same jit_code_cache.
235 // This may be called multiple times via Runtime::registerAppInfo (e.g. for
236 // apps which share the same runtime).
237 DCHECK_EQ(instance_->jit_code_cache_, jit_code_cache);
238 // Add the code_paths to the tracked locations.
239 instance_->AddTrackedLocations(output_filename, code_paths);
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000240 return;
241 }
242
243 VLOG(profiler) << "Starting profile saver using output file: " << output_filename
244 << ". Tracking: " << Join(code_paths, ':');
245
Calin Juravle86a9ebe2016-02-24 10:13:09 +0000246 instance_ = new ProfileSaver(output_filename,
247 jit_code_cache,
248 code_paths,
249 foreign_dex_profile_path,
250 app_data_dir);
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000251
252 // Create a new thread which does the saving.
253 CHECK_PTHREAD_CALL(
254 pthread_create,
255 (&profiler_pthread_, nullptr, &RunProfileSaverThread, reinterpret_cast<void*>(instance_)),
256 "Profile saver thread");
257}
258
Calin Juravlec19c1c22016-03-09 15:37:48 +0000259void ProfileSaver::Stop(bool dump_info) {
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000260 ProfileSaver* profile_saver = nullptr;
261 pthread_t profiler_pthread = 0U;
262
263 {
264 MutexLock profiler_mutex(Thread::Current(), *Locks::profiler_lock_);
Calin Juravleb4eddd22016-01-13 15:52:33 -0800265 VLOG(profiler) << "Stopping profile saver thread";
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000266 profile_saver = instance_;
267 profiler_pthread = profiler_pthread_;
268 if (instance_ == nullptr) {
269 DCHECK(false) << "Tried to stop a profile saver which was not started";
270 return;
271 }
272 if (instance_->shutting_down_) {
273 DCHECK(false) << "Tried to stop the profile saver twice";
274 return;
275 }
276 instance_->shutting_down_ = true;
Calin Juravlec19c1c22016-03-09 15:37:48 +0000277 if (dump_info) {
278 instance_->DumpInfo(LOG(INFO));
279 }
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000280 }
281
282 {
283 // Wake up the saver thread if it is sleeping to allow for a clean exit.
284 MutexLock wait_mutex(Thread::Current(), profile_saver->wait_lock_);
285 profile_saver->period_condition_.Signal(Thread::Current());
286 }
287
288 // Wait for the saver thread to stop.
289 CHECK_PTHREAD_CALL(pthread_join, (profiler_pthread, nullptr), "profile saver thread shutdown");
290
291 {
292 MutexLock profiler_mutex(Thread::Current(), *Locks::profiler_lock_);
293 instance_ = nullptr;
294 profiler_pthread_ = 0U;
295 }
296 delete profile_saver;
297}
298
299bool ProfileSaver::ShuttingDown(Thread* self) {
300 MutexLock mu(self, *Locks::profiler_lock_);
301 return shutting_down_;
302}
303
304bool ProfileSaver::IsStarted() {
305 MutexLock mu(Thread::Current(), *Locks::profiler_lock_);
306 return instance_ != nullptr;
307}
308
Calin Juravleb4eddd22016-01-13 15:52:33 -0800309void ProfileSaver::AddTrackedLocations(const std::string& output_filename,
310 const std::vector<std::string>& code_paths) {
311 auto it = tracked_dex_base_locations_.find(output_filename);
312 if (it == tracked_dex_base_locations_.end()) {
313 tracked_dex_base_locations_.Put(output_filename,
314 std::set<std::string>(code_paths.begin(), code_paths.end()));
315 } else {
316 it->second.insert(code_paths.begin(), code_paths.end());
317 }
318}
319
Calin Juravle86a9ebe2016-02-24 10:13:09 +0000320void ProfileSaver::NotifyDexUse(const std::string& dex_location) {
321 std::set<std::string> app_code_paths;
322 std::string foreign_dex_profile_path;
323 std::string app_data_dir;
324 {
325 MutexLock mu(Thread::Current(), *Locks::profiler_lock_);
Calin Juravlec19c1c22016-03-09 15:37:48 +0000326 if (instance_ == nullptr) {
327 return;
328 }
Calin Juravle86a9ebe2016-02-24 10:13:09 +0000329 // Make a copy so that we don't hold the lock while doing I/O.
330 for (const auto& it : instance_->tracked_dex_base_locations_) {
331 app_code_paths.insert(it.second.begin(), it.second.end());
332 }
333 foreign_dex_profile_path = instance_->foreign_dex_profile_path_;
334 app_data_dir = instance_->app_data_dir_;
335 }
336
Calin Juravlec19c1c22016-03-09 15:37:48 +0000337 bool mark_created = MaybeRecordDexUseInternal(dex_location,
338 app_code_paths,
339 foreign_dex_profile_path,
340 app_data_dir);
341 if (mark_created) {
342 MutexLock mu(Thread::Current(), *Locks::profiler_lock_);
343 if (instance_ != nullptr) {
344 instance_->total_number_of_foreign_dex_marks_++;
345 }
346 }
Calin Juravle86a9ebe2016-02-24 10:13:09 +0000347}
348
Calin Juravlec19c1c22016-03-09 15:37:48 +0000349bool ProfileSaver::MaybeRecordDexUseInternal(
Calin Juravle86a9ebe2016-02-24 10:13:09 +0000350 const std::string& dex_location,
351 const std::set<std::string>& app_code_paths,
352 const std::string& foreign_dex_profile_path,
353 const std::string& app_data_dir) {
Calin Juravle1fae45f2016-03-08 12:52:52 +0000354 if (dex_location.empty()) {
355 LOG(WARNING) << "Asked to record foreign dex use with an empty dex location.";
Calin Juravlec19c1c22016-03-09 15:37:48 +0000356 return false;
Calin Juravle1fae45f2016-03-08 12:52:52 +0000357 }
Calin Juravle86a9ebe2016-02-24 10:13:09 +0000358 if (foreign_dex_profile_path.empty()) {
359 LOG(WARNING) << "Asked to record foreign dex use without a valid profile path ";
Calin Juravlec19c1c22016-03-09 15:37:48 +0000360 return false;
Calin Juravle86a9ebe2016-02-24 10:13:09 +0000361 }
362
363 UniqueCPtr<const char[]> dex_location_real_path(realpath(dex_location.c_str(), nullptr));
Calin Juravle1fae45f2016-03-08 12:52:52 +0000364 if (dex_location_real_path == nullptr) {
365 PLOG(WARNING) << "Could not get realpath for " << dex_location;
366 }
367 std::string dex_location_real_path_str((dex_location_real_path == nullptr)
368 ? dex_location.c_str()
369 : dex_location_real_path.get());
Calin Juravle86a9ebe2016-02-24 10:13:09 +0000370
371 if (dex_location_real_path_str.compare(0, app_data_dir.length(), app_data_dir) == 0) {
372 // The dex location is under the application folder. Nothing to record.
Calin Juravlec19c1c22016-03-09 15:37:48 +0000373 return false;
Calin Juravle86a9ebe2016-02-24 10:13:09 +0000374 }
375
376 if (app_code_paths.find(dex_location) != app_code_paths.end()) {
377 // The dex location belongs to the application code paths. Nothing to record.
Calin Juravlec19c1c22016-03-09 15:37:48 +0000378 return false;
Calin Juravle86a9ebe2016-02-24 10:13:09 +0000379 }
380 // Do another round of checks with the real paths.
381 // Note that we could cache all the real locations in the saver (since it's an expensive
382 // operation). However we expect that app_code_paths is small (usually 1 element), and
383 // NotifyDexUse is called just a few times in the app lifetime. So we make the compromise
384 // to save some bytes of memory usage.
385 for (const auto& app_code_location : app_code_paths) {
386 UniqueCPtr<const char[]> real_app_code_location(realpath(app_code_location.c_str(), nullptr));
Calin Juravle1fae45f2016-03-08 12:52:52 +0000387 if (real_app_code_location == nullptr) {
388 PLOG(WARNING) << "Could not get realpath for " << app_code_location;
389 }
390 std::string real_app_code_location_str((real_app_code_location == nullptr)
391 ? app_code_location.c_str()
392 : real_app_code_location.get());
Calin Juravle86a9ebe2016-02-24 10:13:09 +0000393 if (real_app_code_location_str == dex_location_real_path_str) {
394 // The dex location belongs to the application code paths. Nothing to record.
Calin Juravlec19c1c22016-03-09 15:37:48 +0000395 return false;
Calin Juravle86a9ebe2016-02-24 10:13:09 +0000396 }
397 }
398
399 // For foreign dex files we record a flag on disk. PackageManager will (potentially) take this
400 // into account when deciding how to optimize the loaded dex file.
401 // The expected flag name is the canonical path of the apk where '/' is substituted to '@'.
402 // (it needs to be kept in sync with
403 // frameworks/base/services/core/java/com/android/server/pm/PackageDexOptimizer.java)
404 std::replace(dex_location_real_path_str.begin(), dex_location_real_path_str.end(), '/', '@');
405 std::string flag_path = foreign_dex_profile_path + "/" + dex_location_real_path_str;
406 // No need to give any sort of access to flag_path. The system has enough permissions
407 // to test for its existence.
408 int fd = TEMP_FAILURE_RETRY(open(flag_path.c_str(), O_CREAT | O_EXCL, 0));
409 if (fd != -1) {
410 if (close(fd) != 0) {
411 PLOG(WARNING) << "Could not close file after flagging foreign dex use " << flag_path;
412 }
Calin Juravlec19c1c22016-03-09 15:37:48 +0000413 return true;
Calin Juravle86a9ebe2016-02-24 10:13:09 +0000414 } else {
415 if (errno != EEXIST) {
416 // Another app could have already created the file.
417 PLOG(WARNING) << "Could not create foreign dex use mark " << flag_path;
Calin Juravlec19c1c22016-03-09 15:37:48 +0000418 return false;
Calin Juravle86a9ebe2016-02-24 10:13:09 +0000419 }
Calin Juravlec19c1c22016-03-09 15:37:48 +0000420 return true;
Calin Juravle86a9ebe2016-02-24 10:13:09 +0000421 }
422}
423
Calin Juravlec19c1c22016-03-09 15:37:48 +0000424void ProfileSaver::DumpInstanceInfo(std::ostream& os) {
425 MutexLock mu(Thread::Current(), *Locks::profiler_lock_);
426 if (instance_ != nullptr) {
427 instance_->DumpInfo(os);
428 }
429}
430
431void ProfileSaver::DumpInfo(std::ostream& os) {
432 os << "ProfileSaver total_bytes_written=" << total_bytes_written_ << '\n'
433 << "ProfileSaver total_number_of_writes=" << total_number_of_writes_ << '\n'
434 << "ProfileSaver total_number_of_code_cache_queries=" << total_number_of_code_cache_queries_ << '\n'
435 << "ProfileSaver total_number_of_skipped_writes=" << total_number_of_skipped_writes_ << '\n'
436 << "ProfileSaver total_number_of_failed_writes=" << total_number_of_failed_writes_ << '\n'
437 << "ProfileSaver total_ms_of_sleep=" << (total_ns_of_sleep_ / kMilisecondsToNano) << '\n'
438 << "ProfileSaver total_ms_of_work=" << (total_ns_of_work_ / kMilisecondsToNano) << '\n'
439 << "ProfileSaver total_number_of_foreign_dex_marks=" << total_number_of_foreign_dex_marks_ << '\n';
440}
441
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000442} // namespace art