@@ -76,6 +76,10 @@ void AndroidAflagsDataSource::Start() {
7676}
7777
7878void AndroidAflagsDataSource::Tick () {
79+ #if !PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID)
80+ PERFETTO_ELOG (" Aflags only supported on Android." );
81+ return ;
82+ #else
7983 auto weak_this = weak_factory_.GetWeakPtr ();
8084 if (poll_period_ms_ > 0 ) {
8185 uint32_t delay_ms =
@@ -95,7 +99,6 @@ void AndroidAflagsDataSource::Tick() {
9599 return ;
96100 }
97101
98- #if PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID)
99102 aflags_output_pipe_ = base::Pipe::Create (base::Pipe::kRdNonBlock );
100103 // Watch the read end of the pipe for output from the aflags process.
101104 task_runner_->AddFileDescriptorWatch (*aflags_output_pipe_->rd , [weak_this] {
@@ -114,38 +117,25 @@ void AndroidAflagsDataSource::Tick() {
114117 aflags_process_->args .out_fd = std::move (aflags_output_pipe_->wr );
115118 aflags_process_->args .stderr_mode = base::Subprocess::OutputMode::kDevNull ;
116119 aflags_process_->Start ();
117- #else
118- PERFETTO_ELOG (" Aflags only supported on Android." );
119120#endif
120121}
121122
122123void AndroidAflagsDataSource::OnAflagsOutput () {
123- char buf[4096 ];
124- for (;;) {
125- ssize_t rsize = base::Read (*aflags_output_pipe_->rd , buf, sizeof (buf));
126- if (rsize == 0 ) {
127- break ; // EOF
128- }
129-
130- if (rsize > 0 ) {
131- aflags_output_.append (buf, static_cast <size_t >(rsize));
132- continue ; // More data may be available, try reading again immediately.
133- }
134-
135- if (base::IsAgain (errno)) {
136- return ; // Read is blocked, wait for the next notification.
137- }
138-
139- PERFETTO_PLOG (" Error reading from aflags output pipe." );
124+ if (base::ReadFileDescriptor (*aflags_output_pipe_->rd , &aflags_output_)) {
140125 task_runner_->RemoveFileDescriptorWatch (*aflags_output_pipe_->rd );
141- aflags_process_.reset ();
142- aflags_output_pipe_.reset ();
143- aflags_output_.clear ();
126+ FinalizeAflagsCapture ();
144127 return ;
145128 }
146129
130+ if (base::IsAgain (errno)) {
131+ return ; // Read is blocked, wait for the next notification.
132+ }
133+
134+ PERFETTO_PLOG (" Error reading from aflags output pipe." );
147135 task_runner_->RemoveFileDescriptorWatch (*aflags_output_pipe_->rd );
148- FinalizeAflagsCapture ();
136+ aflags_process_.reset ();
137+ aflags_output_pipe_.reset ();
138+ aflags_output_.clear ();
149139}
150140
151141void AndroidAflagsDataSource::FinalizeAflagsCapture () {
@@ -167,7 +157,7 @@ void AndroidAflagsDataSource::FinalizeAflagsCapture() {
167157 return ;
168158 }
169159
170- auto returncode = aflags_process_->returncode ();
160+ int returncode = aflags_process_->returncode ();
171161 aflags_process_.reset ();
172162 aflags_output_pipe_.reset ();
173163
@@ -191,8 +181,10 @@ void AndroidAflagsDataSource::FinalizeAflagsCapture() {
191181
192182 TraceWriter::TracePacketHandle packet = writer_->NewTracePacket ();
193183 packet->set_timestamp (static_cast <uint64_t >(base::GetBootTimeNs ().count ()));
194- auto * aflags_proto = packet->set_android_aflags ();
184+ protos::pbzero::AndroidAflags * aflags_proto = packet->set_android_aflags ();
195185 aflags_proto->AppendRawProtoBytes (decoded->data (), decoded->size ());
186+ packet->Finalize ();
187+ writer_->Flush ();
196188}
197189
198190void AndroidAflagsDataSource::Flush (FlushRequestID,
0 commit comments