Skip to content

Commit

Permalink
Log db write transactions taking more than 0.5s
Browse files Browse the repository at this point in the history
  • Loading branch information
tmolitor-stud-tu committed Dec 25, 2023
1 parent 9e189f4 commit 9ad5467
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Monal/Classes/HelperTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void swizzle(Class c, SEL orig, SEL new);
+(void) postError:(NSString*) description withNode:(XMPPStanza* _Nullable) node andAccount:(xmpp*) account andIsSevere:(BOOL) isSevere andDisableAccount:(BOOL) disableAccount;
+(void) postError:(NSString*) description withNode:(XMPPStanza* _Nullable) node andAccount:(xmpp*) account andIsSevere:(BOOL) isSevere;
+(NSString*) extractXMPPError:(XMPPStanza*) stanza withDescription:(NSString* _Nullable) description;
+(void) showErrorOnAlpha:(NSString*) description withNode:(XMPPStanza* _Nullable) node andAccount:(xmpp*) account andFile:(char*) file andLine:(int) line andFunc:(char*) func;
+(void) showErrorOnAlpha:(NSString*) description withNode:(XMPPStanza* _Nullable) node andAccount:(xmpp* _Nullable) account andFile:(char*) file andLine:(int) line andFunc:(char*) func;

+(NSDictionary<NSString*, NSString*>*) getInvalidPushServers;
+(NSString*) getSelectedPushServerBasedOnLocale;
Expand Down
18 changes: 15 additions & 3 deletions Monal/Classes/HelperTools.m
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,30 @@ +(void) postError:(NSString*) description withNode:(XMPPStanza* _Nullable) node
[[MLNotificationQueue currentQueue] postNotificationName:kXMPPError object:account userInfo:@{@"message": message, @"isSevere":@(isSevere)}];
}

+(void) showErrorOnAlpha:(NSString*) description withNode:(XMPPStanza* _Nullable) node andAccount:(xmpp*) account andFile:(char*) file andLine:(int) line andFunc:(char*) func
+(void) showErrorOnAlpha:(NSString*) description withNode:(XMPPStanza* _Nullable) node andAccount:(xmpp* _Nullable) account andFile:(char*) file andLine:(int) line andFunc:(char*) func
{
NSString* fileStr = [NSString stringWithFormat:@"%s", file];
NSArray* filePathComponents = [fileStr pathComponents];
if([filePathComponents count]>1)
fileStr = [NSString stringWithFormat:@"%@/%@", filePathComponents[[filePathComponents count]-2], filePathComponents[[filePathComponents count]-1]];
NSString* message = description;
if(node)
message = [HelperTools extractXMPPError:node withDescription:description];
message = [self extractXMPPError:node withDescription:description];
#ifdef IS_ALPHA
DDLogError(@"Notifying alpha user about error at %@:%d in %s: %@", fileStr, line, func, message);
[[MLNotificationQueue currentQueue] postNotificationName:kXMPPError object:account userInfo:@{@"message": message, @"isSevere":@YES}];
if(account != nil)
[[MLNotificationQueue currentQueue] postNotificationName:kXMPPError object:account userInfo:@{@"message": message, @"isSevere":@YES}];
else
{
UNMutableNotificationContent* content = [UNMutableNotificationContent new];
content.title = @"Global Error";
content.body = message;
content.sound = [UNNotificationSound defaultSound];
UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:[[NSUUID UUID] UUIDString] content:content trigger:nil];
NSError* error = [self postUserNotificationRequest:request];
if(error)
DDLogError(@"Error posting global alpha xmppError notification: %@", error);
}
#else
DDLogWarn(@"Ignoring alpha-only error at %@:%d in %s: %@", fileStr, line, func, message);
#endif
Expand Down
4 changes: 4 additions & 0 deletions Monal/Classes/MLSQLite.m
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,12 @@ -(BOOL) boolWriteTransaction:(monal_sqlite_bool_operations_t) operations
-(id) idWriteTransaction:(monal_sqlite_operations_t) operations
{
[self beginWriteTransaction];
NSDate* startTime = [NSDate date];
id retval = operations();
NSDate* endTime = [NSDate date];
[self endWriteTransaction];
if([endTime timeIntervalSinceDate:startTime] > 0.5)
showErrorOnAlpha(nil, [NSString stringWithFormat:@"Write transaction took %fs (longer than 0.5s): %@", [endTime timeIntervalSinceDate:startTime], [NSThread callStackSymbols]]);
return retval;
}

Expand Down

0 comments on commit 9ad5467

Please sign in to comment.