PerfE2EScreenTracesViewController.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "PerfE2EScreenTracesViewController.h"
  15. /** Number of cells in the table view. */
  16. static const NSInteger kNumberOfCellsInTable = 200;
  17. /** Number of sections in the table view. */
  18. static const NSInteger kNumberOfSectionsInTable = 1;
  19. /** Defines X where every Xth cell on load causes a frozen frame. */
  20. static const NSInteger kIntervalOfCellThatCausesFrozenFrame = 15;
  21. /** Duration for which the main thread has to be stalled to deterministically cause a frozen frame.
  22. */
  23. static const NSTimeInterval kThreadSleepDurationForFrozenFrame = 0.9;
  24. /** Duration for which the main thread has to be stalled to deterministically cause a slow frame. */
  25. static const NSTimeInterval kThreadSleepDurationForSlowFrame = 0.05;
  26. @interface PerfE2EScreenTracesViewController ()
  27. @end
  28. @implementation PerfE2EScreenTracesViewController
  29. #pragma mark - Table view data source
  30. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  31. return kNumberOfSectionsInTable;
  32. }
  33. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  34. return kNumberOfCellsInTable;
  35. }
  36. - (UITableViewCell *)tableView:(UITableView *)tableView
  37. cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  38. // Not recycling cells so that this table view is deliberately slow.
  39. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
  40. reuseIdentifier:nil];
  41. cell.textLabel.text = [NSString stringWithFormat:@"%ld", indexPath.row];
  42. cell.accessibilityIdentifier = [NSString stringWithFormat:@"cell_%ld", indexPath.row];
  43. // Adds a manual delay that slows down this method.
  44. if (indexPath.row % kIntervalOfCellThatCausesFrozenFrame == 0) {
  45. [NSThread sleepForTimeInterval:kThreadSleepDurationForFrozenFrame];
  46. } else {
  47. [NSThread sleepForTimeInterval:kThreadSleepDurationForSlowFrame];
  48. }
  49. return cell;
  50. }
  51. @end