7070#import " OASearchHistorySettingsItem.h"
7171#import " OATileSource.h"
7272#import " OAPluginsHelper.h"
73+ #import " OABackupHelper.h"
74+ #import " OAOperationLog.h"
7375
7476#include < OsmAndCore/Map/IOnlineTileSources.h>
7577#include < OsmAndCore/Map/OnlineTileSources.h>
@@ -90,6 +92,9 @@ @implementation OASettingsHelper
9092{
9193 __weak OAImportSettingsViewController *_importDataVC;
9294 NSInteger _currentBackupVersion;
95+
96+ // COLLECT_LOCAL_DIAG: remove after cloud sync performance investigation.
97+ OAOperationLog *_cloudSyncOperationLog;
9398}
9499
95100+ (OASettingsHelper *) sharedInstance
@@ -108,6 +113,7 @@ - (instancetype)init
108113 if (self)
109114 {
110115 _currentBackupVersion = kVersion ;
116+ _cloudSyncOperationLog = [[OAOperationLog alloc ] initWithOperationName: @" cloudSyncSettings" debug: BACKUP_DEBUG_LOGS ];
111117 }
112118 return self;
113119}
@@ -224,12 +230,30 @@ - (void) exportSettings:(NSString *)fileDir fileName:(NSString *)fileName settin
224230
225231- (NSArray <OASettingsItem *> *) getFilteredSettingsItems : (NSArray <OAExportSettingsType *> *)settingsTypes addProfiles : (BOOL )addProfiles doExport : (BOOL )doExport
226232{
233+ [_cloudSyncOperationLog startOperation: @" COLLECT_LOCAL_DIAG getFilteredSettingsItems" ];
234+ CFAbsoluteTime phaseStartTime = CFAbsoluteTimeGetCurrent ();
227235 NSMutableDictionary <OAExportSettingsType *, NSArray *> *typesMap = [NSMutableDictionary new ];
228236 [typesMap addEntriesFromDictionary: [self getSettingsItems: addProfiles]];
237+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG getSettingsItems END duration=%.3f ms" ,
238+ (CFAbsoluteTimeGetCurrent () - phaseStartTime) * 1000 ]];
239+
240+ phaseStartTime = CFAbsoluteTimeGetCurrent ();
229241 [typesMap addEntriesFromDictionary: [self getMyPlacesItems: NO ]];
242+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG getMyPlacesItems END duration=%.3f ms" ,
243+ (CFAbsoluteTimeGetCurrent () - phaseStartTime) * 1000 ]];
244+
245+ phaseStartTime = CFAbsoluteTimeGetCurrent ();
230246 [typesMap addEntriesFromDictionary: [self getResourcesItems ]];
231-
232- return [self getFilteredSettingsItems: typesMap settingsTypes: settingsTypes settingsItems: @[] doExport: doExport];
247+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG getResourcesItems END duration=%.3f ms" ,
248+ (CFAbsoluteTimeGetCurrent () - phaseStartTime) * 1000 ]];
249+
250+ phaseStartTime = CFAbsoluteTimeGetCurrent ();
251+ NSArray <OASettingsItem *> *result = [self getFilteredSettingsItems: typesMap settingsTypes: settingsTypes settingsItems: @[] doExport: doExport];
252+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG prepareFilteredItems END duration=%.3f ms count=%ld " ,
253+ (CFAbsoluteTimeGetCurrent () - phaseStartTime) * 1000 ,
254+ result.count]];
255+ [_cloudSyncOperationLog finishOperation: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG items=%ld " , result.count]];
256+ return result;
233257}
234258
235259- (NSArray <OASettingsItem *> *) getFilteredSettingsItems : (NSDictionary <OAExportSettingsType *, NSArray *> *)allSettingsMap
@@ -243,7 +267,14 @@ - (void) exportSettings:(NSString *)fileDir fileName:(NSString *)fileName settin
243267 NSArray *settingsDataObjects = allSettingsMap[settingsType];
244268 if (settingsDataObjects != nil )
245269 {
246- [filteredSettingsItems addObjectsFromArray: [self prepareSettingsItems: settingsDataObjects settingsItems: settingsItems doExport: doExport]];
270+ CFAbsoluteTime typeStartTime = CFAbsoluteTimeGetCurrent ();
271+ NSArray <OASettingsItem *> *preparedItems = [self prepareSettingsItems: settingsDataObjects settingsItems: settingsItems doExport: doExport];
272+ [filteredSettingsItems addObjectsFromArray: preparedItems];
273+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG prepareSettingsItems type=%@ duration=%.3f ms input=%ld output=%ld " ,
274+ settingsType.name,
275+ (CFAbsoluteTimeGetCurrent () - typeStartTime) * 1000 ,
276+ settingsDataObjects.count,
277+ preparedItems.count]];
247278 }
248279 }
249280 return filteredSettingsItems;
@@ -269,6 +300,8 @@ - (void) exportSettings:(NSString *)fileDir fileName:(NSString *)fileName settin
269300
270301- (NSDictionary <OAExportSettingsType *, NSArray *> *) getSettingsItems : (BOOL )addProfiles
271302{
303+ CFAbsoluteTime methodStartTime = CFAbsoluteTimeGetCurrent ();
304+ CFAbsoluteTime phaseStartTime = methodStartTime;
272305 MutableOrderedDictionary<OAExportSettingsType *, NSArray *> *settingsItems = [MutableOrderedDictionary new ];
273306
274307 if (addProfiles)
@@ -281,7 +314,10 @@ - (void) exportSettings:(NSString *)fileDir fileName:(NSString *)fileName settin
281314 settingsItems[OAExportSettingsType.PROFILE ] = appModeBeans;
282315 }
283316 settingsItems[OAExportSettingsType.GLOBAL ] = @[[[OAGlobalSettingsItem alloc ] init ]];
317+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG settings profiles/global duration=%.3f ms" ,
318+ (CFAbsoluteTimeGetCurrent () - phaseStartTime) * 1000 ]];
284319
320+ phaseStartTime = CFAbsoluteTimeGetCurrent ();
285321 OAMapButtonsHelper *buttonsHelper = [OAMapButtonsHelper sharedInstance ];
286322 NSArray <QuickActionButtonState *> *buttonStates = [buttonsHelper getButtonsStates ];
287323 if (buttonStates.count == 1 )
@@ -297,15 +333,24 @@ - (void) exportSettings:(NSString *)fileDir fileName:(NSString *)fileName settin
297333 NSArray <QuickActionButtonState *> *actionsList = [registry getButtonsStates ];
298334 if (actionsList.count > 0 )
299335 settingsItems[OAExportSettingsType.QUICK_ACTIONS ] = actionsList;
336+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG settings quickActions duration=%.3f ms count=%ld " ,
337+ (CFAbsoluteTimeGetCurrent () - phaseStartTime) * 1000 ,
338+ actionsList.count]];
300339
340+ phaseStartTime = CFAbsoluteTimeGetCurrent ();
301341 NSArray <OAPOIUIFilter *> *poiList = [OAPOIFiltersHelper.sharedInstance getUserDefinedPoiFilters: NO ];
302342 if (poiList.count > 0 )
303343 settingsItems[OAExportSettingsType.POI_TYPES ] = poiList;
304344
305345 NSArray <OAAvoidRoadInfo *> *impassableRoads = OAAvoidSpecificRoads.instance .getImpassableRoads ;
306346 if (impassableRoads.count > 0 )
307347 settingsItems[OAExportSettingsType.AVOID_ROADS ] = impassableRoads;
348+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG settings poi/avoidRoads duration=%.3f ms poi=%ld roads=%ld " ,
349+ (CFAbsoluteTimeGetCurrent () - phaseStartTime) * 1000 ,
350+ poiList.count,
351+ impassableRoads.count]];
308352
353+ phaseStartTime = CFAbsoluteTimeGetCurrent ();
309354 NSFileManager *fileManager = NSFileManager .defaultManager ;
310355 BOOL isDir = NO ;
311356 NSString *colorPaletteFolder = [OsmAndApp instance ].colorsPalettePath ;
@@ -345,17 +390,27 @@ - (void) exportSettings:(NSString *)fileDir fileName:(NSString *)fileName settin
345390 }
346391 }
347392
393+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG settings colorPalette duration=%.3f ms" ,
394+ (CFAbsoluteTimeGetCurrent () - phaseStartTime) * 1000 ]];
395+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG settings TOTAL duration=%.3f ms" ,
396+ (CFAbsoluteTimeGetCurrent () - methodStartTime) * 1000 ]];
348397 return settingsItems;
349398}
350399
351400- (NSDictionary <OAExportSettingsType *, NSArray *> *)getMyPlacesItems : (BOOL )sorted
352401{
402+ CFAbsoluteTime methodStartTime = CFAbsoluteTimeGetCurrent ();
403+ CFAbsoluteTime phaseStartTime = methodStartTime;
353404 MutableOrderedDictionary<OAExportSettingsType *, NSArray *> *myPlacesItems = [MutableOrderedDictionary new ];
354405
355406 NSArray <OAFavoriteGroup *> *favoriteGroups = [OAFavoritesHelper getFavoriteGroups ];
356407 if (favoriteGroups.count > 0 )
357408 myPlacesItems[OAExportSettingsType.FAVORITES ] = favoriteGroups;
409+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG myPlaces favorites duration=%.3f ms count=%ld " ,
410+ (CFAbsoluteTimeGetCurrent () - phaseStartTime) * 1000 ,
411+ favoriteGroups.count]];
358412
413+ phaseStartTime = CFAbsoluteTimeGetCurrent ();
359414 NSFileManager *fileManager = NSFileManager .defaultManager ;
360415 NSArray <OASGpxDataItem *> *gpsDataItems;
361416 if (sorted)
@@ -384,7 +439,11 @@ - (void) exportSettings:(NSString *)fileDir fileName:(NSString *)fileName settin
384439 if (files.count > 0 )
385440 myPlacesItems[OAExportSettingsType.TRACKS ] = files;
386441 }
442+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG myPlaces tracks duration=%.3f ms count=%ld " ,
443+ (CFAbsoluteTimeGetCurrent () - phaseStartTime) * 1000 ,
444+ gpsDataItems.count]];
387445
446+ phaseStartTime = CFAbsoluteTimeGetCurrent ();
388447 OAOsmEditingPlugin *osmEditingPlugin = (OAOsmEditingPlugin *) [OAPluginsHelper getPlugin: OAOsmEditingPlugin.class ];
389448 if (osmEditingPlugin)
390449 {
@@ -395,6 +454,9 @@ - (void) exportSettings:(NSString *)fileDir fileName:(NSString *)fileName settin
395454 if (editsPointList.count > 0 )
396455 myPlacesItems[OAExportSettingsType.OSM_EDITS ] = editsPointList;
397456 }
457+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG myPlaces osm duration=%.3f ms enabled=%d " ,
458+ (CFAbsoluteTimeGetCurrent () - phaseStartTime) * 1000 ,
459+ osmEditingPlugin != nil ]];
398460 // TODO: implement after adding Audio/video notes
399461// AudioVideoNotesPlugin plugin = OsmandPlugin.getPlugin(AudioVideoNotesPlugin.class);
400462// if (plugin != null) {
@@ -409,6 +471,7 @@ - (void) exportSettings:(NSString *)fileDir fileName:(NSString *)fileName settin
409471// myPlacesItems.put(ExportSettingsType.MULTIMEDIA_NOTES, files);
410472// }
411473// }
474+ phaseStartTime = CFAbsoluteTimeGetCurrent ();
412475 NSArray <OADestination *> *mapMarkers = [OADestinationsHelper.instance sortedDestinationsWithoutParking ];
413476 if (mapMarkers.count > 0 )
414477 {
@@ -437,12 +500,22 @@ - (void) exportSettings:(NSString *)fileDir fileName:(NSString *)fileName settin
437500 NSArray <OAHistoryItem *> *navigationHistoryEntries = [historyHelper getPointsFromNavigation: 0 ];
438501 if (navigationHistoryEntries.count > 0 )
439502 myPlacesItems[OAExportSettingsType.NAVIGATION_HISTORY ] = navigationHistoryEntries;
440-
503+
504+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG myPlaces markers/history duration=%.3f ms markers=%ld history=%ld /%ld /%ld " ,
505+ (CFAbsoluteTimeGetCurrent () - phaseStartTime) * 1000 ,
506+ mapMarkers.count,
507+ markersHistory.count,
508+ searchHistoryEntries.count,
509+ navigationHistoryEntries.count]];
510+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG myPlaces TOTAL duration=%.3f ms" ,
511+ (CFAbsoluteTimeGetCurrent () - methodStartTime) * 1000 ]];
441512 return myPlacesItems;
442513}
443514
444515- (NSDictionary <OAExportSettingsType *, NSArray *> *)getResourcesItems
445516{
517+ CFAbsoluteTime methodStartTime = CFAbsoluteTimeGetCurrent ();
518+ CFAbsoluteTime phaseStartTime = methodStartTime;
446519 MutableOrderedDictionary<OAExportSettingsType *, NSArray *> *resourcesItems = [MutableOrderedDictionary new ];
447520
448521 NSArray <NSString *> *mapStyleFiles = [OARendererRegistry getPathExternalRenderers ];
@@ -465,11 +538,14 @@ - (void) exportSettings:(NSString *)fileDir fileName:(NSString *)fileName settin
465538 if (items.count > 0 )
466539 resourcesItems[OAExportSettingsType.CUSTOM_ROUTING ] = items;
467540 }
541+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG resources renderers/routing duration=%.3f ms" ,
542+ (CFAbsoluteTimeGetCurrent () - phaseStartTime) * 1000 ]];
468543// List<OnlineRoutingEngine> onlineRoutingEngines = app.getOnlineRoutingHelper().getEngines();
469544// if (!Algorithms.isEmpty(onlineRoutingEngines)) {
470545// resourcesItems.put(ExportSettingsType.ONLINE_ROUTING_ENGINES, onlineRoutingEngines);
471546// }
472547 // TODO: implement export!
548+ phaseStartTime = CFAbsoluteTimeGetCurrent ();
473549 NSMutableArray <OATileSource *> *tileSources = [NSMutableArray new ];
474550 NSArray <OAResourceItem *> *tileResources = [OAResourcesUIHelper getSortedRasterMapSources: YES ];
475551 for (OAResourceItem *res in tileResources)
@@ -492,7 +568,12 @@ - (void) exportSettings:(NSString *)fileDir fileName:(NSString *)fileName settin
492568 }
493569 if (tileSources.count > 0 )
494570 resourcesItems[OAExportSettingsType.MAP_SOURCES ] = tileSources;
571+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG resources rasterSources duration=%.3f ms resources=%ld sources=%ld " ,
572+ (CFAbsoluteTimeGetCurrent () - phaseStartTime) * 1000 ,
573+ tileResources.count,
574+ tileSources.count]];
495575
576+ phaseStartTime = CFAbsoluteTimeGetCurrent ();
496577 QSet<OsmAnd::ResourcesManager::ResourceType> types;
497578 types << OsmAnd::ResourcesManager::ResourceType::MapRegion;
498579 NSArray <NSString *> *localIndexFiles = [OAResourcesUIHelper getInstalledResourcePathsByTypes: types includeHidden: NO ];
@@ -503,7 +584,11 @@ - (void) exportSettings:(NSString *)fileDir fileName:(NSString *)fileName settin
503584 }];
504585 resourcesItems[OAExportSettingsType.STANDARD_MAPS ] = sortedFiles;
505586 }
587+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG resources standardMaps duration=%.3f ms count=%ld " ,
588+ (CFAbsoluteTimeGetCurrent () - phaseStartTime) * 1000 ,
589+ localIndexFiles.count]];
506590
591+ phaseStartTime = CFAbsoluteTimeGetCurrent ();
507592 QSet<OsmAnd::ResourcesManager::ResourceType> wikiTypes;
508593 wikiTypes << OsmAnd::ResourcesManager::ResourceType::WikiMapRegion;
509594 wikiTypes << OsmAnd::ResourcesManager::ResourceType::Travel;
@@ -515,7 +600,11 @@ - (void) exportSettings:(NSString *)fileDir fileName:(NSString *)fileName settin
515600 }];
516601 resourcesItems[OAExportSettingsType.WIKI_AND_TRAVEL ] = sortedFiles;
517602 }
603+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG resources wikiTravel duration=%.3f ms count=%ld " ,
604+ (CFAbsoluteTimeGetCurrent () - phaseStartTime) * 1000 ,
605+ wikiFiles.count]];
518606
607+ phaseStartTime = CFAbsoluteTimeGetCurrent ();
519608 QSet<OsmAnd::ResourcesManager::ResourceType> nauticalTypes;
520609 nauticalTypes << OsmAnd::ResourcesManager::ResourceType::DepthMapRegion;
521610 NSArray <NSString *> *nauticalFiles = [OAResourcesUIHelper getInstalledResourcePathsByTypes: nauticalTypes includeHidden: NO ];
@@ -526,7 +615,11 @@ - (void) exportSettings:(NSString *)fileDir fileName:(NSString *)fileName settin
526615 }];
527616 resourcesItems[OAExportSettingsType.DEPTH_DATA ] = sortedFiles;
528617 }
618+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG resources nautical duration=%.3f ms count=%ld " ,
619+ (CFAbsoluteTimeGetCurrent () - phaseStartTime) * 1000 ,
620+ nauticalFiles.count]];
529621
622+ phaseStartTime = CFAbsoluteTimeGetCurrent ();
530623 QSet<OsmAnd::ResourcesManager::ResourceType> terrainTypes;
531624 terrainTypes << OsmAnd::ResourcesManager::ResourceType::SrtmMapRegion;
532625 terrainTypes << OsmAnd::ResourcesManager::ResourceType::HillshadeRegion;
@@ -540,6 +633,9 @@ - (void) exportSettings:(NSString *)fileDir fileName:(NSString *)fileName settin
540633 }];
541634 resourcesItems[OAExportSettingsType.TERRAIN_DATA ] = sortedFiles;
542635 }
636+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG resources terrain duration=%.3f ms count=%ld " ,
637+ (CFAbsoluteTimeGetCurrent () - phaseStartTime) * 1000 ,
638+ terrainFiles.count]];
543639
544640// files = getFilesByType(localIndexInfoList, LocalIndexType.TTS_VOICE_DATA);
545641// if (!files.isEmpty()) {
@@ -550,6 +646,8 @@ - (void) exportSettings:(NSString *)fileDir fileName:(NSString *)fileName settin
550646// resourcesItems.put(ExportSettingsType.VOICE, files);
551647// }
552648
649+ [_cloudSyncOperationLog log: [NSString stringWithFormat: @" COLLECT_LOCAL_DIAG resources TOTAL duration=%.3f ms" ,
650+ (CFAbsoluteTimeGetCurrent () - methodStartTime) * 1000 ]];
553651 return resourcesItems;
554652}
555653
0 commit comments