-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
183 additions
and
15 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
log-viewer/src/lib/components/timeline/LogDurations.stories.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<script context="module" lang="ts"> | ||
import type { MetaProps } from '@storybook/addon-svelte-csf'; | ||
import { randomLogger } from '../../log.test_utils'; | ||
import LogDurations from './LogDurations.svelte'; | ||
const logger = randomLogger(); | ||
export const meta: MetaProps = { | ||
title: 'Timeline/Molecules/LogDurations', | ||
component: LogDurations, | ||
tags: ['autodocs'], | ||
args: { | ||
logs: logger.logs | ||
} | ||
}; | ||
</script> | ||
|
||
<script lang="ts"> | ||
import { Story, Template } from '@storybook/addon-svelte-csf'; | ||
</script> | ||
|
||
<Template let:args> | ||
<LogDurations {...args} /> | ||
</Template> | ||
|
||
<Story name="Base" /> |
35 changes: 35 additions & 0 deletions
35
log-viewer/src/lib/components/timeline/LogDurations.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<script lang="ts"> | ||
import { compareAsc } from 'date-fns'; | ||
import { type Entry, isSpan } from '../../log'; | ||
import SpanDuration from './SpanDuration.svelte'; | ||
/** | ||
* The list of log entries to render in the tree. | ||
*/ | ||
export let logs: Entry[]; | ||
// Filter out LogEntry's, only show the Span/TaskSpan in the tree | ||
$: spans = logs.filter(isSpan); | ||
let logTimes: Date[]; | ||
$: { | ||
logTimes = logs.reduce<Date[]>((acc, i) => { | ||
if ('timestamp' in i) acc.push(new Date(i.timestamp)); | ||
if ('start_timestamp' in i) acc.push(new Date(i.start_timestamp)); | ||
if ('end_timestamp' in i) acc.push(new Date(i.end_timestamp)); | ||
return acc; | ||
}, []); | ||
logTimes.sort(compareAsc); | ||
console.log(logTimes); | ||
} | ||
</script> | ||
|
||
<!-- | ||
@compone nt | ||
A timeline of all sub-span durations | ||
--> | ||
<div class="w-full"> | ||
{#each spans as span} | ||
<SpanDuration {span} runStart={logTimes[0]} runEnd={logTimes[logTimes.length - 1]} /> | ||
{/each} | ||
</div> |
29 changes: 29 additions & 0 deletions
29
log-viewer/src/lib/components/timeline/SpanDuration.stories.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<script context="module" lang="ts"> | ||
import type { MetaProps } from '@storybook/addon-svelte-csf'; | ||
import { randomSpan, randomDateRange } from '../../log.test_utils'; | ||
import SpanDuration from './SpanDuration.svelte'; | ||
const range = randomDateRange(); | ||
const span = randomSpan(range); | ||
export const meta: MetaProps = { | ||
title: 'Timeline/Atoms/SpanDuration', | ||
component: SpanDuration, | ||
tags: ['autodocs'], | ||
args: { | ||
span, | ||
runStart: range.from, | ||
runEnd: range.to | ||
} | ||
}; | ||
</script> | ||
|
||
<script lang="ts"> | ||
import { Story, Template } from '@storybook/addon-svelte-csf'; | ||
</script> | ||
|
||
<Template let:args> | ||
<SpanDuration {...args} /> | ||
</Template> | ||
|
||
<Story name="Base" /> |
64 changes: 64 additions & 0 deletions
64
log-viewer/src/lib/components/timeline/SpanDuration.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<script lang="ts"> | ||
import { differenceInMilliseconds } from 'date-fns'; | ||
import { type SpanEntry, isSpan } from '../../log'; | ||
/** | ||
* A Span or TaskSpan to show the duration of | ||
*/ | ||
export let span: SpanEntry; | ||
/** | ||
* The start of the entire run of the logger | ||
*/ | ||
export let runStart: Date; | ||
/** | ||
* The end of the entire run of the logger | ||
*/ | ||
export let runEnd: Date; | ||
$: spanStart = new Date(span.start_timestamp); | ||
$: spanOffset = differenceInMilliseconds(spanStart, runStart); | ||
$: spanLength = differenceInMilliseconds(new Date(span.end_timestamp), spanStart); | ||
$: runLength = differenceInMilliseconds(runEnd, runStart); | ||
// Filter out LogEntry's, only show the Span/TaskSpan in the tree | ||
$: childSpans = span.logs.filter(isSpan); | ||
function renderDuration(spanLength: number): string { | ||
let unit = 'ms'; | ||
let length = spanLength; | ||
if (length > 1000) { | ||
length /= 1000; | ||
unit = 's'; | ||
if (length > 60) { | ||
length /= 60; | ||
unit = 'min'; | ||
if (length > 60) { | ||
length /= 60; | ||
unit = 'h'; | ||
} | ||
} | ||
} | ||
return `${length.toLocaleString('en-US')}${unit}`; | ||
} | ||
</script> | ||
|
||
<!-- | ||
@component | ||
A view of Span durations in relation to the entire duration of the log. | ||
This is a recursive component that builds itself up by creating the same component for sub-spans. | ||
--> | ||
<div class="w-full py-0.5 hover:bg-gray-50"> | ||
<button | ||
class="h-8 bg-accent-400 py-1 text-right text-xs font-extrabold text-gray-950 shadow outline-none ring-1 ring-gray-950/20 hover:bg-accent-500" | ||
style="margin-left: {Math.round((spanOffset / runLength) * 100)}%; width:{Math.round( | ||
(spanLength / runLength) * 100 | ||
)}%;" | ||
> | ||
<span class="px-1">{renderDuration(spanLength)}</span> | ||
</button> | ||
</div> | ||
{#each childSpans as span} | ||
<svelte:self {span} {runStart} {runEnd} /> | ||
{/each} |
9 changes: 4 additions & 5 deletions
9
log-viewer/src/lib/components/timeline/SpanTree.stories.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters