OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROMECAST_CRASH_LINUX_MINIDUMP_WRITER_H_ |
| 6 #define CHROMECAST_CRASH_LINUX_MINIDUMP_WRITER_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "chromecast/crash/linux/dump_info.h" |
| 12 #include "chromecast/crash/linux/minidump_manager.h" |
| 13 |
| 14 namespace chromecast { |
| 15 |
| 16 class MinidumpGenerator; |
| 17 |
| 18 // Class for writing a minidump. |
| 19 class MinidumpWriter : public MinidumpManager { |
| 20 public: |
| 21 // Constructs a minidump writer. |
| 22 MinidumpWriter(MinidumpGenerator* minidump_generator, |
| 23 const std::string& minidump_path, |
| 24 const MinidumpParams& params); |
| 25 |
| 26 ~MinidumpWriter() override {} |
| 27 |
| 28 // Fork and run dumpstate, saving results to minidump_name + ".txt.gz". |
| 29 static int DumpState(const std::string& minidump_name); |
| 30 |
| 31 void SetMaxDumpsForTest(int max_dumps) { max_dumps_ = max_dumps; } |
| 32 void SetMaxRecentDumpsForTest(int max_recent_dumps) { |
| 33 max_recent_dumps_ = max_recent_dumps; |
| 34 } |
| 35 bool CanWriteDumpForTest() { return CanWriteDump(); }; |
| 36 |
| 37 protected: |
| 38 // MinidumpManager implementation: |
| 39 int DoWork() override; |
| 40 |
| 41 private: |
| 42 // Returns true if we can write another dump, false otherwise. This |
| 43 // function parses the file at |lockfile_path_|, which contains records of |
| 44 // each minidump in |minidump_path_|. We can write another dump if the number |
| 45 // of minidumps is strictly less than |max_dumps_| and the number of minidumps |
| 46 // which occurred within the last |dump_interval_| is strictly less than |
| 47 // |max_recent_dumps_|. This method is expensive, and should be called |
| 48 // sparingly. |
| 49 bool CanWriteDump() const; |
| 50 |
| 51 // Append another entry to the lockfile describing the latest dump written. |
| 52 // Returns 0 on success, -1 on failure. |
| 53 int LogLockFile(const std::string& logfile); |
| 54 |
| 55 // These are data passed in from the constructor, to be used inside DoWork(). |
| 56 MinidumpGenerator* minidump_generator_; |
| 57 const std::string& minidump_path_; |
| 58 const MinidumpParams params_; |
| 59 |
| 60 int max_dumps_; |
| 61 int dump_interval_; |
| 62 int max_recent_dumps_; |
| 63 int max_total_size_; |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(MinidumpWriter); |
| 66 }; |
| 67 |
| 68 } // namespace chromecast |
| 69 |
| 70 #endif // CHROMECAST_CRASH_LINUX_MINIDUMP_WRITER_H_ |
OLD | NEW |