Debian Codegraph @

html_renderer/src/components/CallStackView.svelte

raw
1 <script lang="ts">
2 import FrameView from './Frame.svelte'
3 import type Frame from '../lib/model/Frame';
4 import type Session from '../lib/model/Session';
5 import { applyProcessors } from '../lib/model/modelUtil';
6 import {aggregate_repeated_calls, group_library_frames_processor, merge_consecutive_self_time, remove_first_pyinstrument_frames_processor, remove_importlib, remove_irrelevant_nodes, remove_tracebackhide, remove_unnecessary_self_time_nodes, type ProcessorFunction, type ProcessorOptions, allProcessors, type Processor, remove_useless_groups_processor} from '../lib/model/processors'
7 export let session: Session
8 import { viewOptionsCallStack } from '../lib/settings';
9 import { derived } from 'svelte/store';
10 import { onMount } from 'svelte';
11
12 const config = derived([viewOptionsCallStack], ([viewOptionsCallStack]) => {
13 const processors = [
14 viewOptionsCallStack.removeImportlib ? remove_importlib : null,
15 viewOptionsCallStack.removeTracebackHide ? remove_tracebackhide : null,
16 merge_consecutive_self_time,
17 aggregate_repeated_calls,
18 remove_unnecessary_self_time_nodes,
19 viewOptionsCallStack.removeIrrelevant ? remove_irrelevant_nodes : null,
20 viewOptionsCallStack.removePyinstrument ? remove_first_pyinstrument_frames_processor : null,
21 viewOptionsCallStack.collapseMode !== 'disabled' ? group_library_frames_processor : null,
22 remove_useless_groups_processor,
23 ].filter(p => p !== null)
24 const options = {
25 filterThreshold: viewOptionsCallStack.removeIrrelevantThreshold,
26 hideRegex: viewOptionsCallStack.collapseMode == 'custom' ? viewOptionsCallStack.collapseCustomHide : undefined,
27 showRegex: viewOptionsCallStack.collapseMode == 'custom' ? viewOptionsCallStack.collapseCustomShow : undefined,
28 } as ProcessorOptions
29 return {processors, options}
30 })
31
32 let element: HTMLElement|undefined
33 let scrollInnerElement: HTMLElement|undefined
34 let scrollSizeFixerElement: HTMLElement|undefined
35 // don't let the body scroll up due to lack of content (when a tree is
36 // closed)
37 //
38 // the scrollSizeFixerElement prevents the frames from jumping around
39 // when they are collapsed
40 onMount(() => {
41 let scrollMaxY = 0
42 const el = element
43 if (!el) { throw new Error('element not set'); }
44 if (!scrollInnerElement) { throw new Error('scrollInnerElement not set'); }
45 if (!scrollSizeFixerElement) { throw new Error('scrollSizeFixerElement not set'); }
46
47 const sizeObserver = new ResizeObserver(() => {
48 // when the size of the scrollInnerElement changes, we can increase the
49 // scrollMaxY, but not decrease it
50 const height = scrollInnerElement!.getBoundingClientRect().height;
51 if (height > scrollMaxY) {
52 scrollMaxY = height;
53 scrollSizeFixerElement!.style.top = `${scrollMaxY-1}px`;
54 }
55 });
56 sizeObserver.observe(scrollInnerElement!);
57 let scrollListener
58 el.addEventListener('scroll', scrollListener = () => {
59 // when the user scrolls, we can decrease the scrollMaxY, but no smaller
60 // than the current height of the scrollInnerElement
61 let scrollBottom = el.scrollTop + el.clientHeight;
62 const height = scrollInnerElement!.getBoundingClientRect().height;
63 if (scrollBottom < height) {
64 scrollBottom = height;
65 }
66 if (scrollBottom < scrollMaxY) {
67 scrollMaxY = scrollBottom
68 scrollSizeFixerElement!.style.top = `${scrollMaxY-1}px`;
69 }
70 });
71 scrollListener();
72 return () => {
73 sizeObserver.disconnect();
74 el.removeEventListener('scroll', scrollListener);
75 }
76 });
77
78 let rootFrame: Frame|null
79 $: rootFrame = applyProcessors(session.rootFrame?.cloneDeep() ?? null, $config.processors, $config.options)
80 </script>
81
82 <div class="call-stack-view" bind:this={element}>
83 <div class="scroll-inner" bind:this={scrollInnerElement}>
84 {#if !rootFrame}
85 <div class="margins">
86 <div class="error">
87 All frames were filtered out.
88 </div>
89 </div>
90 {:else}
91 <div class="call-stack-margins">
92 <FrameView frame={rootFrame} rootFrame={rootFrame} />
93 </div>
94 {/if}
95 </div>
96 <div class="scroll-size-fixer" bind:this={scrollSizeFixerElement}></div>
97 </div>
98
99 <style lang="scss">
100 .call-stack-view {
101 background-color: #303538;
102 position: absolute;
103 top: 0;
104 bottom: 0;
105 left: 0;
106 right: 0;
107 overflow: auto;
108 &:focus {
109 outline: none;
110 }
111 }
112 .scroll-inner {
113 padding-top: 10px;
114 padding-bottom: 40px;
115 box-sizing: border-box;
116 width: auto;
117 min-width: max-content;
118 }
119 .call-stack-margins {
120 padding-left: 18px;
121 padding-right: 18px;
122 }
123 .scroll-size-fixer {
124 height: 1px;
125 width: 100px;
126 position: absolute;
127 left: 0;
128 // background-color: red;
129 }
130 </style>