More thoroughly profile the display loop
							parent
							
								
									65434e2e67
								
							
						
					
					
						commit
						4866bdc460
					
				| 
						 | 
					@ -202,6 +202,14 @@ async def increment_history_view(
 | 
				
			||||||
    async with open_sample_stream(1.) as istream:
 | 
					    async with open_sample_stream(1.) as istream:
 | 
				
			||||||
        async for msg in istream:
 | 
					        async for msg in istream:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            profiler = Profiler(
 | 
				
			||||||
 | 
					                msg=f'History chart cycle for: `{ds.fqsn}`',
 | 
				
			||||||
 | 
					                delayed=True,
 | 
				
			||||||
 | 
					                disabled=not pg_profile_enabled(),
 | 
				
			||||||
 | 
					                ms_threshold=ms_slower_then,
 | 
				
			||||||
 | 
					                # ms_threshold=4,
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # l3 = ds.viz.shm.array[-3:]
 | 
					            # l3 = ds.viz.shm.array[-3:]
 | 
				
			||||||
            # print(
 | 
					            # print(
 | 
				
			||||||
            #     f'fast step for {ds.flume.symbol.fqsn}:\n'
 | 
					            #     f'fast step for {ds.flume.symbol.fqsn}:\n'
 | 
				
			||||||
| 
						 | 
					@ -229,7 +237,10 @@ async def increment_history_view(
 | 
				
			||||||
                # ensure path graphics append is shown on treads since
 | 
					                # ensure path graphics append is shown on treads since
 | 
				
			||||||
                # the main rt loop does not call this.
 | 
					                # the main rt loop does not call this.
 | 
				
			||||||
                hist_viz.update_graphics()
 | 
					                hist_viz.update_graphics()
 | 
				
			||||||
 | 
					                profiler('`hist Viz.update_graphics()` call')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                hist_chart.increment_view(datums=append_diff)
 | 
					                hist_chart.increment_view(datums=append_diff)
 | 
				
			||||||
 | 
					                profiler('hist tread view')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (
 | 
					            if (
 | 
				
			||||||
                do_px_step
 | 
					                do_px_step
 | 
				
			||||||
| 
						 | 
					@ -466,6 +477,7 @@ def graphics_update_cycle(
 | 
				
			||||||
        delayed=True,
 | 
					        delayed=True,
 | 
				
			||||||
        disabled=not pg_profile_enabled(),
 | 
					        disabled=not pg_profile_enabled(),
 | 
				
			||||||
        ms_threshold=ms_slower_then,
 | 
					        ms_threshold=ms_slower_then,
 | 
				
			||||||
 | 
					        # ms_threshold=4,
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # TODO: SPEEDing this all up..
 | 
					    # TODO: SPEEDing this all up..
 | 
				
			||||||
| 
						 | 
					@ -475,24 +487,21 @@ def graphics_update_cycle(
 | 
				
			||||||
    # - use a streaming minmax algo and drop the use of the
 | 
					    # - use a streaming minmax algo and drop the use of the
 | 
				
			||||||
    #   state-tracking ``chart_maxmin()`` routine from above?
 | 
					    #   state-tracking ``chart_maxmin()`` routine from above?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fqsn = ds.fqsn
 | 
				
			||||||
    chart = ds.chart
 | 
					    chart = ds.chart
 | 
				
			||||||
    hist_chart = ds.hist_chart
 | 
					    hist_chart = ds.hist_chart
 | 
				
			||||||
    flume = ds.flume
 | 
					 | 
				
			||||||
    sym = flume.symbol
 | 
					 | 
				
			||||||
    fqsn = sym.fqsn
 | 
					 | 
				
			||||||
    main_viz = ds.viz
 | 
					 | 
				
			||||||
    hist_viz = ds.hist_viz
 | 
					 | 
				
			||||||
    index_field = main_viz.index_field
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # unpack multi-referenced components
 | 
					 | 
				
			||||||
    vlm_chart = ds.vlm_chart
 | 
					    vlm_chart = ds.vlm_chart
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # rt "HFT" chart
 | 
					    varz = ds.vars
 | 
				
			||||||
    l1 = ds.l1
 | 
					    l1 = ds.l1
 | 
				
			||||||
 | 
					    flume = ds.flume
 | 
				
			||||||
    ohlcv = flume.rt_shm
 | 
					    ohlcv = flume.rt_shm
 | 
				
			||||||
    array = ohlcv.array
 | 
					    array = ohlcv.array
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    varz = ds.vars
 | 
					    hist_viz = ds.hist_viz
 | 
				
			||||||
 | 
					    main_viz = ds.viz
 | 
				
			||||||
 | 
					    index_field = main_viz.index_field
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    tick_margin = varz['tick_margin']
 | 
					    tick_margin = varz['tick_margin']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (
 | 
					    (
 | 
				
			||||||
| 
						 | 
					@ -505,6 +514,8 @@ def graphics_update_cycle(
 | 
				
			||||||
        should_tread,
 | 
					        should_tread,
 | 
				
			||||||
    ) = main_viz.incr_info(ds=ds)
 | 
					    ) = main_viz.incr_info(ds=ds)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    profiler('`.incr_info()`')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # TODO: we should only run mxmn when we know
 | 
					    # TODO: we should only run mxmn when we know
 | 
				
			||||||
    # an update is due via ``do_px_step`` above.
 | 
					    # an update is due via ``do_px_step`` above.
 | 
				
			||||||
    (
 | 
					    (
 | 
				
			||||||
| 
						 | 
					@ -529,6 +540,7 @@ def graphics_update_cycle(
 | 
				
			||||||
        or trigger_all
 | 
					        or trigger_all
 | 
				
			||||||
    ):
 | 
					    ):
 | 
				
			||||||
        main_viz.update_graphics(array_key=fqsn)
 | 
					        main_viz.update_graphics(array_key=fqsn)
 | 
				
			||||||
 | 
					        profiler('`Viz.update_graphics()` call')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # don't real-time "shift" the curve to the
 | 
					        # don't real-time "shift" the curve to the
 | 
				
			||||||
        # left unless we get one of the following:
 | 
					        # left unless we get one of the following:
 | 
				
			||||||
| 
						 | 
					@ -589,8 +601,8 @@ def graphics_update_cycle(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # update OHLC chart last bars
 | 
					            # update OHLC chart last bars
 | 
				
			||||||
            # TODO: fix the only last uppx stuff....
 | 
					            # TODO: fix the only last uppx stuff....
 | 
				
			||||||
            main_viz.draw_last() # only_last_uppx=True)
 | 
					            main_viz.draw_last()  # only_last_uppx=True)
 | 
				
			||||||
            hist_viz.draw_last() # only_last_uppx=True)
 | 
					            hist_viz.draw_last()  # only_last_uppx=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # L1 book label-line updates
 | 
					        # L1 book label-line updates
 | 
				
			||||||
        if typ in ('last',):
 | 
					        if typ in ('last',):
 | 
				
			||||||
| 
						 | 
					@ -627,6 +639,8 @@ def graphics_update_cycle(
 | 
				
			||||||
        ):
 | 
					        ):
 | 
				
			||||||
            l1.bid_label.update_fields({'level': price, 'size': size})
 | 
					            l1.bid_label.update_fields({'level': price, 'size': size})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    profiler('L1 labels updates')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Y-autoranging: adjust y-axis limits based on state tracking
 | 
					    # Y-autoranging: adjust y-axis limits based on state tracking
 | 
				
			||||||
    # of previous "last" L1 values which are in view.
 | 
					    # of previous "last" L1 values which are in view.
 | 
				
			||||||
    lmx = varz['last_mx']
 | 
					    lmx = varz['last_mx']
 | 
				
			||||||
| 
						 | 
					@ -681,6 +695,7 @@ def graphics_update_cycle(
 | 
				
			||||||
                    # range_margin=0.1,
 | 
					                    # range_margin=0.1,
 | 
				
			||||||
                    yrange=yr
 | 
					                    yrange=yr
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
 | 
					                profiler('main vb y-autorange')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # SLOW CHART resize case
 | 
					        # SLOW CHART resize case
 | 
				
			||||||
        (
 | 
					        (
 | 
				
			||||||
| 
						 | 
					@ -695,6 +710,7 @@ def graphics_update_cycle(
 | 
				
			||||||
            ds=ds,
 | 
					            ds=ds,
 | 
				
			||||||
            is_1m=True,
 | 
					            is_1m=True,
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					        profiler('hist `Viz.incr_info()`')
 | 
				
			||||||
        if (
 | 
					        if (
 | 
				
			||||||
            hist_liv
 | 
					            hist_liv
 | 
				
			||||||
            and not hist_chart._static_yrange == 'axis'
 | 
					            and not hist_chart._static_yrange == 'axis'
 | 
				
			||||||
| 
						 | 
					@ -703,6 +719,7 @@ def graphics_update_cycle(
 | 
				
			||||||
                viz=hist_viz,
 | 
					                viz=hist_viz,
 | 
				
			||||||
                # yrange=yr,  # this is the rt range, not hist.. XD
 | 
					                # yrange=yr,  # this is the rt range, not hist.. XD
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					            profiler('hist vb y-autorange')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # XXX: update this every draw cycle to ensure y-axis auto-ranging
 | 
					    # XXX: update this every draw cycle to ensure y-axis auto-ranging
 | 
				
			||||||
    # only adjusts when the in-view data co-domain actually expands or
 | 
					    # only adjusts when the in-view data co-domain actually expands or
 | 
				
			||||||
| 
						 | 
					@ -746,6 +763,8 @@ def graphics_update_cycle(
 | 
				
			||||||
                only_last_uppx=True,
 | 
					                only_last_uppx=True,
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    profiler('overlays updates')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # volume chart logic..
 | 
					    # volume chart logic..
 | 
				
			||||||
    # TODO: can we unify this with the above loop?
 | 
					    # TODO: can we unify this with the above loop?
 | 
				
			||||||
    if vlm_chart:
 | 
					    if vlm_chart:
 | 
				
			||||||
| 
						 | 
					@ -808,13 +827,15 @@ def graphics_update_cycle(
 | 
				
			||||||
                    liv and do_rt_update
 | 
					                    liv and do_rt_update
 | 
				
			||||||
                    or do_px_step
 | 
					                    or do_px_step
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
                and curve_name not in {fqsn,}
 | 
					                and curve_name not in {fqsn}
 | 
				
			||||||
            ):
 | 
					            ):
 | 
				
			||||||
                update_fsp_chart(
 | 
					                update_fsp_chart(
 | 
				
			||||||
                    viz,
 | 
					                    viz,
 | 
				
			||||||
                    curve_name,
 | 
					                    curve_name,
 | 
				
			||||||
                    array_key=curve_name,
 | 
					                    array_key=curve_name,
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
 | 
					                profiler(f'vlm `Viz[{viz.name}].update_graphics()`')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                # is this even doing anything?
 | 
					                # is this even doing anything?
 | 
				
			||||||
                # (pretty sure it's the real-time
 | 
					                # (pretty sure it's the real-time
 | 
				
			||||||
                # resizing from last quote?)
 | 
					                # resizing from last quote?)
 | 
				
			||||||
| 
						 | 
					@ -825,6 +846,7 @@ def graphics_update_cycle(
 | 
				
			||||||
                fvb._set_yrange(
 | 
					                fvb._set_yrange(
 | 
				
			||||||
                    viz=viz,
 | 
					                    viz=viz,
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
 | 
					                profiler(f'vlm `Viz[{viz.name}].plot.vb._set_yrange()`')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # even if we're downsampled bigly
 | 
					            # even if we're downsampled bigly
 | 
				
			||||||
            # draw the last datum in the final
 | 
					            # draw the last datum in the final
 | 
				
			||||||
| 
						 | 
					@ -838,6 +860,9 @@ def graphics_update_cycle(
 | 
				
			||||||
                # always update the last datum-element
 | 
					                # always update the last datum-element
 | 
				
			||||||
                # graphic for all vizs
 | 
					                # graphic for all vizs
 | 
				
			||||||
                viz.draw_last(array_key=curve_name)
 | 
					                viz.draw_last(array_key=curve_name)
 | 
				
			||||||
 | 
					                profiler(f'vlm `Viz[{viz.name}].draw_last()`')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        profiler('vlm Viz all updates complete')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    profiler.finish()
 | 
					    profiler.finish()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue