OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/zygote_host_linux.h" | 5 #include "content/browser/zygote_host_linux.h" |
6 | 6 |
7 #include <sys/socket.h> | 7 #include <sys/socket.h> |
8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
11 | 11 |
12 #include "base/base_switches.h" | 12 #include "base/base_switches.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/eintr_wrapper.h" | 14 #include "base/eintr_wrapper.h" |
15 #include "base/environment.h" | 15 #include "base/environment.h" |
16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
17 #include "base/linux_util.h" | 17 #include "base/linux_util.h" |
18 #include "base/logging.h" | 18 #include "base/logging.h" |
19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
| 20 #include "base/metrics/histogram.h" |
20 #include "base/path_service.h" | 21 #include "base/path_service.h" |
21 #include "base/pickle.h" | 22 #include "base/pickle.h" |
22 #include "base/process_util.h" | 23 #include "base/process_util.h" |
23 #include "base/string_number_conversions.h" | 24 #include "base/string_number_conversions.h" |
24 #include "base/string_util.h" | 25 #include "base/string_util.h" |
25 #include "base/time.h" | 26 #include "base/time.h" |
26 #include "base/utf_string_conversions.h" | 27 #include "base/utf_string_conversions.h" |
27 #include "content/browser/content_browser_client.h" | 28 #include "content/browser/content_browser_client.h" |
28 #include "content/browser/renderer_host/render_sandbox_host_linux.h" | 29 #include "content/browser/renderer_host/render_sandbox_host_linux.h" |
29 #include "content/common/process_watcher.h" | 30 #include "content/common/process_watcher.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 fds.push_back(i->second); | 261 fds.push_back(i->second); |
261 } | 262 } |
262 | 263 |
263 pid_t pid; | 264 pid_t pid; |
264 { | 265 { |
265 base::AutoLock lock(control_lock_); | 266 base::AutoLock lock(control_lock_); |
266 if (!UnixDomainSocket::SendMsg(control_fd_, pickle.data(), pickle.size(), | 267 if (!UnixDomainSocket::SendMsg(control_fd_, pickle.data(), pickle.size(), |
267 fds)) | 268 fds)) |
268 return base::kNullProcessHandle; | 269 return base::kNullProcessHandle; |
269 | 270 |
270 if (ReadReply(&pid, sizeof(pid)) != sizeof(pid)) | 271 // Read the reply, which pickles the PID and an optional UMA enumeration. |
| 272 static const unsigned kMaxReplyLength = 2048; |
| 273 char buf[kMaxReplyLength]; |
| 274 const ssize_t len = ReadReply(buf, sizeof(buf)); |
| 275 |
| 276 Pickle reply_pickle(buf, len); |
| 277 void *iter = NULL; |
| 278 if (len <= 0 || !reply_pickle.ReadInt(&iter, &pid)) |
271 return base::kNullProcessHandle; | 279 return base::kNullProcessHandle; |
| 280 |
| 281 // If there is a nonempty UMA name string, then there is a UMA |
| 282 // enumeration to record. |
| 283 std::string uma_name; |
| 284 int uma_sample; |
| 285 int uma_boundary_value; |
| 286 if (reply_pickle.ReadString(&iter, &uma_name) && |
| 287 !uma_name.empty() && |
| 288 reply_pickle.ReadInt(&iter, &uma_sample) && |
| 289 reply_pickle.ReadInt(&iter, &uma_boundary_value)) { |
| 290 // We cannot use the UMA_HISTOGRAM_ENUMERATION macro here, |
| 291 // because that's only for when the name is the same every time. |
| 292 // Here we're using whatever name we got from the other side. |
| 293 // But since it's likely that the same one will be used repeatedly |
| 294 // (even though it's not guaranteed), we cache it here. |
| 295 static base::Histogram* uma_histogram; |
| 296 if (!uma_histogram || uma_histogram->histogram_name() != uma_name) |
| 297 uma_histogram = base::LinearHistogram::FactoryGet( |
| 298 uma_name, 1, |
| 299 uma_boundary_value, |
| 300 uma_boundary_value + 1, base::Histogram::kUmaTargetedHistogramFlag); |
| 301 uma_histogram->Add(uma_sample); |
| 302 } |
| 303 |
272 if (pid <= 0) | 304 if (pid <= 0) |
273 return base::kNullProcessHandle; | 305 return base::kNullProcessHandle; |
274 } | 306 } |
275 | 307 |
276 // This is just a starting score for a renderer or extension (the | 308 // This is just a starting score for a renderer or extension (the |
277 // only types of processes that will be started this way). It will | 309 // only types of processes that will be started this way). It will |
278 // get adjusted as time goes on. (This is the same value as | 310 // get adjusted as time goes on. (This is the same value as |
279 // chrome::kLowestRendererOomScore in chrome/chrome_constants.h, but | 311 // chrome::kLowestRendererOomScore in chrome/chrome_constants.h, but |
280 // that's not something we can include here.) | 312 // that's not something we can include here.) |
281 const int kLowestRendererOomScore = 300; | 313 const int kLowestRendererOomScore = 300; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 !read_pickle.ReadInt(&iter, &tmp_exit_code)) { | 432 !read_pickle.ReadInt(&iter, &tmp_exit_code)) { |
401 LOG(WARNING) << "Error parsing GetTerminationStatus response from zygote."; | 433 LOG(WARNING) << "Error parsing GetTerminationStatus response from zygote."; |
402 return base::TERMINATION_STATUS_NORMAL_TERMINATION; | 434 return base::TERMINATION_STATUS_NORMAL_TERMINATION; |
403 } | 435 } |
404 | 436 |
405 if (exit_code) | 437 if (exit_code) |
406 *exit_code = tmp_exit_code; | 438 *exit_code = tmp_exit_code; |
407 | 439 |
408 return static_cast<base::TerminationStatus>(status); | 440 return static_cast<base::TerminationStatus>(status); |
409 } | 441 } |
OLD | NEW |