diff options
author | skuhne@chromium.org <skuhne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-06 07:47:07 +0000 |
---|---|---|
committer | skuhne@chromium.org <skuhne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-06 07:47:07 +0000 |
commit | 89af400288e84e47f5756909dd7463c27f6f3423 (patch) | |
tree | 803f959ded9e6a16a81aca406705a1d04fa8e3dd /content/browser/browser_shutdown_profile_dumper.h | |
parent | f69751276e78d137623b342e52537f8b49377e03 (diff) | |
download | chromium_src-89af400288e84e47f5756909dd7463c27f6f3423.zip chromium_src-89af400288e84e47f5756909dd7463c27f6f3423.tar.gz chromium_src-89af400288e84e47f5756909dd7463c27f6f3423.tar.bz2 |
Adding shutdown tracing capabilities
use "--trace-shutdown" to enable the feature to start profiling when the user has pressed "shutdown" and specify "--trace-shutdown-file=<name>" to specify the file where you want to dump to. Additionally you can specify which modules to trace with e.g. "--trace-shutdown=base,net".
That said: NOTE that the dumping will cost time since it has to be done after the shutdown of Chrome is finished. As such it takes time and will make it impossible to get a correct reading of time from shutdown till a new startup is finished.
Note: This is similar to the trace-startup - with the exception that upon shutdown it is not possible to rely on threads for IO anymore.
BUG=281524
TEST=visual tests
Review URL: https://chromiumcodereview.appspot.com/23691025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221631 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/browser_shutdown_profile_dumper.h')
-rw-r--r-- | content/browser/browser_shutdown_profile_dumper.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/content/browser/browser_shutdown_profile_dumper.h b/content/browser/browser_shutdown_profile_dumper.h new file mode 100644 index 0000000..bb2c09b --- /dev/null +++ b/content/browser/browser_shutdown_profile_dumper.h @@ -0,0 +1,69 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_BROWSER_SHUTDOWN_PROFILE_DUMPER_H_ +#define CONTENT_BROWSER_BROWSER_SHUTDOWN_PROFILE_DUMPER_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/memory/ref_counted.h" +#include "base/memory/ref_counted_memory.h" +#include "content/common/content_export.h" + +namespace base { +class FilePath; +} + +namespace content { + +// This class is intended to dump the tracing results of the shutdown process +// to a file before the browser process exits. +// It will save the file either into the command line passed +// "--trace-shutdown-file=<name>" parameter - or - to "chrometrace.log" in the +// current directory. +// Use the class with a scoped_ptr to get files written in the destructor. +// Note that we cannot use the asynchronous file writer since the +// |SequencedWorkerPool| will get killed in the shutdown process. +class BrowserShutdownProfileDumper { + public: + BrowserShutdownProfileDumper(); + + ~BrowserShutdownProfileDumper(); + + private: + // Writes all traces which happened to disk. + void WriteTracesToDisc(const base::FilePath& file_name); + + // Returns the file name where we should save the trace dump to. + base::FilePath GetFileName(); + + // The callback for the |TraceLog::Flush| function. It saves all traces to + // disc. + void WriteTraceDataCollected( + const scoped_refptr<base::RefCountedString>& events_str); + + // Returns true if the dump file is valid. + bool IsFileValid(); + + // Writes a string to the dump file. + void WriteString(const std::string& string); + + // Write a buffer to the dump file. + void WriteChars(const char* chars, size_t size); + + // Closes the dump file. + void CloseFile(); + + // The number of blocks we have already written. + int blocks_; + // For dumping the content to disc. + FILE* dump_file_; + + DISALLOW_COPY_AND_ASSIGN(BrowserShutdownProfileDumper); +}; + +} // namespace content + +#endif // CONTENT_BROWSER_BROWSER_SHUTDOWN_PROFILE_DUMPER_H_ |