Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(555)

Side by Side Diff: ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc

Issue 356923002: Pepper: Move Pnacl init time out of trusted plugin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h" 5 #include "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "native_client/src/include/checked_cast.h" 10 #include "native_client/src/include/checked_cast.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 const nacl::string& pexe_url, 75 const nacl::string& pexe_url,
76 const PP_PNaClOptions& pnacl_options, 76 const PP_PNaClOptions& pnacl_options,
77 const pp::CompletionCallback& translate_notify_callback) { 77 const pp::CompletionCallback& translate_notify_callback) {
78 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (plugin=%p, pexe=%s)\n", 78 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (plugin=%p, pexe=%s)\n",
79 static_cast<void*>(plugin), pexe_url.c_str())); 79 static_cast<void*>(plugin), pexe_url.c_str()));
80 PnaclCoordinator* coordinator = 80 PnaclCoordinator* coordinator =
81 new PnaclCoordinator(plugin, pexe_url, 81 new PnaclCoordinator(plugin, pexe_url,
82 pnacl_options, 82 pnacl_options,
83 translate_notify_callback); 83 translate_notify_callback);
84 84
85 coordinator->pnacl_init_time_ = NaClGetTimeOfDayMicroseconds(); 85 GetNaClInterface()->SetPNaClStartTime(plugin->pp_instance());
86 int cpus = plugin->nacl_interface()->GetNumberOfProcessors(); 86 int cpus = plugin->nacl_interface()->GetNumberOfProcessors();
87 coordinator->split_module_count_ = std::min(4, std::max(1, cpus)); 87 coordinator->split_module_count_ = std::min(4, std::max(1, cpus));
88 88
89 // First start a network request for the pexe, to tickle the component 89 // First start a network request for the pexe, to tickle the component
90 // updater's On-Demand resource throttler, and to get Last-Modified/ETag 90 // updater's On-Demand resource throttler, and to get Last-Modified/ETag
91 // cache information. We can cancel the request later if there's 91 // cache information. We can cancel the request later if there's
92 // a bitcode->nexe cache hit. 92 // a bitcode->nexe cache hit.
93 coordinator->OpenBitcodeStream(); 93 coordinator->OpenBitcodeStream();
94 return coordinator; 94 return coordinator;
95 } 95 }
96 96
97 PnaclCoordinator::PnaclCoordinator( 97 PnaclCoordinator::PnaclCoordinator(
98 Plugin* plugin, 98 Plugin* plugin,
99 const nacl::string& pexe_url, 99 const nacl::string& pexe_url,
100 const PP_PNaClOptions& pnacl_options, 100 const PP_PNaClOptions& pnacl_options,
101 const pp::CompletionCallback& translate_notify_callback) 101 const pp::CompletionCallback& translate_notify_callback)
102 : translate_finish_error_(PP_OK), 102 : translate_finish_error_(PP_OK),
103 plugin_(plugin), 103 plugin_(plugin),
104 translate_notify_callback_(translate_notify_callback), 104 translate_notify_callback_(translate_notify_callback),
105 translation_finished_reported_(false), 105 translation_finished_reported_(false),
106 pexe_url_(pexe_url), 106 pexe_url_(pexe_url),
107 pnacl_options_(pnacl_options), 107 pnacl_options_(pnacl_options),
108 architecture_attributes_(GetArchitectureAttributes(plugin)), 108 architecture_attributes_(GetArchitectureAttributes(plugin)),
109 split_module_count_(1), 109 split_module_count_(1),
110 is_cache_hit_(PP_FALSE), 110 is_cache_hit_(PP_FALSE),
111 error_already_reported_(false), 111 error_already_reported_(false),
112 pnacl_init_time_(0),
113 pexe_size_(0), 112 pexe_size_(0),
114 pexe_bytes_compiled_(0), 113 pexe_bytes_compiled_(0),
115 expected_pexe_size_(-1) { 114 expected_pexe_size_(-1) {
116 PLUGIN_PRINTF(("PnaclCoordinator::PnaclCoordinator (this=%p, plugin=%p)\n", 115 PLUGIN_PRINTF(("PnaclCoordinator::PnaclCoordinator (this=%p, plugin=%p)\n",
117 static_cast<void*>(this), static_cast<void*>(plugin))); 116 static_cast<void*>(this), static_cast<void*>(plugin)));
118 callback_factory_.Initialize(this); 117 callback_factory_.Initialize(this);
119 } 118 }
120 119
121 PnaclCoordinator::~PnaclCoordinator() { 120 PnaclCoordinator::~PnaclCoordinator() {
122 PLUGIN_PRINTF(("PnaclCoordinator::~PnaclCoordinator (this=%p, " 121 PLUGIN_PRINTF(("PnaclCoordinator::~PnaclCoordinator (this=%p, "
123 "translate_thread=%p\n", 122 "translate_thread=%p\n",
124 static_cast<void*>(this), translate_thread_.get())); 123 static_cast<void*>(this), translate_thread_.get()));
125 // Stopping the translate thread will cause the translate thread to try to 124 // Stopping the translate thread will cause the translate thread to try to
126 // run translation_complete_callback_ on the main thread. This destructor is 125 // run translation_complete_callback_ on the main thread. This destructor is
127 // running from the main thread, and by the time it exits, callback_factory_ 126 // running from the main thread, and by the time it exits, callback_factory_
128 // will have been destroyed. This will result in the cancellation of 127 // will have been destroyed. This will result in the cancellation of
129 // translation_complete_callback_, so no notification will be delivered. 128 // translation_complete_callback_, so no notification will be delivered.
130 if (translate_thread_.get() != NULL) 129 if (translate_thread_.get() != NULL)
131 translate_thread_->AbortSubprocesses(); 130 translate_thread_->AbortSubprocesses();
132 if (!translation_finished_reported_) { 131 if (!translation_finished_reported_) {
133 plugin_->nacl_interface()->ReportTranslationFinished( 132 plugin_->nacl_interface()->ReportTranslationFinished(
134 plugin_->pp_instance(), 133 plugin_->pp_instance(),
135 PP_FALSE, 0, 0, 0, 0); 134 PP_FALSE, 0, 0, 0);
136 } 135 }
137 // Force deleting the translate_thread now. It must be deleted 136 // Force deleting the translate_thread now. It must be deleted
138 // before any scoped_* fields hanging off of PnaclCoordinator 137 // before any scoped_* fields hanging off of PnaclCoordinator
139 // since the thread may be accessing those fields. 138 // since the thread may be accessing those fields.
140 // It will also be accessing obj_files_. 139 // It will also be accessing obj_files_.
141 translate_thread_.reset(NULL); 140 translate_thread_.reset(NULL);
142 for (size_t i = 0; i < obj_files_.size(); i++) 141 for (size_t i = 0; i < obj_files_.size(); i++)
143 delete obj_files_[i]; 142 delete obj_files_[i];
144 } 143 }
145 144
(...skipping 28 matching lines...) Expand all
174 // to the various helper classes (e.g., pnacl_resources). Thus, those 173 // to the various helper classes (e.g., pnacl_resources). Thus, those
175 // callbacks may still run asynchronously. We let those run but ignore 174 // callbacks may still run asynchronously. We let those run but ignore
176 // any other errors they may generate so that they do not end up running 175 // any other errors they may generate so that they do not end up running
177 // translate_notify_callback_, which has already been freed. 176 // translate_notify_callback_, which has already been freed.
178 callback_factory_.CancelAll(); 177 callback_factory_.CancelAll();
179 if (!error_already_reported_) { 178 if (!error_already_reported_) {
180 error_already_reported_ = true; 179 error_already_reported_ = true;
181 translation_finished_reported_ = true; 180 translation_finished_reported_ = true;
182 plugin_->nacl_interface()->ReportTranslationFinished( 181 plugin_->nacl_interface()->ReportTranslationFinished(
183 plugin_->pp_instance(), 182 plugin_->pp_instance(),
184 PP_FALSE, 0, 0, 0, 0); 183 PP_FALSE, 0, 0, 0);
185 translate_notify_callback_.Run(PP_ERROR_FAILED); 184 translate_notify_callback_.Run(PP_ERROR_FAILED);
186 } else { 185 } else {
187 PLUGIN_PRINTF(("PnaclCoordinator::ExitWithError an earlier error was " 186 PLUGIN_PRINTF(("PnaclCoordinator::ExitWithError an earlier error was "
188 "already reported -- Skipping.\n")); 187 "already reported -- Skipping.\n"));
189 } 188 }
190 } 189 }
191 190
192 // Signal that Pnacl translation completed normally. 191 // Signal that Pnacl translation completed normally.
193 void PnaclCoordinator::TranslateFinished(int32_t pp_error) { 192 void PnaclCoordinator::TranslateFinished(int32_t pp_error) {
194 PLUGIN_PRINTF(("PnaclCoordinator::TranslateFinished (pp_error=%" 193 PLUGIN_PRINTF(("PnaclCoordinator::TranslateFinished (pp_error=%"
(...skipping 28 matching lines...) Expand all
223 HistogramSizeKB(plugin_->uma_interface(), 222 HistogramSizeKB(plugin_->uma_interface(),
224 "NaCl.Perf.Size.PNaClTranslatedNexe", 223 "NaCl.Perf.Size.PNaClTranslatedNexe",
225 static_cast<int64_t>(nexe_size / 1024)); 224 static_cast<int64_t>(nexe_size / 1024));
226 HistogramRatio(plugin_->uma_interface(), 225 HistogramRatio(plugin_->uma_interface(),
227 "NaCl.Perf.Size.PexeNexeSizePct", pexe_size_, nexe_size); 226 "NaCl.Perf.Size.PexeNexeSizePct", pexe_size_, nexe_size);
228 } 227 }
229 // The nexe is written to the temp_nexe_file_. We must Reset() the file 228 // The nexe is written to the temp_nexe_file_. We must Reset() the file
230 // pointer to be able to read it again from the beginning. 229 // pointer to be able to read it again from the beginning.
231 temp_nexe_file_->Reset(); 230 temp_nexe_file_->Reset();
232 231
233 int64_t total_time = NaClGetTimeOfDayMicroseconds() - pnacl_init_time_;
234 // Report to the browser that translation finished. The browser will take 232 // Report to the browser that translation finished. The browser will take
235 // care of storing the nexe in the cache. 233 // care of storing the nexe in the cache.
236 translation_finished_reported_ = true; 234 translation_finished_reported_ = true;
237 plugin_->nacl_interface()->ReportTranslationFinished( 235 plugin_->nacl_interface()->ReportTranslationFinished(
238 plugin_->pp_instance(), PP_TRUE, pnacl_options_.opt_level, 236 plugin_->pp_instance(), PP_TRUE, pnacl_options_.opt_level,
239 pexe_size_, translate_thread_->GetCompileTime(), total_time); 237 pexe_size_, translate_thread_->GetCompileTime());
240 238
241 NexeReadDidOpen(PP_OK); 239 NexeReadDidOpen(PP_OK);
242 } 240 }
243 241
244 void PnaclCoordinator::NexeReadDidOpen(int32_t pp_error) { 242 void PnaclCoordinator::NexeReadDidOpen(int32_t pp_error) {
245 PLUGIN_PRINTF(("PnaclCoordinator::NexeReadDidOpen (pp_error=%" 243 PLUGIN_PRINTF(("PnaclCoordinator::NexeReadDidOpen (pp_error=%"
246 NACL_PRId32 ")\n", pp_error)); 244 NACL_PRId32 ")\n", pp_error));
247 if (pp_error != PP_OK) { 245 if (pp_error != PP_OK) {
248 if (pp_error == PP_ERROR_FILENOTFOUND) { 246 if (pp_error == PP_ERROR_FILENOTFOUND) {
249 ReportPpapiError(PP_NACL_ERROR_PNACL_CACHE_FETCH_NOTFOUND, 247 ReportPpapiError(PP_NACL_ERROR_PNACL_CACHE_FETCH_NOTFOUND,
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 invalid_desc_wrapper_.get(), 514 invalid_desc_wrapper_.get(),
517 &error_info_, 515 &error_info_,
518 resources_.get(), 516 resources_.get(),
519 &pnacl_options_, 517 &pnacl_options_,
520 architecture_attributes_, 518 architecture_attributes_,
521 this, 519 this,
522 plugin_); 520 plugin_);
523 } 521 }
524 522
525 } // namespace plugin 523 } // namespace plugin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698