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

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

Issue 2859353003: [BattOr] Reduce StartTracing time by about four seconds.
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
« no previous file with comments | « tools/battor_agent/battor_agent.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 PerformAction(Action::READ_CALIBRATION_FRAME); 239 PerformAction(Action::READ_CALIBRATION_FRAME);
240 return; 240 return;
241 case Action::SEND_CURRENT_SAMPLE_REQUEST: 241 case Action::SEND_CURRENT_SAMPLE_REQUEST:
242 num_read_attempts_ = 1; 242 num_read_attempts_ = 1;
243 PerformAction(Action::READ_CURRENT_SAMPLE); 243 PerformAction(Action::READ_CURRENT_SAMPLE);
244 return; 244 return;
245 case Action::SEND_GIT_HASH_REQUEST: 245 case Action::SEND_GIT_HASH_REQUEST:
246 num_read_attempts_ = 1; 246 num_read_attempts_ = 1;
247 PerformAction(Action::READ_GIT_HASH); 247 PerformAction(Action::READ_GIT_HASH);
248 return; 248 return;
249 case Action::RESET:
250 CompleteCommand(BATTOR_ERROR_NONE);
251 return;
249 default: 252 default:
250 CompleteCommand(BATTOR_ERROR_UNEXPECTED_MESSAGE); 253 CompleteCommand(BATTOR_ERROR_UNEXPECTED_MESSAGE);
251 } 254 }
252 } 255 }
253 256
254 void BattOrAgent::OnMessageRead(bool success, 257 void BattOrAgent::OnMessageRead(bool success,
255 BattOrMessageType type, 258 BattOrMessageType type,
256 std::unique_ptr<vector<char>> bytes) { 259 std::unique_ptr<vector<char>> bytes) {
257 // Return immediately if whatever action we were trying to perform already 260 // Return immediately if whatever action we were trying to perform already
258 // timed out. 261 // timed out.
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 vector<RawBattOrSample> frame; 402 vector<RawBattOrSample> frame;
400 if (!ParseSampleFrame(type, *bytes, next_sequence_number_++, 403 if (!ParseSampleFrame(type, *bytes, next_sequence_number_++,
401 &frame_header, &frame)) { 404 &frame_header, &frame)) {
402 CompleteCommand(BATTOR_ERROR_UNEXPECTED_MESSAGE); 405 CompleteCommand(BATTOR_ERROR_UNEXPECTED_MESSAGE);
403 return; 406 return;
404 } 407 }
405 408
406 // Check for the empty frame the BattOr uses to indicate it's done 409 // Check for the empty frame the BattOr uses to indicate it's done
407 // streaming samples. 410 // streaming samples.
408 if (frame.empty()) { 411 if (frame.empty()) {
409 CompleteCommand(BATTOR_ERROR_NONE); 412 // Proactively reset the BattOr to speed up the next trace.
charliea (OOO until 10-5) 2017/05/09 19:19:06 I think this could be made clearer: for people stu
aschulman 2017/05/12 22:32:03 agreed. I will do this as best as I can.
413 PerformAction(Action::RESET);
410 return; 414 return;
411 } 415 }
412 416
413 samples_.insert(samples_.end(), frame.begin(), frame.end()); 417 samples_.insert(samples_.end(), frame.begin(), frame.end());
414 418
415 num_read_attempts_ = 1; 419 num_read_attempts_ = 1;
416 PerformAction(Action::READ_DATA_FRAME); 420 PerformAction(Action::READ_DATA_FRAME);
417 return; 421 return;
418 } 422 }
419 423
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 case Action::SEND_GIT_HASH_REQUEST: 533 case Action::SEND_GIT_HASH_REQUEST:
530 connection_->Flush(); 534 connection_->Flush();
531 SendControlMessage( 535 SendControlMessage(
532 BATTOR_CONTROL_MESSAGE_TYPE_GET_FIRMWARE_GIT_HASH, 0, 0); 536 BATTOR_CONTROL_MESSAGE_TYPE_GET_FIRMWARE_GIT_HASH, 0, 0);
533 return; 537 return;
534 538
535 case Action::READ_GIT_HASH: 539 case Action::READ_GIT_HASH:
536 connection_->ReadMessage(BATTOR_MESSAGE_TYPE_CONTROL_ACK); 540 connection_->ReadMessage(BATTOR_MESSAGE_TYPE_CONTROL_ACK);
537 return; 541 return;
538 542
543 case Action::RESET:
544 SendControlMessage(BATTOR_CONTROL_MESSAGE_TYPE_RESET, 0, 0);
545 return;
546
539 case Action::INVALID: 547 case Action::INVALID:
540 NOTREACHED(); 548 NOTREACHED();
541 } 549 }
542 } 550 }
543 551
544 void BattOrAgent::PerformDelayedAction(Action action, base::TimeDelta delay) { 552 void BattOrAgent::PerformDelayedAction(Action action, base::TimeDelta delay) {
545 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 553 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
546 FROM_HERE, base::Bind(&BattOrAgent::PerformAction, AsWeakPtr(), action), 554 FROM_HERE, base::Bind(&BattOrAgent::PerformAction, AsWeakPtr(), action),
547 delay); 555 delay);
548 } 556 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 if (clock_sync_marker != clock_sync_markers_.end()) 669 if (clock_sync_marker != clock_sync_markers_.end())
662 trace_stream << " <" << clock_sync_marker->second << ">"; 670 trace_stream << " <" << clock_sync_marker->second << ">";
663 671
664 trace_stream << std::endl; 672 trace_stream << std::endl;
665 } 673 }
666 674
667 return trace_stream.str(); 675 return trace_stream.str();
668 } 676 }
669 677
670 } // namespace battor 678 } // namespace battor
OLDNEW
« no previous file with comments | « tools/battor_agent/battor_agent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698