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

Side by Side Diff: base/process_util.h

Issue 6736019: Base: A few more files using BASE_API (for base.dll) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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
« no previous file with comments | « base/process.h ('k') | base/scoped_native_library.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // This file/namespace contains utility functions for enumerating, ending and 5 // This file/namespace contains utility functions for enumerating, ending and
6 // computing statistics of processes. 6 // computing statistics of processes.
7 7
8 #ifndef BASE_PROCESS_UTIL_H_ 8 #ifndef BASE_PROCESS_UTIL_H_
9 #define BASE_PROCESS_UTIL_H_ 9 #define BASE_PROCESS_UTIL_H_
10 #pragma once 10 #pragma once
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // specific values instead. 124 // specific values instead.
125 enum TerminationStatus { 125 enum TerminationStatus {
126 TERMINATION_STATUS_NORMAL_TERMINATION, // zero exit status 126 TERMINATION_STATUS_NORMAL_TERMINATION, // zero exit status
127 TERMINATION_STATUS_ABNORMAL_TERMINATION, // non-zero exit status 127 TERMINATION_STATUS_ABNORMAL_TERMINATION, // non-zero exit status
128 TERMINATION_STATUS_PROCESS_WAS_KILLED, // e.g. SIGKILL or task manager kill 128 TERMINATION_STATUS_PROCESS_WAS_KILLED, // e.g. SIGKILL or task manager kill
129 TERMINATION_STATUS_PROCESS_CRASHED, // e.g. Segmentation fault 129 TERMINATION_STATUS_PROCESS_CRASHED, // e.g. Segmentation fault
130 TERMINATION_STATUS_STILL_RUNNING // child hasn't exited yet 130 TERMINATION_STATUS_STILL_RUNNING // child hasn't exited yet
131 }; 131 };
132 132
133 // Returns the id of the current process. 133 // Returns the id of the current process.
134 ProcessId GetCurrentProcId(); 134 BASE_API ProcessId GetCurrentProcId();
135 135
136 // Returns the ProcessHandle of the current process. 136 // Returns the ProcessHandle of the current process.
137 ProcessHandle GetCurrentProcessHandle(); 137 BASE_API ProcessHandle GetCurrentProcessHandle();
138 138
139 // Converts a PID to a process handle. This handle must be closed by 139 // Converts a PID to a process handle. This handle must be closed by
140 // CloseProcessHandle when you are done with it. Returns true on success. 140 // CloseProcessHandle when you are done with it. Returns true on success.
141 bool OpenProcessHandle(ProcessId pid, ProcessHandle* handle); 141 BASE_API bool OpenProcessHandle(ProcessId pid, ProcessHandle* handle);
142 142
143 // Converts a PID to a process handle. On Windows the handle is opened 143 // Converts a PID to a process handle. On Windows the handle is opened
144 // with more access rights and must only be used by trusted code. 144 // with more access rights and must only be used by trusted code.
145 // You have to close returned handle using CloseProcessHandle. Returns true 145 // You have to close returned handle using CloseProcessHandle. Returns true
146 // on success. 146 // on success.
147 // TODO(sanjeevr): Replace all calls to OpenPrivilegedProcessHandle with the 147 // TODO(sanjeevr): Replace all calls to OpenPrivilegedProcessHandle with the
148 // more specific OpenProcessHandleWithAccess method and delete this. 148 // more specific OpenProcessHandleWithAccess method and delete this.
149 bool OpenPrivilegedProcessHandle(ProcessId pid, ProcessHandle* handle); 149 BASE_API bool OpenPrivilegedProcessHandle(ProcessId pid, ProcessHandle* handle);
150 150
151 // Converts a PID to a process handle using the desired access flags. Use a 151 // Converts a PID to a process handle using the desired access flags. Use a
152 // combination of the kProcessAccess* flags defined above for |access_flags|. 152 // combination of the kProcessAccess* flags defined above for |access_flags|.
153 bool OpenProcessHandleWithAccess(ProcessId pid, 153 BASE_API bool OpenProcessHandleWithAccess(ProcessId pid,
154 uint32 access_flags, 154 uint32 access_flags,
155 ProcessHandle* handle); 155 ProcessHandle* handle);
156 156
157 // Closes the process handle opened by OpenProcessHandle. 157 // Closes the process handle opened by OpenProcessHandle.
158 void CloseProcessHandle(ProcessHandle process); 158 BASE_API void CloseProcessHandle(ProcessHandle process);
159 159
160 // Returns the unique ID for the specified process. This is functionally the 160 // Returns the unique ID for the specified process. This is functionally the
161 // same as Windows' GetProcessId(), but works on versions of Windows before 161 // same as Windows' GetProcessId(), but works on versions of Windows before
162 // Win XP SP1 as well. 162 // Win XP SP1 as well.
163 ProcessId GetProcId(ProcessHandle process); 163 BASE_API ProcessId GetProcId(ProcessHandle process);
164 164
165 #if defined(OS_LINUX) 165 #if defined(OS_LINUX)
166 // Returns the path to the executable of the given process. 166 // Returns the path to the executable of the given process.
167 FilePath GetProcessExecutablePath(ProcessHandle process); 167 FilePath GetProcessExecutablePath(ProcessHandle process);
168 168
169 // Parse the data found in /proc/<pid>/stat and return the sum of the 169 // Parse the data found in /proc/<pid>/stat and return the sum of the
170 // CPU-related ticks. Returns -1 on parse error. 170 // CPU-related ticks. Returns -1 on parse error.
171 // Exposed for testing. 171 // Exposed for testing.
172 int ParseProcStatCPU(const std::string& input); 172 int ParseProcStatCPU(const std::string& input);
173 173
(...skipping 19 matching lines...) Expand all
193 193
194 enum IntegrityLevel { 194 enum IntegrityLevel {
195 INTEGRITY_UNKNOWN, 195 INTEGRITY_UNKNOWN,
196 LOW_INTEGRITY, 196 LOW_INTEGRITY,
197 MEDIUM_INTEGRITY, 197 MEDIUM_INTEGRITY,
198 HIGH_INTEGRITY, 198 HIGH_INTEGRITY,
199 }; 199 };
200 // Determine the integrity level of the specified process. Returns false 200 // Determine the integrity level of the specified process. Returns false
201 // if the system does not support integrity levels (pre-Vista) or in the case 201 // if the system does not support integrity levels (pre-Vista) or in the case
202 // of an underlying system failure. 202 // of an underlying system failure.
203 bool GetProcessIntegrityLevel(ProcessHandle process, IntegrityLevel *level); 203 BASE_API bool GetProcessIntegrityLevel(ProcessHandle process,
204 IntegrityLevel *level);
204 205
205 // Runs the given application name with the given command line. Normally, the 206 // Runs the given application name with the given command line. Normally, the
206 // first command line argument should be the path to the process, and don't 207 // first command line argument should be the path to the process, and don't
207 // forget to quote it. 208 // forget to quote it.
208 // 209 //
209 // If wait is true, it will block and wait for the other process to finish, 210 // If wait is true, it will block and wait for the other process to finish,
210 // otherwise, it will just continue asynchronously. 211 // otherwise, it will just continue asynchronously.
211 // 212 //
212 // Example (including literal quotes) 213 // Example (including literal quotes)
213 // cmdline = "c:\windows\explorer.exe" -foo "c:\bar\" 214 // cmdline = "c:\windows\explorer.exe" -foo "c:\bar\"
214 // 215 //
215 // If process_handle is non-NULL, the process handle of the launched app will be 216 // If process_handle is non-NULL, the process handle of the launched app will be
216 // stored there on a successful launch. 217 // stored there on a successful launch.
217 // NOTE: In this case, the caller is responsible for closing the handle so 218 // NOTE: In this case, the caller is responsible for closing the handle so
218 // that it doesn't leak! 219 // that it doesn't leak!
219 bool LaunchApp(const std::wstring& cmdline, 220 BASE_API bool LaunchApp(const std::wstring& cmdline,
220 bool wait, bool start_hidden, ProcessHandle* process_handle); 221 bool wait, bool start_hidden,
222 ProcessHandle* process_handle);
221 223
222 // Same as LaunchApp, except allows the new process to inherit handles of the 224 // Same as LaunchApp, except allows the new process to inherit handles of the
223 // parent process. 225 // parent process.
224 bool LaunchAppWithHandleInheritance(const std::wstring& cmdline, 226 BASE_API bool LaunchAppWithHandleInheritance(const std::wstring& cmdline,
225 bool wait, 227 bool wait, bool start_hidden,
226 bool start_hidden, 228 ProcessHandle* process_handle);
227 ProcessHandle* process_handle);
228 229
229 // Runs the given application name with the given command line as if the user 230 // Runs the given application name with the given command line as if the user
230 // represented by |token| had launched it. The caveats about |cmdline| and 231 // represented by |token| had launched it. The caveats about |cmdline| and
231 // |process_handle| explained for LaunchApp above apply as well. 232 // |process_handle| explained for LaunchApp above apply as well.
232 // 233 //
233 // Whether the application is visible on the interactive desktop depends on 234 // Whether the application is visible on the interactive desktop depends on
234 // the token belonging to an interactive logon session. 235 // the token belonging to an interactive logon session.
235 // 236 //
236 // To avoid hard to diagnose problems, this function internally loads the 237 // To avoid hard to diagnose problems, this function internally loads the
237 // environment variables associated with the user and if this operation fails 238 // environment variables associated with the user and if this operation fails
238 // the entire call fails as well. 239 // the entire call fails as well.
239 bool LaunchAppAsUser(UserTokenHandle token, const std::wstring& cmdline, 240 BASE_API bool LaunchAppAsUser(UserTokenHandle token,
240 bool start_hidden, ProcessHandle* process_handle); 241 const std::wstring& cmdline,
242 bool start_hidden,
243 ProcessHandle* process_handle);
241 244
242 // Has the same behavior as LaunchAppAsUser, but offers the boolean option to 245 // Has the same behavior as LaunchAppAsUser, but offers the boolean option to
243 // use an empty string for the desktop name and a boolean for allowing the 246 // use an empty string for the desktop name and a boolean for allowing the
244 // child process to inherit handles from its parent. 247 // child process to inherit handles from its parent.
245 bool LaunchAppAsUser(UserTokenHandle token, const std::wstring& cmdline, 248 BASE_API bool LaunchAppAsUser(UserTokenHandle token,
246 bool start_hidden, ProcessHandle* process_handle, 249 const std::wstring& cmdline,
247 bool empty_desktop_name, bool inherit_handles); 250 bool start_hidden, ProcessHandle* process_handle,
251 bool empty_desktop_name, bool inherit_handles);
248 252
249 253
250 #elif defined(OS_POSIX) 254 #elif defined(OS_POSIX)
251 // Runs the application specified in argv[0] with the command line argv. 255 // Runs the application specified in argv[0] with the command line argv.
252 // Before launching all FDs open in the parent process will be marked as 256 // Before launching all FDs open in the parent process will be marked as
253 // close-on-exec. |fds_to_remap| defines a mapping of src fd->dest fd to 257 // close-on-exec. |fds_to_remap| defines a mapping of src fd->dest fd to
254 // propagate FDs into the child process. 258 // propagate FDs into the child process.
255 // 259 //
256 // As above, if wait is true, execute synchronously. The pid will be stored 260 // As above, if wait is true, execute synchronously. The pid will be stored
257 // in process_handle if that pointer is non-null. 261 // in process_handle if that pointer is non-null.
(...skipping 27 matching lines...) Expand all
285 // event of a match, the value is replaced by the second of the pair, unless 289 // event of a match, the value is replaced by the second of the pair, unless
286 // the second is empty, in which case the key-value is removed. 290 // the second is empty, in which case the key-value is removed.
287 // 291 //
288 // The returned array is allocated using new[] and must be freed by the caller. 292 // The returned array is allocated using new[] and must be freed by the caller.
289 char** AlterEnvironment(const environment_vector& changes, 293 char** AlterEnvironment(const environment_vector& changes,
290 const char* const* const env); 294 const char* const* const env);
291 #endif // defined(OS_POSIX) 295 #endif // defined(OS_POSIX)
292 296
293 // Executes the application specified by cl. This function delegates to one 297 // Executes the application specified by cl. This function delegates to one
294 // of the above two platform-specific functions. 298 // of the above two platform-specific functions.
295 bool LaunchApp(const CommandLine& cl, 299 BASE_API bool LaunchApp(const CommandLine& cl, bool wait, bool start_hidden,
296 bool wait, bool start_hidden, ProcessHandle* process_handle); 300 ProcessHandle* process_handle);
297 301
298 // Executes the application specified by |cl| and wait for it to exit. Stores 302 // Executes the application specified by |cl| and wait for it to exit. Stores
299 // the output (stdout) in |output|. Redirects stderr to /dev/null. Returns true 303 // the output (stdout) in |output|. Redirects stderr to /dev/null. Returns true
300 // on success (application launched and exited cleanly, with exit code 304 // on success (application launched and exited cleanly, with exit code
301 // indicating success). 305 // indicating success).
302 bool GetAppOutput(const CommandLine& cl, std::string* output); 306 BASE_API bool GetAppOutput(const CommandLine& cl, std::string* output);
303 307
304 #if defined(OS_POSIX) 308 #if defined(OS_POSIX)
305 // A restricted version of |GetAppOutput()| which (a) clears the environment, 309 // A restricted version of |GetAppOutput()| which (a) clears the environment,
306 // and (b) stores at most |max_output| bytes; also, it doesn't search the path 310 // and (b) stores at most |max_output| bytes; also, it doesn't search the path
307 // for the command. 311 // for the command.
308 bool GetAppOutputRestricted(const CommandLine& cl, 312 bool GetAppOutputRestricted(const CommandLine& cl,
309 std::string* output, size_t max_output); 313 std::string* output, size_t max_output);
310 #endif 314 #endif
311 315
312 // Used to filter processes by process ID. 316 // Used to filter processes by process ID.
313 class ProcessFilter { 317 class ProcessFilter {
314 public: 318 public:
315 // Returns true to indicate set-inclusion and false otherwise. This method 319 // Returns true to indicate set-inclusion and false otherwise. This method
316 // should not have side-effects and should be idempotent. 320 // should not have side-effects and should be idempotent.
317 virtual bool Includes(const ProcessEntry& entry) const = 0; 321 virtual bool Includes(const ProcessEntry& entry) const = 0;
318 322
319 protected: 323 protected:
320 virtual ~ProcessFilter() {} 324 virtual ~ProcessFilter() {}
321 }; 325 };
322 326
323 // Returns the number of processes on the machine that are running from the 327 // Returns the number of processes on the machine that are running from the
324 // given executable name. If filter is non-null, then only processes selected 328 // given executable name. If filter is non-null, then only processes selected
325 // by the filter will be counted. 329 // by the filter will be counted.
326 int GetProcessCount(const FilePath::StringType& executable_name, 330 BASE_API int GetProcessCount(const FilePath::StringType& executable_name,
327 const ProcessFilter* filter); 331 const ProcessFilter* filter);
328 332
329 // Attempts to kill all the processes on the current machine that were launched 333 // Attempts to kill all the processes on the current machine that were launched
330 // from the given executable name, ending them with the given exit code. If 334 // from the given executable name, ending them with the given exit code. If
331 // filter is non-null, then only processes selected by the filter are killed. 335 // filter is non-null, then only processes selected by the filter are killed.
332 // Returns true if all processes were able to be killed off, false if at least 336 // Returns true if all processes were able to be killed off, false if at least
333 // one couldn't be killed. 337 // one couldn't be killed.
334 bool KillProcesses(const FilePath::StringType& executable_name, int exit_code, 338 BASE_API bool KillProcesses(const FilePath::StringType& executable_name,
335 const ProcessFilter* filter); 339 int exit_code, const ProcessFilter* filter);
336 340
337 // Attempts to kill the process identified by the given process 341 // Attempts to kill the process identified by the given process
338 // entry structure, giving it the specified exit code. If |wait| is true, wait 342 // entry structure, giving it the specified exit code. If |wait| is true, wait
339 // for the process to be actually terminated before returning. 343 // for the process to be actually terminated before returning.
340 // Returns true if this is successful, false otherwise. 344 // Returns true if this is successful, false otherwise.
341 bool KillProcess(ProcessHandle process, int exit_code, bool wait); 345 BASE_API bool KillProcess(ProcessHandle process, int exit_code, bool wait);
342 346
343 #if defined(OS_POSIX) 347 #if defined(OS_POSIX)
344 // Attempts to kill the process group identified by |process_group_id|. Returns 348 // Attempts to kill the process group identified by |process_group_id|. Returns
345 // true on success. 349 // true on success.
346 bool KillProcessGroup(ProcessHandle process_group_id); 350 bool KillProcessGroup(ProcessHandle process_group_id);
347 #endif 351 #endif
348 352
349 #if defined(OS_WIN) 353 #if defined(OS_WIN)
350 bool KillProcessById(ProcessId process_id, int exit_code, bool wait); 354 BASE_API bool KillProcessById(ProcessId process_id, int exit_code, bool wait);
351 #endif 355 #endif
352 356
353 // Get the termination status of the process by interpreting the 357 // Get the termination status of the process by interpreting the
354 // circumstances of the child process' death. |exit_code| is set to 358 // circumstances of the child process' death. |exit_code| is set to
355 // the status returned by waitpid() on POSIX, and from 359 // the status returned by waitpid() on POSIX, and from
356 // GetExitCodeProcess() on Windows. |exit_code| may be NULL if the 360 // GetExitCodeProcess() on Windows. |exit_code| may be NULL if the
357 // caller is not interested in it. Note that on Linux, this function 361 // caller is not interested in it. Note that on Linux, this function
358 // will only return a useful result the first time it is called after 362 // will only return a useful result the first time it is called after
359 // the child exits (because it will reap the child and the information 363 // the child exits (because it will reap the child and the information
360 // will no longer be available). 364 // will no longer be available).
361 TerminationStatus GetTerminationStatus(ProcessHandle handle, int* exit_code); 365 BASE_API TerminationStatus GetTerminationStatus(ProcessHandle handle,
366 int* exit_code);
362 367
363 // Waits for process to exit. On POSIX systems, if the process hasn't been 368 // Waits for process to exit. On POSIX systems, if the process hasn't been
364 // signaled then puts the exit code in |exit_code|; otherwise it's considered 369 // signaled then puts the exit code in |exit_code|; otherwise it's considered
365 // a failure. On Windows |exit_code| is always filled. Returns true on success, 370 // a failure. On Windows |exit_code| is always filled. Returns true on success,
366 // and closes |handle| in any case. 371 // and closes |handle| in any case.
367 bool WaitForExitCode(ProcessHandle handle, int* exit_code); 372 BASE_API bool WaitForExitCode(ProcessHandle handle, int* exit_code);
368 373
369 // Waits for process to exit. If it did exit within |timeout_milliseconds|, 374 // Waits for process to exit. If it did exit within |timeout_milliseconds|,
370 // then puts the exit code in |exit_code|, closes |handle|, and returns true. 375 // then puts the exit code in |exit_code|, closes |handle|, and returns true.
371 // In POSIX systems, if the process has been signaled then |exit_code| is set 376 // In POSIX systems, if the process has been signaled then |exit_code| is set
372 // to -1. Returns false on failure (the caller is then responsible for closing 377 // to -1. Returns false on failure (the caller is then responsible for closing
373 // |handle|). 378 // |handle|).
374 bool WaitForExitCodeWithTimeout(ProcessHandle handle, int* exit_code, 379 BASE_API bool WaitForExitCodeWithTimeout(ProcessHandle handle, int* exit_code,
375 int64 timeout_milliseconds); 380 int64 timeout_milliseconds);
376 381
377 // Wait for all the processes based on the named executable to exit. If filter 382 // Wait for all the processes based on the named executable to exit. If filter
378 // is non-null, then only processes selected by the filter are waited on. 383 // is non-null, then only processes selected by the filter are waited on.
379 // Returns after all processes have exited or wait_milliseconds have expired. 384 // Returns after all processes have exited or wait_milliseconds have expired.
380 // Returns true if all the processes exited, false otherwise. 385 // Returns true if all the processes exited, false otherwise.
381 bool WaitForProcessesToExit(const FilePath::StringType& executable_name, 386 BASE_API bool WaitForProcessesToExit(
382 int64 wait_milliseconds, 387 const FilePath::StringType& executable_name,
383 const ProcessFilter* filter); 388 int64 wait_milliseconds,
389 const ProcessFilter* filter);
384 390
385 // Wait for a single process to exit. Return true if it exited cleanly within 391 // Wait for a single process to exit. Return true if it exited cleanly within
386 // the given time limit. On Linux |handle| must be a child process, however 392 // the given time limit. On Linux |handle| must be a child process, however
387 // on Mac and Windows it can be any process. 393 // on Mac and Windows it can be any process.
388 bool WaitForSingleProcess(ProcessHandle handle, int64 wait_milliseconds); 394 BASE_API bool WaitForSingleProcess(ProcessHandle handle,
395 int64 wait_milliseconds);
389 396
390 // Returns true when |wait_milliseconds| have elapsed and the process 397 // Returns true when |wait_milliseconds| have elapsed and the process
391 // is still running. 398 // is still running.
392 bool CrashAwareSleep(ProcessHandle handle, int64 wait_milliseconds); 399 BASE_API bool CrashAwareSleep(ProcessHandle handle, int64 wait_milliseconds);
393 400
394 // Waits a certain amount of time (can be 0) for all the processes with a given 401 // Waits a certain amount of time (can be 0) for all the processes with a given
395 // executable name to exit, then kills off any of them that are still around. 402 // executable name to exit, then kills off any of them that are still around.
396 // If filter is non-null, then only processes selected by the filter are waited 403 // If filter is non-null, then only processes selected by the filter are waited
397 // on. Killed processes are ended with the given exit code. Returns false if 404 // on. Killed processes are ended with the given exit code. Returns false if
398 // any processes needed to be killed, true if they all exited cleanly within 405 // any processes needed to be killed, true if they all exited cleanly within
399 // the wait_milliseconds delay. 406 // the wait_milliseconds delay.
400 bool CleanupProcesses(const FilePath::StringType& executable_name, 407 BASE_API bool CleanupProcesses(const FilePath::StringType& executable_name,
401 int64 wait_milliseconds, 408 int64 wait_milliseconds,
402 int exit_code, 409 int exit_code,
403 const ProcessFilter* filter); 410 const ProcessFilter* filter);
404 411
405 // This class provides a way to iterate through a list of processes on the 412 // This class provides a way to iterate through a list of processes on the
406 // current machine with a specified filter. 413 // current machine with a specified filter.
407 // To use, create an instance and then call NextProcessEntry() until it returns 414 // To use, create an instance and then call NextProcessEntry() until it returns
408 // false. 415 // false.
409 class ProcessIterator { 416 class BASE_API ProcessIterator {
410 public: 417 public:
411 typedef std::list<ProcessEntry> ProcessEntries; 418 typedef std::list<ProcessEntry> ProcessEntries;
412 419
413 explicit ProcessIterator(const ProcessFilter* filter); 420 explicit ProcessIterator(const ProcessFilter* filter);
414 virtual ~ProcessIterator(); 421 virtual ~ProcessIterator();
415 422
416 // If there's another process that matches the given executable name, 423 // If there's another process that matches the given executable name,
417 // returns a const pointer to the corresponding PROCESSENTRY32. 424 // returns a const pointer to the corresponding PROCESSENTRY32.
418 // If there are no more matching processes, returns NULL. 425 // If there are no more matching processes, returns NULL.
419 // The returned pointer will remain valid until NextProcessEntry() 426 // The returned pointer will remain valid until NextProcessEntry()
(...skipping 29 matching lines...) Expand all
449 ProcessEntry entry_; 456 ProcessEntry entry_;
450 const ProcessFilter* filter_; 457 const ProcessFilter* filter_;
451 458
452 DISALLOW_COPY_AND_ASSIGN(ProcessIterator); 459 DISALLOW_COPY_AND_ASSIGN(ProcessIterator);
453 }; 460 };
454 461
455 // This class provides a way to iterate through the list of processes 462 // This class provides a way to iterate through the list of processes
456 // on the current machine that were started from the given executable 463 // on the current machine that were started from the given executable
457 // name. To use, create an instance and then call NextProcessEntry() 464 // name. To use, create an instance and then call NextProcessEntry()
458 // until it returns false. 465 // until it returns false.
459 class NamedProcessIterator : public ProcessIterator { 466 class BASE_API NamedProcessIterator : public ProcessIterator {
460 public: 467 public:
461 NamedProcessIterator(const FilePath::StringType& executable_name, 468 NamedProcessIterator(const FilePath::StringType& executable_name,
462 const ProcessFilter* filter); 469 const ProcessFilter* filter);
463 virtual ~NamedProcessIterator(); 470 virtual ~NamedProcessIterator();
464 471
465 protected: 472 protected:
466 virtual bool IncludeEntry(); 473 virtual bool IncludeEntry();
467 474
468 private: 475 private:
469 FilePath::StringType executable_name_; 476 FilePath::StringType executable_name_;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 // largest : size of the largest contiguous amount of memory found. It is 521 // largest : size of the largest contiguous amount of memory found. It is
515 // always smaller or equal to FreeMBytes::total. 522 // always smaller or equal to FreeMBytes::total.
516 // largest_ptr: starting address of the largest memory block. 523 // largest_ptr: starting address of the largest memory block.
517 struct FreeMBytes { 524 struct FreeMBytes {
518 size_t total; 525 size_t total;
519 size_t largest; 526 size_t largest;
520 void* largest_ptr; 527 void* largest_ptr;
521 }; 528 };
522 529
523 // Convert a POSIX timeval to microseconds. 530 // Convert a POSIX timeval to microseconds.
524 int64 TimeValToMicroseconds(const struct timeval& tv); 531 BASE_API int64 TimeValToMicroseconds(const struct timeval& tv);
525 532
526 // Provides performance metrics for a specified process (CPU usage, memory and 533 // Provides performance metrics for a specified process (CPU usage, memory and
527 // IO counters). To use it, invoke CreateProcessMetrics() to get an instance 534 // IO counters). To use it, invoke CreateProcessMetrics() to get an instance
528 // for a specific process, then access the information with the different get 535 // for a specific process, then access the information with the different get
529 // methods. 536 // methods.
530 class ProcessMetrics { 537 class BASE_API ProcessMetrics {
531 public: 538 public:
532 ~ProcessMetrics(); 539 ~ProcessMetrics();
533 540
534 // Creates a ProcessMetrics for the specified process. 541 // Creates a ProcessMetrics for the specified process.
535 // The caller owns the returned object. 542 // The caller owns the returned object.
536 #if !defined(OS_MACOSX) 543 #if !defined(OS_MACOSX)
537 static ProcessMetrics* CreateProcessMetrics(ProcessHandle process); 544 static ProcessMetrics* CreateProcessMetrics(ProcessHandle process);
538 #else 545 #else
539 class PortProvider { 546 class PortProvider {
540 public: 547 public:
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 #elif defined(OS_POSIX) 628 #elif defined(OS_POSIX)
622 // Jiffie count at the last_time_ we updated. 629 // Jiffie count at the last_time_ we updated.
623 int last_cpu_; 630 int last_cpu_;
624 #endif // defined(OS_MACOSX) 631 #endif // defined(OS_MACOSX)
625 632
626 DISALLOW_COPY_AND_ASSIGN(ProcessMetrics); 633 DISALLOW_COPY_AND_ASSIGN(ProcessMetrics);
627 }; 634 };
628 635
629 // Returns the memory commited by the system in KBytes. 636 // Returns the memory commited by the system in KBytes.
630 // Returns 0 if it can't compute the commit charge. 637 // Returns 0 if it can't compute the commit charge.
631 size_t GetSystemCommitCharge(); 638 BASE_API size_t GetSystemCommitCharge();
632 639
633 // Enables low fragmentation heap (LFH) for every heaps of this process. This 640 // Enables low fragmentation heap (LFH) for every heaps of this process. This
634 // won't have any effect on heaps created after this function call. It will not 641 // won't have any effect on heaps created after this function call. It will not
635 // modify data allocated in the heaps before calling this function. So it is 642 // modify data allocated in the heaps before calling this function. So it is
636 // better to call this function early in initialization and again before 643 // better to call this function early in initialization and again before
637 // entering the main loop. 644 // entering the main loop.
638 // Note: Returns true on Windows 2000 without doing anything. 645 // Note: Returns true on Windows 2000 without doing anything.
639 bool EnableLowFragmentationHeap(); 646 BASE_API bool EnableLowFragmentationHeap();
640 647
641 // Enables 'terminate on heap corruption' flag. Helps protect against heap 648 // Enables 'terminate on heap corruption' flag. Helps protect against heap
642 // overflow. Has no effect if the OS doesn't provide the necessary facility. 649 // overflow. Has no effect if the OS doesn't provide the necessary facility.
643 BASE_API void EnableTerminationOnHeapCorruption(); 650 BASE_API void EnableTerminationOnHeapCorruption();
644 651
645 #if !defined(OS_WIN) 652 #if !defined(OS_WIN)
646 // Turns on process termination if memory runs out. This is handled on Windows 653 // Turns on process termination if memory runs out. This is handled on Windows
647 // inside RegisterInvalidParamHandler(). 654 // inside RegisterInvalidParamHandler().
648 void EnableTerminationOnOutOfMemory(); 655 void EnableTerminationOnOutOfMemory();
649 #if defined(OS_MACOSX) 656 #if defined(OS_MACOSX)
650 // Exposed for testing. 657 // Exposed for testing.
651 malloc_zone_t* GetPurgeableZone(); 658 malloc_zone_t* GetPurgeableZone();
652 #endif 659 #endif
653 #endif 660 #endif
654 661
655 #if defined(UNIT_TEST)
656 // Enables stack dump to console output on exception and signals. 662 // Enables stack dump to console output on exception and signals.
657 // When enabled, the process will quit immediately. This is meant to be used in 663 // When enabled, the process will quit immediately. This is meant to be used in
658 // unit_tests only! 664 // unit_tests only!
659 bool EnableInProcessStackDumping(); 665 BASE_API bool EnableInProcessStackDumping();
660 #endif // defined(UNIT_TEST)
661 666
662 // If supported on the platform, and the user has sufficent rights, increase 667 // If supported on the platform, and the user has sufficent rights, increase
663 // the current process's scheduling priority to a high priority. 668 // the current process's scheduling priority to a high priority.
664 void RaiseProcessToHighPriority(); 669 BASE_API void RaiseProcessToHighPriority();
665 670
666 #if defined(OS_MACOSX) 671 #if defined(OS_MACOSX)
667 // Restore the default exception handler, setting it to Apple Crash Reporter 672 // Restore the default exception handler, setting it to Apple Crash Reporter
668 // (ReportCrash). When forking and execing a new process, the child will 673 // (ReportCrash). When forking and execing a new process, the child will
669 // inherit the parent's exception ports, which may be set to the Breakpad 674 // inherit the parent's exception ports, which may be set to the Breakpad
670 // instance running inside the parent. The parent's Breakpad instance should 675 // instance running inside the parent. The parent's Breakpad instance should
671 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler 676 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler
672 // in the child after forking will restore the standard exception handler. 677 // in the child after forking will restore the standard exception handler.
673 // See http://crbug.com/20371/ for more details. 678 // See http://crbug.com/20371/ for more details.
674 void RestoreDefaultExceptionHandler(); 679 void RestoreDefaultExceptionHandler();
675 #endif // defined(OS_MACOSX) 680 #endif // defined(OS_MACOSX)
676 681
677 } // namespace base 682 } // namespace base
678 683
679 #endif // BASE_PROCESS_UTIL_H_ 684 #endif // BASE_PROCESS_UTIL_H_
OLDNEW
« no previous file with comments | « base/process.h ('k') | base/scoped_native_library.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698