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

Side by Side Diff: tools/battor_agent/battor_agent.cc

Issue 2859353003: [BattOr] Reduce StartTracing time by about four seconds.
Patch Set: Fixed test cases Created 3 years, 6 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 #include "tools/battor_agent/battor_agent.h" 4 #include "tools/battor_agent/battor_agent.h"
5 5
6 #include <iomanip> 6 #include <iomanip>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "tools/battor_agent/battor_connection_impl.h" 10 #include "tools/battor_agent/battor_connection_impl.h"
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 return; 219 return;
220 case Action::SEND_SAMPLES_REQUEST: 220 case Action::SEND_SAMPLES_REQUEST:
221 PerformAction(Action::READ_CALIBRATION_FRAME); 221 PerformAction(Action::READ_CALIBRATION_FRAME);
222 return; 222 return;
223 case Action::SEND_CURRENT_SAMPLE_REQUEST: 223 case Action::SEND_CURRENT_SAMPLE_REQUEST:
224 PerformAction(Action::READ_CURRENT_SAMPLE); 224 PerformAction(Action::READ_CURRENT_SAMPLE);
225 return; 225 return;
226 case Action::SEND_GIT_HASH_REQUEST: 226 case Action::SEND_GIT_HASH_REQUEST:
227 PerformAction(Action::READ_GIT_HASH); 227 PerformAction(Action::READ_GIT_HASH);
228 return; 228 return;
229 case Action::RESET:
230 CompleteCommand(BATTOR_ERROR_NONE);
231 return;
229 default: 232 default:
230 NOTREACHED(); 233 NOTREACHED();
231 return; 234 return;
232 } 235 }
233 } 236 }
234 237
235 void BattOrAgent::OnMessageRead(bool success, 238 void BattOrAgent::OnMessageRead(bool success,
236 BattOrMessageType type, 239 BattOrMessageType type,
237 std::unique_ptr<vector<char>> bytes) { 240 std::unique_ptr<vector<char>> bytes) {
238 if (!success) { 241 if (!success) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 RetryCommand(); 348 RetryCommand();
346 return; 349 return;
347 } 350 }
348 351
349 // Check for the empty frame the BattOr uses to indicate it's done 352 // Check for the empty frame the BattOr uses to indicate it's done
350 // streaming samples. 353 // streaming samples.
351 if (frame.empty()) { 354 if (frame.empty()) {
352 // Cancel the next data frame timeout. 355 // Cancel the next data frame timeout.
353 timeout_callback_.Cancel(); 356 timeout_callback_.Cancel();
354 CompleteCommand(BATTOR_ERROR_NONE); 357 CompleteCommand(BATTOR_ERROR_NONE);
358
359 // Proactively reset the BattOr to speed up the next trace.
360 //
361 // Without this proactive reset, the BattOr will take several seconds
362 // to automatically reset the next time that a trace is started. By
363 // proactively resetting the BattOr now, before the trace is printed by
364 // the agent, the reset is parallelized with the final processing of
365 // this trace by the agent. Thus the BattOr will be ready to start
366 // the next trace immediately.
367 PerformAction(Action::RESET);
355 return; 368 return;
356 } 369 }
357 370
358 samples_.insert(samples_.end(), frame.begin(), frame.end()); 371 samples_.insert(samples_.end(), frame.begin(), frame.end());
359 372
360 PerformAction(Action::READ_DATA_FRAME); 373 PerformAction(Action::READ_DATA_FRAME);
361 return; 374 return;
362 } 375 }
363 376
364 case Action::READ_CURRENT_SAMPLE: 377 case Action::READ_CURRENT_SAMPLE:
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 481
469 case Action::SEND_GIT_HASH_REQUEST: 482 case Action::SEND_GIT_HASH_REQUEST:
470 SendControlMessage( 483 SendControlMessage(
471 BATTOR_CONTROL_MESSAGE_TYPE_GET_FIRMWARE_GIT_HASH, 0, 0); 484 BATTOR_CONTROL_MESSAGE_TYPE_GET_FIRMWARE_GIT_HASH, 0, 0);
472 return; 485 return;
473 486
474 case Action::READ_GIT_HASH: 487 case Action::READ_GIT_HASH:
475 connection_->ReadMessage(BATTOR_MESSAGE_TYPE_CONTROL_ACK); 488 connection_->ReadMessage(BATTOR_MESSAGE_TYPE_CONTROL_ACK);
476 return; 489 return;
477 490
491 case Action::RESET:
492 SendControlMessage(BATTOR_CONTROL_MESSAGE_TYPE_RESET, 0, 0);
493 return;
494
478 case Action::INVALID: 495 case Action::INVALID:
479 NOTREACHED(); 496 NOTREACHED();
480 return; 497 return;
481 } 498 }
482 } 499 }
483 500
484 void BattOrAgent::PerformDelayedAction(Action action, base::TimeDelta delay) { 501 void BattOrAgent::PerformDelayedAction(Action action, base::TimeDelta delay) {
485 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 502 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
486 FROM_HERE, base::Bind(&BattOrAgent::PerformAction, AsWeakPtr(), action), 503 FROM_HERE, base::Bind(&BattOrAgent::PerformAction, AsWeakPtr(), action),
487 delay); 504 delay);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 641
625 void BattOrAgent::SetActionTimeout(uint16_t timeout_seconds) { 642 void BattOrAgent::SetActionTimeout(uint16_t timeout_seconds) {
626 timeout_callback_.Reset( 643 timeout_callback_.Reset(
627 base::Bind(&BattOrAgent::OnActionTimeout, AsWeakPtr())); 644 base::Bind(&BattOrAgent::OnActionTimeout, AsWeakPtr()));
628 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 645 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
629 FROM_HERE, timeout_callback_.callback(), 646 FROM_HERE, timeout_callback_.callback(),
630 base::TimeDelta::FromSeconds(timeout_seconds)); 647 base::TimeDelta::FromSeconds(timeout_seconds));
631 } 648 }
632 649
633 } // namespace battor 650 } // namespace battor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698