Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix iOS Mar 2022 Update #728

Merged
merged 1 commit into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

#define STACK_PER_MAX_COUNT 100 // the max address count of one stack

#define SHORTEST_LENGTH_OF_STACK 10

@interface WCMainThreadHandler () {
pthread_mutex_t m_threadLock;
int m_cycleArrayCount;
Expand Down Expand Up @@ -167,8 +165,7 @@ - (KSStackCursor *)getPointStackCursor {
BOOL trueStack = NO;
for (int i = 0; i < m_cycleArrayCount; i++) {
size_t currentValue = m_topStackAddressRepeatArray[i];
int stackCount = (int)m_mainThreadStackCount[i];
if (currentValue >= maxValue && stackCount > SHORTEST_LENGTH_OF_STACK) {
if (currentValue >= maxValue) {
maxValue = currentValue;
trueStack = YES;
}
Expand All @@ -182,8 +179,7 @@ - (KSStackCursor *)getPointStackCursor {
size_t currentIndex = (m_tailPoint + m_cycleArrayCount - 1) % m_cycleArrayCount;
for (int i = 0; i < m_cycleArrayCount; i++) {
int trueIndex = (m_tailPoint + m_cycleArrayCount - i - 1) % m_cycleArrayCount;
int stackCount = (int)m_mainThreadStackCount[trueIndex];
if (m_topStackAddressRepeatArray[trueIndex] == maxValue && stackCount > SHORTEST_LENGTH_OF_STACK) {
if (m_topStackAddressRepeatArray[trueIndex] == maxValue) {
currentIndex = trueIndex;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
- (BOOL)getShouldGetCPUHighLog;
- (BOOL)getShouldGetPowerConsumeStack;
- (float)getPowerConsumeCPULimit;
- (BOOL)getShouldFilterSameStack;
- (uint32_t)getTriggerFilterCount;
- (BOOL)getShouldFilterSameStack DEPRECATED_MSG_ATTRIBUTE("use dumpDailyLimit instead");
- (uint32_t)getTriggerFilterCount DEPRECATED_MSG_ATTRIBUTE("use dumpDailyLimit instead");
- (uint32_t)getDumpDailyLimit;
- (BOOL)getShouldPrintMemoryUse;
- (BOOL)getShouldGetDiskIOStack DEPRECATED_MSG_ATTRIBUTE("feature removed");
- (size_t)getSingleReadLimit DEPRECATED_MSG_ATTRIBUTE("feature removed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ - (uint32_t)getTriggerFilterCount {
return m_currentConfiguration.triggerToBeFilteredCount;
}

- (uint32_t)getDumpDailyLimit {
return m_currentConfiguration.dumpDailyLimit;
}

- (BOOL)getShouldPrintMemoryUse {
return m_currentConfiguration.bPrintMemomryUse;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ const static size_t g_defaultSingleWriteLimit = 100 * 1024;
const static size_t g_defaultTotalReadLimit = 500 * 1024 * 1024;
const static size_t g_defaultTotalWriteLimit = 200 * 1024 * 1024;
const static uint32_t g_defaultMemoryThresholdInMB = 1024;
const static int g_defaultDumpDailyLimit = 100;

@interface WCBlockMonitorConfiguration : NSObject <NSCoding>
@interface WCBlockMonitorConfiguration : NSObject

+ (id)defaultConfig;

Expand Down Expand Up @@ -77,10 +78,13 @@ const static uint32_t g_defaultMemoryThresholdInMB = 1024;
@property (nonatomic, assign) float powerConsumeStackCPULimit;

/// enable to filter the same stack in one day, the stack be captured over "triggerToBeFilteredCount" times would be filtered
@property (nonatomic, assign) BOOL bFilterSameStack;
@property (nonatomic, assign) BOOL bFilterSameStack DEPRECATED_MSG_ATTRIBUTE("use dumpDailyLimit instead");

/// define the count that a stack can be captured in one day, see above "bFilterSameStack"
@property (nonatomic, assign) uint32_t triggerToBeFilteredCount;
@property (nonatomic, assign) uint32_t triggerToBeFilteredCount DEPRECATED_MSG_ATTRIBUTE("use dumpDailyLimit instead");

/// define the max number of lag dump per day
@property (nonatomic, assign) uint32_t dumpDailyLimit;

/// enable printing the memory use
@property (nonatomic, assign) BOOL bPrintMemomryUse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,6 @@

#import "WCBlockMonitorConfiguration.h"

#define kMonitor "Monitor"
#define kRunloopTimeOut "RunloopTimeOut"
#define kRunloopLowThreshold "RunloopLowThreshold"
#define kRunloopDynamicThresholdEnabled "RunloopDynamicThresholdEnabled"
#define kCheckPeriodTime "CheckPeriodTime"
#define kMainThreadHandle "MainThreadHandle"
#define kMainThreadProfile "MainThreadProfile"
#define kPerStackInterval "PerStackInterval"
#define kMainThreadCount "MainThreadCount"
#define kFrameDropLimit "FrameDropLimit"
#define kGetFPSLog "GetFPSLog"
#define kCPUPercentLimit "CPUPercentLimit"
#define kPrintCPUUsage "PrintCPUUsage"
#define kGetCPUHighLog "GetCPUHigh"
#define kGetPowerConsumeStack "GetPowerConsumeStack"
#define kPowerConsumeCPULimit "PowerConsumeCPULimit"
#define kFilterSameStack "FilterSameStack"
#define kTriggerFilteredCount "TriggerFilteredCount"
#define kPrintMemoryUsage "PrintMemoryUse"
#define kGetDiskIOStack "GetDiskIOStack"
#define kSingleReadLimit "SingleReadLimit"
#define kSingleWriteLimit "SingleWriteLimit"
#define kTotalReadLimit "TotalReadLimit"
#define kTotalWriteLimit "TotalWriteLimit"
#define kPrintCPUFrequency "PrintCPUFrequency"
#define kMemoryWarningThresholdInMB "MemoryWarningThresholdInMB"
#define kSensitiveRunloopHangDetection "SensitiveRunloopHangDetection"
#define kSuspendAllThreads "SuspendAllThreads"
#define kEnableSnapshot "EnableSnapshot"

@implementation WCBlockMonitorConfiguration

+ (id)defaultConfig {
Expand All @@ -66,6 +36,7 @@ + (id)defaultConfig {
configuration.powerConsumeStackCPULimit = g_defaultPowerConsumeCPULimit;
configuration.bFilterSameStack = NO;
configuration.triggerToBeFilteredCount = 10;
configuration.dumpDailyLimit = g_defaultDumpDailyLimit;
configuration.bPrintMemomryUse = NO;
configuration.bPrintCPUFrequency = NO;
configuration.bGetDiskIOStack = NO;
Expand All @@ -81,92 +52,22 @@ + (id)defaultConfig {
return configuration;
}

- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super init];
if (self) {
_runloopTimeOut = (useconds_t)[aDecoder decodeInt32ForKey:@kRunloopTimeOut];
_runloopLowThreshold = (useconds_t)[aDecoder decodeInt32ForKey:@kRunloopLowThreshold];
_bRunloopDynamicThreshold = [aDecoder decodeBoolForKey:@kRunloopDynamicThresholdEnabled];
_checkPeriodTime = (useconds_t)[aDecoder decodeInt32ForKey:@kCheckPeriodTime];
_bMainThreadHandle = [aDecoder decodeBoolForKey:@kMainThreadHandle];
_perStackInterval = (useconds_t)[aDecoder decodeInt32ForKey:@kPerStackInterval];
_mainThreadCount = (uint32_t)[aDecoder decodeInt32ForKey:@kMainThreadCount];
_bMainThreadProfile = [aDecoder decodeBoolForKey:@kMainThreadProfile];
_limitCPUPercent = [aDecoder decodeFloatForKey:@kCPUPercentLimit];
_bPrintCPUUsage = [aDecoder decodeBoolForKey:@kPrintCPUUsage];
_bGetCPUHighLog = [aDecoder decodeBoolForKey:@kGetCPUHighLog];
_bGetPowerConsumeStack = [aDecoder decodeBoolForKey:@kGetPowerConsumeStack];
_powerConsumeStackCPULimit = [aDecoder decodeFloatForKey:@kPowerConsumeCPULimit];
_bFilterSameStack = [aDecoder decodeBoolForKey:@kFilterSameStack];
_triggerToBeFilteredCount = (uint32_t)[aDecoder decodeInt32ForKey:@kTriggerFilteredCount];
_bPrintMemomryUse = [aDecoder decodeBoolForKey:@kPrintMemoryUsage];
_bGetDiskIOStack = [aDecoder decodeBoolForKey:@kGetDiskIOStack];
_singleReadLimit = [aDecoder decodeInt64ForKey:@kSingleReadLimit];
_singleWriteLimit = [aDecoder decodeInt64ForKey:@kSingleWriteLimit];
_totalReadLimit = [aDecoder decodeInt64ForKey:@kTotalReadLimit];
_totalWriteLimit = [aDecoder decodeInt64ForKey:@kTotalWriteLimit];
_bPrintCPUFrequency = [aDecoder decodeBoolForKey:@kPrintCPUFrequency];
_memoryWarningThresholdInMB = (uint32_t)[aDecoder decodeInt32ForKey:@kMemoryWarningThresholdInMB];
_bSensitiveRunloopHangDetection = [aDecoder decodeBoolForKey:@kSensitiveRunloopHangDetection];
_bSuspendAllThreads = [aDecoder decodeBoolForKey:@kSuspendAllThreads];
_bEnableSnapshot = [aDecoder decodeBoolForKey:@kEnableSnapshot];
}
return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeInt32:_runloopTimeOut forKey:@kRunloopTimeOut];
[aCoder encodeInt32:_runloopLowThreshold forKey:@kRunloopLowThreshold];
[aCoder encodeBool:_bRunloopDynamicThreshold forKey:@kRunloopDynamicThresholdEnabled];
[aCoder encodeInt32:_checkPeriodTime forKey:@kCheckPeriodTime];
[aCoder encodeBool:_bMainThreadHandle forKey:@kMainThreadHandle];
[aCoder encodeInt32:_perStackInterval forKey:@kPerStackInterval];
[aCoder encodeInt32:_mainThreadCount forKey:@kMainThreadCount];
[aCoder encodeBool:_bMainThreadProfile forKey:@kMainThreadProfile];
[aCoder encodeFloat:_limitCPUPercent forKey:@kCPUPercentLimit];
[aCoder encodeBool:_bPrintCPUUsage forKey:@kPrintCPUUsage];
[aCoder encodeBool:_bGetCPUHighLog forKey:@kGetCPUHighLog];
[aCoder encodeBool:_bGetPowerConsumeStack forKey:@kGetPowerConsumeStack];
[aCoder encodeFloat:_powerConsumeStackCPULimit forKey:@kPowerConsumeCPULimit];
[aCoder encodeBool:_bFilterSameStack forKey:@kFilterSameStack];
[aCoder encodeInt32:_triggerToBeFilteredCount forKey:@kTriggerFilteredCount];
[aCoder encodeBool:_bPrintMemomryUse forKey:@kPrintMemoryUsage];
[aCoder encodeBool:_bGetDiskIOStack forKey:@kGetDiskIOStack];
[aCoder encodeInt64:_singleReadLimit forKey:@kSingleReadLimit];
[aCoder encodeInt64:_singleWriteLimit forKey:@kSingleWriteLimit];
[aCoder encodeInt64:_totalReadLimit forKey:@kTotalReadLimit];
[aCoder encodeInt64:_totalWriteLimit forKey:@kTotalWriteLimit];
[aCoder encodeBool:_bPrintCPUFrequency forKey:@kPrintCPUFrequency];
[aCoder encodeInt32:_memoryWarningThresholdInMB forKey:@kMemoryWarningThresholdInMB];
[aCoder encodeBool:_bSensitiveRunloopHangDetection forKey:@kSensitiveRunloopHangDetection];
[aCoder encodeBool:_bSuspendAllThreads forKey:@kSuspendAllThreads];
[aCoder encodeBool:_bEnableSnapshot forKey:@kEnableSnapshot];
}

- (NSString *)description {
NSDictionary *properties = @{
@"runloopTimeOut": @(self.runloopTimeOut),
@"runloopLowThreshold": @(self.runloopLowThreshold),
@"bRunloopDynamicThreshold": @(self.bRunloopDynamicThreshold),
@"checkPeriodTime": @(self.checkPeriodTime),
@"bMainThreadHandle": @(self.bMainThreadHandle),
@"perStackInterval": @(self.perStackInterval),
@"mainThreadCount": @(self.mainThreadCount),
@"bMainThreadProfile": @(self.bMainThreadProfile),
@"limitCPUPercent": @(self.limitCPUPercent),
@"bPrintCPUUsage": @(self.bPrintCPUUsage),
@"bGetCPUHighLog": @(self.bGetCPUHighLog),
@"bGetPowerConsumeStack": @(self.bGetPowerConsumeStack),
@"powerConsumeStackCPULimit": @(self.powerConsumeStackCPULimit),
@"bFilterSameStack": @(self.bFilterSameStack),
@"triggerToBeFilteredCount": @(self.triggerToBeFilteredCount),
@"dumpDailyLimit": @(self.dumpDailyLimit),
@"bPrintMemomryUse": @(self.bPrintMemomryUse),
@"bPrintCPUFrequency": @(self.bPrintCPUFrequency),
@"bGetDiskIOStack": @(self.bGetDiskIOStack),
@"singleReadLimit": @(self.singleReadLimit),
@"singleWriteLimit": @(self.singleWriteLimit),
@"totalReadLimit": @(self.totalReadLimit),
@"totalWriteLimit": @(self.totalWriteLimit),
@"memoryWarningThresholdInMB": @(self.memoryWarningThresholdInMB),
@"bSensitiveRunloopHangDetection": @(self.bSensitiveRunloopHangDetection),
@"bSuspendAllThreads": @(self.bSuspendAllThreads),
Expand Down
Loading