1 : // Copyright 2012 Google Inc.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // This file declares the TraceFileWriterFactory class, which provides a
16 : // factory implementation for the default buffer consumer used by the call
17 : // trace service.
18 :
19 : #ifndef SYZYGY_TRACE_SERVICE_TRACE_FILE_WRITER_H_
20 : #define SYZYGY_TRACE_SERVICE_TRACE_FILE_WRITER_H_
21 :
22 : #include "base/file_path.h"
23 : #include "base/threading/thread.h"
24 : #include "base/win/scoped_handle.h"
25 : #include "syzygy/trace/service/buffer_consumer.h"
26 :
27 m : namespace trace {
28 m : namespace service {
29 :
30 : // Forward Declaration.
31 m : class Session;
32 m : class TraceFileWriterFactory;
33 :
34 : // This class implements the interface the buffer consumer thread uses to
35 : // process incomming buffers.
36 m : class TraceFileWriter : public BufferConsumer {
37 m : public:
38 : // Construct a TraceFileWriter instance.
39 : // @param message_loop The message loop on which this writer instance will
40 : // consume buffers. The writer instance does NOT take ownership of the
41 : // message_loop. The message_loop must outlive the writer instance.
42 : // @param trace_directory The directoy into which this writer instance will
43 : // write the trace file.
44 m : TraceFileWriter(MessageLoop* message_loop, const FilePath& trace_directory);
45 :
46 : // Initialize this trace file writer.
47 : // @name BufferConsumer implementation.
48 : // @{
49 m : bool Open(Session* session) OVERRIDE;
50 m : bool Close(Session* session) OVERRIDE;
51 m : virtual bool ConsumeBuffer(Buffer* buffer) OVERRIDE;
52 m : virtual size_t block_size() const OVERRIDE;
53 : // @}
54 :
55 m : protected:
56 : // Commit a trace buffer to disk. This will be called on message_loop_.
57 m : void WriteBuffer(Session* session, Buffer* buffer);
58 :
59 : // The message loop on which this trace file writer will do IO.
60 m : MessageLoop* const message_loop_;
61 :
62 : // The name of the trace file. Note that we initialize this to the trace
63 : // directory on construction and calculate the final trace file path on
64 : // Open().
65 m : FilePath trace_file_path_;
66 :
67 : // The handle to the trace file to which buffers are committed.
68 m : base::win::ScopedHandle trace_file_handle_;
69 :
70 : // The block size used when writing to disk. This corresponds to
71 : // the physical sector size of the disk.
72 m : size_t block_size_;
73 :
74 m : private:
75 m : DISALLOW_COPY_AND_ASSIGN(TraceFileWriter);
76 m : };
77 :
78 m : } // namespace service
79 m : } // namespace trace
80 :
81 : #endif // SYZYGY_TRACE_SERVICE_TRACE_FILE_WRITER_H_
|