OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 | 4 |
5 #import "ios/chrome/browser/memory/memory_debugger.h" | 5 #import "ios/chrome/browser/memory/memory_debugger.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include "base/ios/ios_util.h" | 9 #include "base/ios/ios_util.h" |
8 #import "base/mac/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
9 #import "base/memory/scoped_ptr.h" | 11 #import "base/memory/scoped_ptr.h" |
10 #import "ios/chrome/browser/memory/memory_metrics.h" | 12 #import "ios/chrome/browser/memory/memory_metrics.h" |
11 #include "ios/chrome/browser/ui/ui_util.h" | 13 #include "ios/chrome/browser/ui/ui_util.h" |
12 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 14 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
13 | 15 |
14 namespace { | 16 namespace { |
15 // The number of bytes in a megabyte. | 17 // The number of bytes in a megabyte. |
16 const CGFloat kNumBytesInMB = 1024 * 1024; | 18 const CGFloat kNumBytesInMB = 1024 * 1024; |
(...skipping 16 matching lines...) Expand all Loading... |
33 base::scoped_nsobject<UILabel> _realMemoryUsedLabel; | 35 base::scoped_nsobject<UILabel> _realMemoryUsedLabel; |
34 base::scoped_nsobject<UILabel> _xcodeGaugeLabel; | 36 base::scoped_nsobject<UILabel> _xcodeGaugeLabel; |
35 base::scoped_nsobject<UILabel> _dirtyVirtualMemoryLabel; | 37 base::scoped_nsobject<UILabel> _dirtyVirtualMemoryLabel; |
36 | 38 |
37 // Inputs for memory commands. | 39 // Inputs for memory commands. |
38 base::scoped_nsobject<UITextField> _bloatField; | 40 base::scoped_nsobject<UITextField> _bloatField; |
39 base::scoped_nsobject<UITextField> _refreshField; | 41 base::scoped_nsobject<UITextField> _refreshField; |
40 base::scoped_nsobject<UITextField> _continuousMemoryWarningField; | 42 base::scoped_nsobject<UITextField> _continuousMemoryWarningField; |
41 | 43 |
42 // A place to store the artifical memory bloat. | 44 // A place to store the artifical memory bloat. |
43 scoped_ptr<uint8> _bloat; | 45 scoped_ptr<uint8_t> _bloat; |
44 | 46 |
45 // Distance the view was pushed up to accomodate the keyboard. | 47 // Distance the view was pushed up to accomodate the keyboard. |
46 CGFloat _keyboardOffset; | 48 CGFloat _keyboardOffset; |
47 | 49 |
48 // The current orientation of the device. | 50 // The current orientation of the device. |
49 BOOL _currentOrientation; | 51 BOOL _currentOrientation; |
50 } | 52 } |
51 | 53 |
52 - (instancetype)init { | 54 - (instancetype)init { |
53 self = [super initWithFrame:CGRectZero]; | 55 self = [super initWithFrame:CGRectZero]; |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 bloatSizeMB = 0; | 477 bloatSizeMB = 0; |
476 NSString* errorMessage = | 478 NSString* errorMessage = |
477 [NSString stringWithFormat:@"Invalid value \"%@\" for bloat size.\n" | 479 [NSString stringWithFormat:@"Invalid value \"%@\" for bloat size.\n" |
478 @"Must be a positive number.\n" | 480 @"Must be a positive number.\n" |
479 @"Resetting to %.1f MB", | 481 @"Resetting to %.1f MB", |
480 [_bloatField text], bloatSizeMB]; | 482 [_bloatField text], bloatSizeMB]; |
481 [self alert:errorMessage]; | 483 [self alert:errorMessage]; |
482 [_bloatField setText:[NSString stringWithFormat:@"%.1f", bloatSizeMB]]; | 484 [_bloatField setText:[NSString stringWithFormat:@"%.1f", bloatSizeMB]]; |
483 } | 485 } |
484 const CGFloat kBloatSizeBytes = ceil(bloatSizeMB * kNumBytesInMB); | 486 const CGFloat kBloatSizeBytes = ceil(bloatSizeMB * kNumBytesInMB); |
485 const uint64 kNumberOfBytes = static_cast<uint64>(kBloatSizeBytes); | 487 const uint64_t kNumberOfBytes = static_cast<uint64_t>(kBloatSizeBytes); |
486 _bloat.reset(kNumberOfBytes ? new uint8[kNumberOfBytes] : nullptr); | 488 _bloat.reset(kNumberOfBytes ? new uint8_t[kNumberOfBytes] : nullptr); |
487 if (_bloat) { | 489 if (_bloat) { |
488 memset(_bloat.get(), -1, kNumberOfBytes); // Occupy memory. | 490 memset(_bloat.get(), -1, kNumberOfBytes); // Occupy memory. |
489 } else { | 491 } else { |
490 if (kNumberOfBytes) { | 492 if (kNumberOfBytes) { |
491 [self alert:@"Could not allocate memory."]; | 493 [self alert:@"Could not allocate memory."]; |
492 } | 494 } |
493 } | 495 } |
494 } | 496 } |
495 | 497 |
496 - (void)clearBloat { | 498 - (void)clearBloat { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 - (void)alert:(NSString*)errorMessage { | 593 - (void)alert:(NSString*)errorMessage { |
592 UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Error" | 594 UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Error" |
593 message:errorMessage | 595 message:errorMessage |
594 delegate:self | 596 delegate:self |
595 cancelButtonTitle:@"OK" | 597 cancelButtonTitle:@"OK" |
596 otherButtonTitles:nil, nil]; | 598 otherButtonTitles:nil, nil]; |
597 [alert show]; | 599 [alert show]; |
598 } | 600 } |
599 | 601 |
600 @end | 602 @end |
OLD | NEW |