Debian Codegraph @

html_renderer/src/App.svelte

raw
1 <script lang="ts">
2 import Header from './components/Header.svelte'
3 import type Session from "./lib/model/Session";
4 export let session: Session
5 import faviconImage from './assets/favicon.png'
6 import { onDestroy, onMount } from 'svelte';
7 import CallStackView from './components/CallStackView.svelte';
8 import TimelineView from './components/TimelineView.svelte';
9 import { viewOptions } from './lib/settings';
10
11 // add favicon
12 const favicon = document.createElement('link')
13 favicon.rel = 'shortcut icon'
14 favicon.href = faviconImage
15 document.head.appendChild(favicon)
16
17 // add webfont
18 const link = document.createElement('link');
19 link.rel = 'preload';
20 link.as = 'style'
21 link.onload = () => {
22 // clever trick to make the css non-blocking, i don't want to wait on slow
23 // connections to see a local page.
24 // adapted from
25 // https://stackoverflow.com/a/60477207/382749
26 link.rel = 'stylesheet'
27 }
28 link.href = `https://fonts.googleapis.com/css?family=Source+Code+Pro:400,600|Source+Sans+Pro:400,600&display=swap`;
29 document.head.appendChild(link);
30
31 const rootFrame = session.rootFrame;
32 const duration = rootFrame?.time.toLocaleString(undefined, {maximumSignificantDigits: 3});
33 let name
34 // let name = rootFrame?.function;
35 // if (name == '<module>') {
36 // name = session.target_description;
37 // }
38
39 let match
40 // grab just the last path component of the description as a short version
41 // for the page title
42 if (match = /[^\s/]+(:\d+)?$/.exec(session.target_description)) {
43 name = match[0]
44 } else {
45 name = session.target_description
46 }
47
48 document.title = `${duration}s - ${name} - pyinstrument`
49 </script>
50
51 <div class="app">
52 <div class="header">
53 <Header session={session} />
54 </div>
55 <div class="body">
56 {#if !session.rootFrame}
57 <div class="margins">
58 <div class="spacer" style="height: 20px;"></div>
59 <div class="error">
60 No samples recorded.
61 </div>
62 </div>
63 {:else if $viewOptions.viewMode === 'call-stack'}
64 <CallStackView session={session} />
65 {:else if $viewOptions.viewMode === 'timeline'}
66 <TimelineView session={session} />
67 {:else}
68 <div class="error">
69 Unknown view mode: {$viewOptions.viewMode}
70 </div>
71 {/if}
72 </div>
73 </div>
74
75
76 <style lang="scss">
77 .app {
78 font-family: 'Source Sans Pro', Arial, Helvetica, sans-serif;
79 font-size-adjust: 0.486;
80 -webkit-font-smoothing: antialiased;
81 -moz-osx-font-smoothing: grayscale;
82 display: flex;
83 flex-direction: column;
84 position: absolute;
85 top: 0;
86 bottom: 0;
87 left: 0;
88 right: 0;
89 }
90 .body {
91 flex: 1;
92 position: relative;
93 }
94 </style>