Hector Dearman | 86cfbe1 | 2018-03-22 11:58:42 +0000 | [diff] [blame] | 1 | /* |
| 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 Tucci | fe92233 | 2018-03-22 16:15:04 -0700 | [diff] [blame] | 26 | #include "perfetto/base/build_config.h" |
Hector Dearman | 86cfbe1 | 2018-03-22 11:58:42 +0000 | [diff] [blame] | 27 | #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 Tucci | 3cbb10a | 2018-04-10 17:52:40 +0100 | [diff] [blame] | 31 | #include "src/perfetto_cmd/rate_limiter.h" |
Hector Dearman | 86cfbe1 | 2018-03-22 11:58:42 +0000 | [diff] [blame] | 32 | |
| 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 Dearman | 86cfbe1 | 2018-03-22 11:58:42 +0000 | [diff] [blame] | 39 | |
| 40 | namespace 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. |
| 44 | extern const char* kTempDropBoxTraceDir; |
| 45 | |
| 46 | #if defined(PERFETTO_OS_ANDROID) |
| 47 | using PlatformTaskRunner = base::AndroidTaskRunner; |
| 48 | #else |
| 49 | using PlatformTaskRunner = base::UnixTaskRunner; |
| 50 | #endif |
| 51 | |
| 52 | class PerfettoCmd : public Consumer { |
| 53 | public: |
| 54 | int Main(int argc, char** argv); |
Hector Dearman | 86cfbe1 | 2018-03-22 11:58:42 +0000 | [diff] [blame] | 55 | |
| 56 | // perfetto::Consumer implementation. |
| 57 | void OnConnect() override; |
| 58 | void OnDisconnect() override; |
Primiano Tucci | dca727d | 2018-04-04 11:31:55 +0200 | [diff] [blame] | 59 | void OnTracingDisabled() override; |
Hector Dearman | 86cfbe1 | 2018-03-22 11:58:42 +0000 | [diff] [blame] | 60 | void OnTraceData(std::vector<TracePacket>, bool has_more) override; |
| 61 | |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 62 | int ctrl_c_pipe_wr() const { return *ctrl_c_pipe_wr_; } |
| 63 | |
Hector Dearman | 86cfbe1 | 2018-03-22 11:58:42 +0000 | [diff] [blame] | 64 | private: |
| 65 | bool OpenOutputFile(); |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 66 | void SetupCtrlCSignalHandler(); |
| 67 | void FinalizeTraceAndExit(); |
| 68 | int PrintUsage(const char* argv0); |
| 69 | void OnTimeout(); |
Hector Dearman | 86cfbe1 | 2018-03-22 11:58:42 +0000 | [diff] [blame] | 70 | |
| 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 Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 76 | base::ScopedFile ctrl_c_pipe_wr_; |
| 77 | base::ScopedFile ctrl_c_pipe_rd_; |
Hector Dearman | 86cfbe1 | 2018-03-22 11:58:42 +0000 | [diff] [blame] | 78 | 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_ |