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

Side by Side Diff: services/service_manager/standalone/tracer.h

Issue 2852183002: Delete the tracing service (Closed)
Patch Set: Created 3 years, 7 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
OLDNEW
(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 SERVICES_SERVICE_MANAGER_STANDALONE_TRACER_H_
6 #define SERVICES_SERVICE_MANAGER_STANDALONE_TRACER_H_
7
8 #include <stddef.h>
9 #include <stdio.h>
10
11 #include <memory>
12 #include <string>
13
14 #include "base/callback.h"
15 #include "base/macros.h"
16 #include "base/memory/ref_counted_memory.h"
17 #include "mojo/common/data_pipe_drainer.h"
18 #include "services/tracing/public/interfaces/tracing.mojom.h"
19
20 namespace service_manager {
21
22 // Tracer collects tracing data from base/trace_event and from externally
23 // configured sources, aggregates it into a single stream, and writes it out to
24 // a file. It should be constructed very early in a process' lifetime before any
25 // initialization that may be interesting to trace has occured and be shut down
26 // as late as possible to capture as much initialization/shutdown code as
27 // possible.
28 class Tracer : public mojo::common::DataPipeDrainer::Client {
29 public:
30 Tracer();
31 ~Tracer() override;
32
33 // Starts tracing the current process with the given set of categories. The
34 // tracing results will be saved into the specified filename when
35 // StopAndFlushToFile() is called.
36 void Start(const std::string& categories,
37 const std::string& duration_seconds_str,
38 const std::string& filename);
39
40 // Starts collecting data from the tracing service with the given set of
41 // categories.
42 void StartCollectingFromTracingService(
43 tracing::mojom::CollectorPtr coordinator);
44
45 // Stops tracing and flushes all collected trace data to the file specified in
46 // Start(). Blocks until the file write is complete. May be called after the
47 // message loop is shut down.
48 void StopAndFlushToFile();
49
50 void ConnectToProvider(tracing::mojom::ProviderRequest request);
51
52 private:
53 void StopTracingAndFlushToDisk();
54
55 // Called from the flush thread. When all data is collected this runs
56 // |done_callback| on the flush thread.
57 void EndTraceAndFlush(const std::string& filename,
58 const base::Closure& done_callback);
59
60 // Called from the flush thread.
61 void WriteTraceDataCollected(
62 const base::Closure& done_callback,
63 const scoped_refptr<base::RefCountedString>& events_str,
64 bool has_more_events);
65
66 // mojo::common::DataPipeDrainer::Client implementation.
67 void OnDataAvailable(const void* data, size_t num_bytes) override;
68 void OnDataComplete() override;
69
70 // Emits a comma if needed.
71 void WriteCommaIfNeeded();
72
73 // Writes trace file footer and closes out the file.
74 void WriteFooterAndClose();
75
76 // Set when connected to the tracing service.
77 tracing::mojom::CollectorPtr coordinator_;
78 std::unique_ptr<mojo::common::DataPipeDrainer> drainer_;
79
80 // Whether we're currently tracing.
81 bool tracing_;
82 // Categories to trace.
83 std::string categories_;
84
85 // Whether we've written the first chunk.
86 bool first_chunk_written_;
87 std::string trace_service_data_;
88
89 // Trace file, if open.
90 FILE* trace_file_;
91 std::string trace_filename_;
92
93 DISALLOW_COPY_AND_ASSIGN(Tracer);
94 };
95
96 } // namespace service_manager
97
98 #endif // SERVICES_SERVICE_MANAGER_STANDALONE_TRACER_H_
OLDNEW
« no previous file with comments | « services/service_manager/standalone/context.cc ('k') | services/service_manager/standalone/tracer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698