01234567890123456789012345678901234567890123456789012345678901234567890123456789
71937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236 741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453 | <----SKIPPED LINES----> tracemalloc.start(initial_frame_count) startup_time = time.time() json_desc_dict = {} init_timing.append((time.time(), 3)) flights = UnpickleObjectFromFile( PICKLE_FLIGHTS, True, max_days=MAX_INSIGHT_HORIZON_DAYS, heartbeat=True) # Clear the loaded flight of any cached data, identified by keys # with a specific suffix, since code fixes may change the values for # some of those cached elements init_timing.append((time.time(), 4)) for flight in flights: for key in list(flight.keys()): if key.endswith(CACHED_ELEMENT_PREFIX): flight.pop(key) init_timing.append((time.time(), 5)) # We have no use for the memory-hogging persistent_path key of historical # flights, so let's remove all those keys and save a lot of memory # TODO: On 2022-10-31, commented out anything deleting persistent path if flights: for flight in flights[:-1]: if 'persistent_path' in flight: del flight['persistent_path'] screen_history = UnpickleObjectFromFile(PICKLE_SCREENS, True, max_days=2) # If we're displaying just a single insight message, we want it to be # something unique, to the extent possible; this dict holds a count of # the diff types of messages displayed so far insight_message_distribution = {} # bootstrap the flight insights distribution from a list of insights on each # flight (i.e.: flight['insight_types'] for a given flight might look like # [1, 2, 7, 9], or [], to indicate which insights were identified; this then # transforms that into {0: 25, 1: 18, ...} summing across all flights. missing_insights = [] for flight in flights: if 'insight_types' not in flight: missing_insights.append('%s on %s' % ( DisplayFlightNumber(flight), DisplayTime(flight, '%x %X'))) distribution = flight.get('insight_types', []) for key in distribution: insight_message_distribution[key] = ( <----SKIPPED LINES----> 'time_flight_message_inserted': time_flight_message_inserted, 'time_insight_message_inserted': time_insight_message_inserted}) PickleObjectToFile(data, PICKLE_FLIGHT_DASHBOARD, True) else: remote, servo = RefreshArduinos( remote, servo, to_remote_q, to_servo_q, to_main_q, shutdown, flights, json_desc_dict, configuration, screen_history) message_queue, next_message_time = ProcessArduinoCommmands( to_main_q, flights, configuration, message_queue, next_message_time) personal_message = PersonalMessage( configuration, message_queue, personal_message) # MEMORY MANAGEMENT # now that we've saved the flight, we have no more need to keep the # memory-hogging persistent_path key of that flight in live memory # TODO: On 2022-10-31, commented out anything deleting persistent path if 'persistent_path' in flights[-1]: del flights[-1]['persistent_path'] # it turns out we only need the last screen in the screen history, not # the entire history, so we can purge all the rest from active memory # to eliminate a slow-growing memory hog if screen_history: screen_history = [screen_history[-1]] # we also do not need more than MAX_INSIGHT_HORIZON_DAYS of history # of the flights, so we can purge flights older than that as the flights # list slowly grows over time. we can search the entire list every time # but that's unnecessary; instead we can just pop off the 0-th element # each time through the list if it's more than 1 + max days in the past. # Why + 1? Because the histogram generation expects that many *full* days # of history, so to make sure we don't have a partial day if we were to # generate the monthly histograms mid-day, we will keep an extra day. if time.time() - flights[0]['now'] > SECONDS_IN_DAY * ( MAX_INSIGHT_HORIZON_DAYS + 1): flights.pop(0) if SIMULATION: if now: simulated_hour = EpochDisplayTime(now, '%Y-%m-%d %H:00%z') <----SKIPPED LINES----> |
01234567890123456789012345678901234567890123456789012345678901234567890123456789
71937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236 741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453 | <----SKIPPED LINES----> tracemalloc.start(initial_frame_count) startup_time = time.time() json_desc_dict = {} init_timing.append((time.time(), 3)) flights = UnpickleObjectFromFile( PICKLE_FLIGHTS, True, max_days=MAX_INSIGHT_HORIZON_DAYS, heartbeat=True) # Clear the loaded flight of any cached data, identified by keys # with a specific suffix, since code fixes may change the values for # some of those cached elements init_timing.append((time.time(), 4)) for flight in flights: for key in list(flight.keys()): if key.endswith(CACHED_ELEMENT_PREFIX): flight.pop(key) init_timing.append((time.time(), 5)) # We have no use for the memory-hogging persistent_path key of historical # flights, so let's remove all those keys and save a lot of memory # TODO: On 2022-10-31, commented out anything deleting persistent path #if flights: # for flight in flights[:-1]: # if 'persistent_path' in flight: # del flight['persistent_path'] screen_history = UnpickleObjectFromFile(PICKLE_SCREENS, True, max_days=2) # If we're displaying just a single insight message, we want it to be # something unique, to the extent possible; this dict holds a count of # the diff types of messages displayed so far insight_message_distribution = {} # bootstrap the flight insights distribution from a list of insights on each # flight (i.e.: flight['insight_types'] for a given flight might look like # [1, 2, 7, 9], or [], to indicate which insights were identified; this then # transforms that into {0: 25, 1: 18, ...} summing across all flights. missing_insights = [] for flight in flights: if 'insight_types' not in flight: missing_insights.append('%s on %s' % ( DisplayFlightNumber(flight), DisplayTime(flight, '%x %X'))) distribution = flight.get('insight_types', []) for key in distribution: insight_message_distribution[key] = ( <----SKIPPED LINES----> 'time_flight_message_inserted': time_flight_message_inserted, 'time_insight_message_inserted': time_insight_message_inserted}) PickleObjectToFile(data, PICKLE_FLIGHT_DASHBOARD, True) else: remote, servo = RefreshArduinos( remote, servo, to_remote_q, to_servo_q, to_main_q, shutdown, flights, json_desc_dict, configuration, screen_history) message_queue, next_message_time = ProcessArduinoCommmands( to_main_q, flights, configuration, message_queue, next_message_time) personal_message = PersonalMessage( configuration, message_queue, personal_message) # MEMORY MANAGEMENT # now that we've saved the flight, we have no more need to keep the # memory-hogging persistent_path key of that flight in live memory # TODO: On 2022-10-31, commented out anything deleting persistent path #if 'persistent_path' in flights[-1]: # del flights[-1]['persistent_path'] # it turns out we only need the last screen in the screen history, not # the entire history, so we can purge all the rest from active memory # to eliminate a slow-growing memory hog if screen_history: screen_history = [screen_history[-1]] # we also do not need more than MAX_INSIGHT_HORIZON_DAYS of history # of the flights, so we can purge flights older than that as the flights # list slowly grows over time. we can search the entire list every time # but that's unnecessary; instead we can just pop off the 0-th element # each time through the list if it's more than 1 + max days in the past. # Why + 1? Because the histogram generation expects that many *full* days # of history, so to make sure we don't have a partial day if we were to # generate the monthly histograms mid-day, we will keep an extra day. if time.time() - flights[0]['now'] > SECONDS_IN_DAY * ( MAX_INSIGHT_HORIZON_DAYS + 1): flights.pop(0) if SIMULATION: if now: simulated_hour = EpochDisplayTime(now, '%Y-%m-%d %H:00%z') <----SKIPPED LINES----> |