blob: f179d8f5b4f13eb1761d1f77aae1a434b8183019 [file] [log] [blame]
Hector Dearman86cfbe12018-03-22 11:58:42 +00001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SRC_PERFETTO_CMD_PERFETTO_CMD_H_
18#define SRC_PERFETTO_CMD_PERFETTO_CMD_H_
19
20#include <memory>
21#include <string>
22#include <vector>
23
24#include <time.h>
25
Primiano Tuccife922332018-03-22 16:15:04 -070026#include "perfetto/base/build_config.h"
Hector Dearman86cfbe12018-03-22 11:58:42 +000027#include "perfetto/base/scoped_file.h"
28#include "perfetto/base/unix_task_runner.h"
29#include "perfetto/tracing/core/consumer.h"
30#include "perfetto/tracing/ipc/consumer_ipc_client.h"
Primiano Tucci3cbb10a2018-04-10 17:52:40 +010031#include "src/perfetto_cmd/rate_limiter.h"
Hector Dearman86cfbe12018-03-22 11:58:42 +000032
33#include "src/perfetto_cmd/perfetto_cmd_state.pb.h"
34
35#if defined(PERFETTO_OS_ANDROID)
36#include "perfetto/base/android_task_runner.h"
37#endif // defined(PERFETTO_OS_ANDROID)
38
Hector Dearman86cfbe12018-03-22 11:58:42 +000039
40namespace perfetto {
41
42// Temporary directory for DropBox traces. Note that this is automatically
43// created by the system by setting setprop persist.traced.enable=1.
44extern const char* kTempDropBoxTraceDir;
45
46#if defined(PERFETTO_OS_ANDROID)
47using PlatformTaskRunner = base::AndroidTaskRunner;
48#else
49using PlatformTaskRunner = base::UnixTaskRunner;
50#endif
51
52class PerfettoCmd : public Consumer {
53 public:
54 int Main(int argc, char** argv);
Hector Dearman86cfbe12018-03-22 11:58:42 +000055
56 // perfetto::Consumer implementation.
57 void OnConnect() override;
58 void OnDisconnect() override;
Primiano Tuccidca727d2018-04-04 11:31:55 +020059 void OnTracingDisabled() override;
Hector Dearman86cfbe12018-03-22 11:58:42 +000060 void OnTraceData(std::vector<TracePacket>, bool has_more) override;
61
Primiano Tucci2ffd1a52018-03-27 01:01:30 +010062 int ctrl_c_pipe_wr() const { return *ctrl_c_pipe_wr_; }
63
Hector Dearman86cfbe12018-03-22 11:58:42 +000064 private:
65 bool OpenOutputFile();
Primiano Tucci2ffd1a52018-03-27 01:01:30 +010066 void SetupCtrlCSignalHandler();
67 void FinalizeTraceAndExit();
68 int PrintUsage(const char* argv0);
69 void OnTimeout();
Hector Dearman86cfbe12018-03-22 11:58:42 +000070
71 PlatformTaskRunner task_runner_;
72 std::unique_ptr<perfetto::Service::ConsumerEndpoint> consumer_endpoint_;
73 std::unique_ptr<TraceConfig> trace_config_;
74 base::ScopedFstream trace_out_stream_;
75 std::string trace_out_path_;
Primiano Tucci2ffd1a52018-03-27 01:01:30 +010076 base::ScopedFile ctrl_c_pipe_wr_;
77 base::ScopedFile ctrl_c_pipe_rd_;
Hector Dearman86cfbe12018-03-22 11:58:42 +000078 std::string dropbox_tag_;
79 bool did_process_full_trace_ = false;
80 size_t bytes_uploaded_to_dropbox_ = 0;
81};
82
83} // namespace perfetto
84
85#endif // SRC_PERFETTO_CMD_PERFETTO_CMD_H_