@kylincloud/flamegraph 0.35.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1211 -0
- package/LICENSE +202 -0
- package/README.md +251 -0
- package/dist/FlameGraph/FlameGraphComponent/CheckIcon.d.ts +2 -0
- package/dist/FlameGraph/FlameGraphComponent/CheckIcon.d.ts.map +1 -0
- package/dist/FlameGraph/FlameGraphComponent/ContextMenu.d.ts +17 -0
- package/dist/FlameGraph/FlameGraphComponent/ContextMenu.d.ts.map +1 -0
- package/dist/FlameGraph/FlameGraphComponent/ContextMenuHighlight.d.ts +14 -0
- package/dist/FlameGraph/FlameGraphComponent/ContextMenuHighlight.d.ts.map +1 -0
- package/dist/FlameGraph/FlameGraphComponent/DiffLegend.d.ts +9 -0
- package/dist/FlameGraph/FlameGraphComponent/DiffLegend.d.ts.map +1 -0
- package/dist/FlameGraph/FlameGraphComponent/DiffLegendPaletteDropdown.d.ts +8 -0
- package/dist/FlameGraph/FlameGraphComponent/DiffLegendPaletteDropdown.d.ts.map +1 -0
- package/dist/FlameGraph/FlameGraphComponent/Flamegraph.d.ts +96 -0
- package/dist/FlameGraph/FlameGraphComponent/Flamegraph.d.ts.map +1 -0
- package/dist/FlameGraph/FlameGraphComponent/Flamegraph_render.d.ts +27 -0
- package/dist/FlameGraph/FlameGraphComponent/Flamegraph_render.d.ts.map +1 -0
- package/dist/FlameGraph/FlameGraphComponent/GraphVizPane.d.ts +7 -0
- package/dist/FlameGraph/FlameGraphComponent/GraphVizPane.d.ts.map +1 -0
- package/dist/FlameGraph/FlameGraphComponent/Header.d.ts +12 -0
- package/dist/FlameGraph/FlameGraphComponent/Header.d.ts.map +1 -0
- package/dist/FlameGraph/FlameGraphComponent/Highlight.d.ts +18 -0
- package/dist/FlameGraph/FlameGraphComponent/Highlight.d.ts.map +1 -0
- package/dist/FlameGraph/FlameGraphComponent/LogoLink.d.ts +2 -0
- package/dist/FlameGraph/FlameGraphComponent/LogoLink.d.ts.map +1 -0
- package/dist/FlameGraph/FlameGraphComponent/color.d.ts +20 -0
- package/dist/FlameGraph/FlameGraphComponent/color.d.ts.map +1 -0
- package/dist/FlameGraph/FlameGraphComponent/colorPalette.d.ts +11 -0
- package/dist/FlameGraph/FlameGraphComponent/colorPalette.d.ts.map +1 -0
- package/dist/FlameGraph/FlameGraphComponent/constants.d.ts +6 -0
- package/dist/FlameGraph/FlameGraphComponent/constants.d.ts.map +1 -0
- package/dist/FlameGraph/FlameGraphComponent/index.d.ts +37 -0
- package/dist/FlameGraph/FlameGraphComponent/index.d.ts.map +1 -0
- package/dist/FlameGraph/FlameGraphComponent/murmur3.d.ts +2 -0
- package/dist/FlameGraph/FlameGraphComponent/murmur3.d.ts.map +1 -0
- package/dist/FlameGraph/FlameGraphComponent/testData.d.ts +53 -0
- package/dist/FlameGraph/FlameGraphComponent/testData.d.ts.map +1 -0
- package/dist/FlameGraph/FlameGraphComponent/utils.d.ts +6 -0
- package/dist/FlameGraph/FlameGraphComponent/utils.d.ts.map +1 -0
- package/dist/FlameGraph/FlameGraphComponent/viewTypes.d.ts +2 -0
- package/dist/FlameGraph/FlameGraphComponent/viewTypes.d.ts.map +1 -0
- package/dist/FlameGraph/FlameGraphRenderer.d.ts +86 -0
- package/dist/FlameGraph/FlameGraphRenderer.d.ts.map +1 -0
- package/dist/FlameGraph/decode.d.ts +27 -0
- package/dist/FlameGraph/decode.d.ts.map +1 -0
- package/dist/FlameGraph/normalize.d.ts +6 -0
- package/dist/FlameGraph/normalize.d.ts.map +1 -0
- package/dist/FlameGraph/uniqueness.d.ts +3 -0
- package/dist/FlameGraph/uniqueness.d.ts.map +1 -0
- package/dist/FlamegraphRenderer.d.ts +19 -0
- package/dist/FlamegraphRenderer.d.ts.map +1 -0
- package/dist/Icons.d.ts +9 -0
- package/dist/Icons.d.ts.map +1 -0
- package/dist/ProfilerTable.d.ts +21 -0
- package/dist/ProfilerTable.d.ts.map +1 -0
- package/dist/SharedQueryInput.d.ts +10 -0
- package/dist/SharedQueryInput.d.ts.map +1 -0
- package/dist/Toolbar.d.ts +31 -0
- package/dist/Toolbar.d.ts.map +1 -0
- package/dist/Tooltip/FlamegraphTooltip.d.ts +59 -0
- package/dist/Tooltip/FlamegraphTooltip.d.ts.map +1 -0
- package/dist/Tooltip/LeftClickIcon.d.ts +2 -0
- package/dist/Tooltip/LeftClickIcon.d.ts.map +1 -0
- package/dist/Tooltip/RightClickIcon.d.ts +2 -0
- package/dist/Tooltip/RightClickIcon.d.ts.map +1 -0
- package/dist/Tooltip/TableTooltip.d.ts +12 -0
- package/dist/Tooltip/TableTooltip.d.ts.map +1 -0
- package/dist/Tooltip/Tooltip.d.ts +29 -0
- package/dist/Tooltip/Tooltip.d.ts.map +1 -0
- package/dist/convert/convertJaegerTraceToProfile.d.ts +3 -0
- package/dist/convert/convertJaegerTraceToProfile.d.ts.map +1 -0
- package/dist/convert/diffTwoProfiles.d.ts +3 -0
- package/dist/convert/diffTwoProfiles.d.ts.map +1 -0
- package/dist/convert/flamebearersToTree.d.ts +11 -0
- package/dist/convert/flamebearersToTree.d.ts.map +1 -0
- package/dist/convert/sandwichViewProfiles.d.ts +14 -0
- package/dist/convert/sandwichViewProfiles.d.ts.map +1 -0
- package/dist/convert/subtract.d.ts +3 -0
- package/dist/convert/subtract.d.ts.map +1 -0
- package/dist/convert/testData.d.ts +50 -0
- package/dist/convert/testData.d.ts.map +1 -0
- package/dist/convert/toGraphviz.d.ts +3 -0
- package/dist/convert/toGraphviz.d.ts.map +1 -0
- package/dist/fitMode/fitMode.d.ts +42 -0
- package/dist/fitMode/fitMode.d.ts.map +1 -0
- package/dist/format/format.d.ts +42 -0
- package/dist/format/format.d.ts.map +1 -0
- package/dist/i18n.d.ts +55 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/index.cjs.css +792 -0
- package/dist/index.cjs.js +5087 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.css +792 -0
- package/dist/index.esm.js +5079 -0
- package/dist/index.node.d.ts +9 -0
- package/dist/index.node.d.ts.map +1 -0
- package/dist/logo-v3-small-T5VXIMRR.svg +32 -0
- package/dist/models/decode.d.ts +3 -0
- package/dist/models/decode.d.ts.map +1 -0
- package/dist/models/flamebearer.d.ts +63 -0
- package/dist/models/flamebearer.d.ts.map +1 -0
- package/dist/models/groups.d.ts +37 -0
- package/dist/models/groups.d.ts.map +1 -0
- package/dist/models/index.d.ts +8 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/profile.d.ts +152 -0
- package/dist/models/profile.d.ts.map +1 -0
- package/dist/models/spyName.d.ts +8 -0
- package/dist/models/spyName.d.ts.map +1 -0
- package/dist/models/trace.d.ts +357 -0
- package/dist/models/trace.d.ts.map +1 -0
- package/dist/models/units.d.ts +6 -0
- package/dist/models/units.d.ts.map +1 -0
- package/dist/search.d.ts +2 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/shims/Box.d.ts +38 -0
- package/dist/shims/Box.d.ts.map +1 -0
- package/dist/shims/Button.d.ts +26 -0
- package/dist/shims/Button.d.ts.map +1 -0
- package/dist/shims/Dropdown.d.ts +30 -0
- package/dist/shims/Dropdown.d.ts.map +1 -0
- package/dist/shims/Input.d.ts +19 -0
- package/dist/shims/Input.d.ts.map +1 -0
- package/dist/shims/LoadingSpinner.d.ts +7 -0
- package/dist/shims/LoadingSpinner.d.ts.map +1 -0
- package/dist/shims/Menu.d.ts +4 -0
- package/dist/shims/Menu.d.ts.map +1 -0
- package/dist/shims/NoData.d.ts +2 -0
- package/dist/shims/NoData.d.ts.map +1 -0
- package/dist/shims/Table.d.ts +52 -0
- package/dist/shims/Table.d.ts.map +1 -0
- package/dist/shims/Tooltip.d.ts +9 -0
- package/dist/shims/Tooltip.d.ts.map +1 -0
- package/package.json +84 -0
- package/src/FlameGraph/FlameGraphComponent/CheckIcon.tsx +27 -0
- package/src/FlameGraph/FlameGraphComponent/ContextMenu.module.scss +10 -0
- package/src/FlameGraph/FlameGraphComponent/ContextMenu.spec.tsx +84 -0
- package/src/FlameGraph/FlameGraphComponent/ContextMenu.tsx +86 -0
- package/src/FlameGraph/FlameGraphComponent/ContextMenuHighlight.module.css +8 -0
- package/src/FlameGraph/FlameGraphComponent/ContextMenuHighlight.tsx +47 -0
- package/src/FlameGraph/FlameGraphComponent/DiffLegend.module.css +21 -0
- package/src/FlameGraph/FlameGraphComponent/DiffLegend.tsx +52 -0
- package/src/FlameGraph/FlameGraphComponent/DiffLegendPaletteDropdown.module.css +40 -0
- package/src/FlameGraph/FlameGraphComponent/DiffLegendPaletteDropdown.tsx +129 -0
- package/src/FlameGraph/FlameGraphComponent/Flamegraph.spec.ts +552 -0
- package/src/FlameGraph/FlameGraphComponent/Flamegraph.ts +446 -0
- package/src/FlameGraph/FlameGraphComponent/Flamegraph_render.spec.tsx +233 -0
- package/src/FlameGraph/FlameGraphComponent/Flamegraph_render.ts +478 -0
- package/src/FlameGraph/FlameGraphComponent/GraphVizPane.tsx +56 -0
- package/src/FlameGraph/FlameGraphComponent/GraphVizPanel.module.scss +55 -0
- package/src/FlameGraph/FlameGraphComponent/Header.module.css +27 -0
- package/src/FlameGraph/FlameGraphComponent/Header.tsx +71 -0
- package/src/FlameGraph/FlameGraphComponent/Highlight.module.css +7 -0
- package/src/FlameGraph/FlameGraphComponent/Highlight.spec.tsx +53 -0
- package/src/FlameGraph/FlameGraphComponent/Highlight.tsx +94 -0
- package/src/FlameGraph/FlameGraphComponent/LogoLink.module.scss +10 -0
- package/src/FlameGraph/FlameGraphComponent/LogoLink.tsx +101 -0
- package/src/FlameGraph/FlameGraphComponent/__image_snapshots__/canvas-renderer-spec-tsx-canvas-renderer-group-snapshot-collapses-small-blocks-into-one-1-snap.png +0 -0
- package/src/FlameGraph/FlameGraphComponent/__image_snapshots__/canvas-renderer-spec-tsx-canvas-renderer-group-snapshot-works-with-diff-mode-1-snap.png +0 -0
- package/src/FlameGraph/FlameGraphComponent/__image_snapshots__/canvas-renderer-spec-tsx-canvas-renderer-group-snapshot-works-with-highlighted-flamegraph-1-snap.png +0 -0
- package/src/FlameGraph/FlameGraphComponent/__image_snapshots__/canvas-renderer-spec-tsx-canvas-renderer-group-snapshot-works-with-normal-flamegraph-1-snap.png +0 -0
- package/src/FlameGraph/FlameGraphComponent/__image_snapshots__/canvas-renderer-spec-tsx-canvas-renderer-group-snapshot-works-with-selected-node-1-snap.png +0 -0
- package/src/FlameGraph/FlameGraphComponent/__image_snapshots__/flamegraph-render-spec-tsx-render-group-snapshot-focused-also-zooms-1-snap.png +0 -0
- package/src/FlameGraph/FlameGraphComponent/__image_snapshots__/flamegraph-render-spec-tsx-render-group-snapshot-focused-renders-a-focused-node-in-the-beginning-1-snap.png +0 -0
- package/src/FlameGraph/FlameGraphComponent/__image_snapshots__/flamegraph-render-spec-tsx-render-group-snapshot-focused-renders-a-focused-node-when-node-is-not-in-the-beginning-1-snap.png +0 -0
- package/src/FlameGraph/FlameGraphComponent/__image_snapshots__/flamegraph-render-spec-tsx-render-group-snapshot-focused-renders-a-focused-node-zoom-top-level-1-snap.png +0 -0
- package/src/FlameGraph/FlameGraphComponent/__image_snapshots__/flamegraph-render-spec-tsx-render-group-snapshot-renders-a-complex-flamegraph-1-snap.png +0 -0
- package/src/FlameGraph/FlameGraphComponent/__image_snapshots__/flamegraph-render-spec-tsx-render-group-snapshot-renders-a-double-diff-flamegraph-1-snap.png +0 -0
- package/src/FlameGraph/FlameGraphComponent/__image_snapshots__/flamegraph-render-spec-tsx-render-group-snapshot-renders-a-highlighted-double-flamegraph-1-snap.png +0 -0
- package/src/FlameGraph/FlameGraphComponent/__image_snapshots__/flamegraph-render-spec-tsx-render-group-snapshot-renders-a-highlighted-flamegraph-1-snap.png +0 -0
- package/src/FlameGraph/FlameGraphComponent/__image_snapshots__/flamegraph-render-spec-tsx-render-group-snapshot-renders-a-simple-flamegraph-1-snap.png +0 -0
- package/src/FlameGraph/FlameGraphComponent/__image_snapshots__/flamegraph-render-spec-tsx-render-group-snapshot-renders-a-simple-tree-1-snap.png +0 -0
- package/src/FlameGraph/FlameGraphComponent/__image_snapshots__/flamegraph-render-spec-tsx-render-group-snapshot-renders-a-zoomed-flamegraph-1-snap.png +0 -0
- package/src/FlameGraph/FlameGraphComponent/__image_snapshots__/flamegraph-render-spec-tsx-render-group-snapshot-renders-a-zoomed-with-fit-mode-tail-1-snap.png +0 -0
- package/src/FlameGraph/FlameGraphComponent/canvas.module.css +6 -0
- package/src/FlameGraph/FlameGraphComponent/color.spec.ts +308 -0
- package/src/FlameGraph/FlameGraphComponent/color.ts +167 -0
- package/src/FlameGraph/FlameGraphComponent/colorPalette.ts +58 -0
- package/src/FlameGraph/FlameGraphComponent/constants.ts +5 -0
- package/src/FlameGraph/FlameGraphComponent/index.spec.tsx +291 -0
- package/src/FlameGraph/FlameGraphComponent/index.tsx +411 -0
- package/src/FlameGraph/FlameGraphComponent/murmur3.ts +97 -0
- package/src/FlameGraph/FlameGraphComponent/styles.module.scss +10 -0
- package/src/FlameGraph/FlameGraphComponent/testData.ts +427 -0
- package/src/FlameGraph/FlameGraphComponent/utils.ts +31 -0
- package/src/FlameGraph/FlameGraphComponent/viewTypes.ts +6 -0
- package/src/FlameGraph/FlameGraphRenderer.tsx +603 -0
- package/src/FlameGraph/FlamegraphRenderer.module.scss +93 -0
- package/src/FlameGraph/decode.ts +78 -0
- package/src/FlameGraph/normalize.spec.ts +76 -0
- package/src/FlameGraph/normalize.ts +60 -0
- package/src/FlameGraph/testData.json +423 -0
- package/src/FlameGraph/uniqueness.spec.ts +16 -0
- package/src/FlameGraph/uniqueness.ts +84 -0
- package/src/FlamegraphRenderer.tsx +61 -0
- package/src/Icons.tsx +74 -0
- package/src/ProfilerTable.tsx +527 -0
- package/src/SharedQueryInput.module.scss +82 -0
- package/src/SharedQueryInput.tsx +127 -0
- package/src/Toolbar.module.scss +117 -0
- package/src/Toolbar.spec.tsx +217 -0
- package/src/Toolbar.tsx +471 -0
- package/src/Tooltip/FlamegraphTooltip.spec.tsx +81 -0
- package/src/Tooltip/FlamegraphTooltip.tsx +257 -0
- package/src/Tooltip/LeftClickIcon.tsx +18 -0
- package/src/Tooltip/RightClickIcon.tsx +18 -0
- package/src/Tooltip/TableTooltip.spec.tsx +44 -0
- package/src/Tooltip/TableTooltip.tsx +145 -0
- package/src/Tooltip/Tooltip.module.scss +71 -0
- package/src/Tooltip/Tooltip.spec.tsx +395 -0
- package/src/Tooltip/Tooltip.tsx +336 -0
- package/src/__snapshots__/Toolbar.spec.tsx.snap +297 -0
- package/src/convert/convertJaegerTraceToProfile.ts +97 -0
- package/src/convert/diffTwoProfiles.ts +81 -0
- package/src/convert/flamebearersToTree.ts +78 -0
- package/src/convert/sandwichViewProfiles.spec.ts +65 -0
- package/src/convert/sandwichViewProfiles.ts +191 -0
- package/src/convert/subtract.ts +87 -0
- package/src/convert/testData.ts +145 -0
- package/src/convert/toGraphviz.ts +485 -0
- package/src/fitMode/fitMode.spec.ts +93 -0
- package/src/fitMode/fitMode.ts +122 -0
- package/src/format/format.spec.ts +291 -0
- package/src/format/format.ts +303 -0
- package/src/globals.d.ts +13 -0
- package/src/i18n.tsx +293 -0
- package/src/index.node.ts +19 -0
- package/src/index.spec.tsx +383 -0
- package/src/index.tsx +10 -0
- package/src/logo-v3-small.svg +32 -0
- package/src/models/decode.ts +45 -0
- package/src/models/flamebearer.ts +86 -0
- package/src/models/groups.ts +14 -0
- package/src/models/index.ts +7 -0
- package/src/models/profile.spec.ts +32 -0
- package/src/models/profile.ts +48 -0
- package/src/models/spyName.spec.ts +18 -0
- package/src/models/spyName.ts +32 -0
- package/src/models/trace.ts +45 -0
- package/src/models/units.spec.ts +21 -0
- package/src/models/units.ts +24 -0
- package/src/sass/_common.scss +206 -0
- package/src/sass/_css-variables.scss +201 -0
- package/src/sass/_mixins.scss +15 -0
- package/src/sass/_sanitize.scss +407 -0
- package/src/sass/_variables.scss +53 -0
- package/src/sass/flamegraph.scss +18 -0
- package/src/search.spec.ts +11 -0
- package/src/search.ts +4 -0
- package/src/shameful-any.d.ts +2 -0
- package/src/shims/Box.module.scss +57 -0
- package/src/shims/Box.tsx +105 -0
- package/src/shims/Button.module.scss +129 -0
- package/src/shims/Button.tsx +128 -0
- package/src/shims/Dropdown.module.scss +63 -0
- package/src/shims/Dropdown.tsx +96 -0
- package/src/shims/Input.module.scss +15 -0
- package/src/shims/Input.tsx +55 -0
- package/src/shims/LoadingSpinner.tsx +19 -0
- package/src/shims/Menu.tsx +9 -0
- package/src/shims/NoData.module.scss +6 -0
- package/src/shims/NoData.tsx +11 -0
- package/src/shims/Table.module.scss +82 -0
- package/src/shims/Table.spec.tsx +121 -0
- package/src/shims/Table.tsx +252 -0
- package/src/shims/Tooltip.tsx +51 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
export const TailMode = 'TAIL';
|
|
2
|
+
export const HeadMode = 'HEAD';
|
|
3
|
+
|
|
4
|
+
export type FitModes = typeof TailMode | typeof HeadMode;
|
|
5
|
+
|
|
6
|
+
const margin = 3;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Returns a text and margin left used to write text into a canvas rectangle
|
|
10
|
+
*
|
|
11
|
+
* @param {FitModes} mode -
|
|
12
|
+
* @param {number} charSize - Size in pixels of an individual character. Assumes it's a monospace font.
|
|
13
|
+
* @param {number} rectWidth - Width in pixels of the rectangle
|
|
14
|
+
* @param {string} fullText - The text that will be first tried.
|
|
15
|
+
* @param {string} shortText - The text that willbe used when fullText can't fit. It's normally a substring of the original text.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
interface fitToCanvasRectProps {
|
|
19
|
+
mode: FitModes;
|
|
20
|
+
|
|
21
|
+
/** charSize - Size in pixels of an individual character. Assumes it's a monospace font. */
|
|
22
|
+
charSize: number;
|
|
23
|
+
|
|
24
|
+
/** Width in pixels of the rectangle */
|
|
25
|
+
rectWidth: number;
|
|
26
|
+
|
|
27
|
+
/** The text that will be first tried to fit */
|
|
28
|
+
fullText: string;
|
|
29
|
+
|
|
30
|
+
/** The text that willbe used when fullText can't fit. It's normally a substring of the original text. */
|
|
31
|
+
shortText: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function fitToCanvasRect({
|
|
35
|
+
mode,
|
|
36
|
+
charSize,
|
|
37
|
+
rectWidth,
|
|
38
|
+
fullText,
|
|
39
|
+
shortText,
|
|
40
|
+
}: fitToCanvasRectProps) {
|
|
41
|
+
switch (mode) {
|
|
42
|
+
case TailMode:
|
|
43
|
+
// Case 1:
|
|
44
|
+
// content fits rectangle width
|
|
45
|
+
// | rectangle |
|
|
46
|
+
// | text |
|
|
47
|
+
if (charSize * fullText.length <= rectWidth) {
|
|
48
|
+
// assume it's a monospaced font
|
|
49
|
+
return {
|
|
50
|
+
mode,
|
|
51
|
+
text: fullText,
|
|
52
|
+
marginLeft: margin,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// assume it's a monospaced font
|
|
57
|
+
// if not the case, use
|
|
58
|
+
// ctx.measureText(shortName).width
|
|
59
|
+
const shortTextWidth = charSize * shortText.length;
|
|
60
|
+
|
|
61
|
+
// Case 2:
|
|
62
|
+
// short text fits rectangle width
|
|
63
|
+
// | rectangle |
|
|
64
|
+
// | long_text_text |
|
|
65
|
+
// | shorttext |
|
|
66
|
+
if (shortTextWidth <= rectWidth) {
|
|
67
|
+
// assume it's a monospaced font
|
|
68
|
+
return {
|
|
69
|
+
mode,
|
|
70
|
+
text: shortText,
|
|
71
|
+
marginLeft: margin,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Case 3:
|
|
76
|
+
// short text is bigger than rectangle width
|
|
77
|
+
// add a negative margin left
|
|
78
|
+
// so that the 'tail' of the string is visible
|
|
79
|
+
// | rectangle |
|
|
80
|
+
// | my_short_text |
|
|
81
|
+
return {
|
|
82
|
+
mode,
|
|
83
|
+
text: shortText,
|
|
84
|
+
marginLeft: -(shortTextWidth - rectWidth + margin),
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// Case 3:
|
|
88
|
+
// Normal
|
|
89
|
+
case HeadMode:
|
|
90
|
+
default:
|
|
91
|
+
return {
|
|
92
|
+
mode,
|
|
93
|
+
text: fullText,
|
|
94
|
+
marginLeft: margin,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Returns an inline style in React format
|
|
101
|
+
* used to fit the content into a table cell
|
|
102
|
+
* or an empty object if not applicable.
|
|
103
|
+
* @param {FitModes} mode - The mode
|
|
104
|
+
*/
|
|
105
|
+
export function fitIntoTableCell(mode: FitModes): React.CSSProperties {
|
|
106
|
+
switch (mode) {
|
|
107
|
+
case TailMode:
|
|
108
|
+
return {
|
|
109
|
+
// prints from right to left
|
|
110
|
+
direction: 'rtl',
|
|
111
|
+
overflow: 'hidden',
|
|
112
|
+
textOverflow: 'ellipsis',
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
case HeadMode:
|
|
116
|
+
default:
|
|
117
|
+
return {
|
|
118
|
+
overflow: 'hidden',
|
|
119
|
+
textOverflow: 'ellipsis',
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { numberWithCommas, getFormatter } from './format';
|
|
2
|
+
|
|
3
|
+
describe('format', () => {
|
|
4
|
+
describe.each([
|
|
5
|
+
[0, '0'],
|
|
6
|
+
[1_000, '1,000'],
|
|
7
|
+
[1_000_000, '1,000,000'],
|
|
8
|
+
[1_000_000_000, '1,000,000,000'],
|
|
9
|
+
[-1_000, '-1,000'],
|
|
10
|
+
[-1_000_000, '-1,000,000'],
|
|
11
|
+
[-1_000_000_000, '-1,000,000,000'],
|
|
12
|
+
])('.numberWithCommas(%i)', (a: number, expected) => {
|
|
13
|
+
it(`returns ${expected}`, () => {
|
|
14
|
+
expect(numberWithCommas(a)).toBe(expected);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('format & formatPrecise', () => {
|
|
19
|
+
// TODO is this correct, since we have an enum?
|
|
20
|
+
// unfortunately until we fully migrate to TS
|
|
21
|
+
// we still need to check for a default value
|
|
22
|
+
it('its constructor should default to DurationFormatter', () => {
|
|
23
|
+
const df = getFormatter(80, 2, '' as any);
|
|
24
|
+
|
|
25
|
+
expect(df.format(0.001, 100)).toBe('< 0.01 ');
|
|
26
|
+
expect(df.formatPrecise(0.001, 100)).toBe('0.00001 ');
|
|
27
|
+
expect(df.formatPrecise(0.1, 100)).toBe('0.001 ');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('DurationFormatter', () => {
|
|
31
|
+
it('correctly formats duration when maxdur = 40', () => {
|
|
32
|
+
const df = getFormatter(80, 2, 'samples');
|
|
33
|
+
|
|
34
|
+
expect(df.format(0, 100)).toBe('0.00 seconds');
|
|
35
|
+
expect(df.format(0.001, 100)).toBe('< 0.01 seconds');
|
|
36
|
+
expect(df.format(100, 100)).toBe('1.00 second');
|
|
37
|
+
expect(df.format(2000, 100)).toBe('20.00 seconds');
|
|
38
|
+
expect(df.format(2012.3, 100)).toBe('20.12 seconds');
|
|
39
|
+
expect(df.format(8000, 100)).toBe('80.00 seconds');
|
|
40
|
+
expect(df.formatPrecise(0.001, 100)).toBe('0.00001 seconds');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('correctly formats duration when maxdur = 80', () => {
|
|
44
|
+
const df = getFormatter(160, 2, 'samples');
|
|
45
|
+
|
|
46
|
+
expect(df.format(6000, 100)).toBe('1.00 minute');
|
|
47
|
+
expect(df.format(100, 100)).toBe('0.02 minutes');
|
|
48
|
+
expect(df.format(2000, 100)).toBe('0.33 minutes');
|
|
49
|
+
expect(df.format(2012.3, 100)).toBe('0.34 minutes');
|
|
50
|
+
expect(df.format(8000, 100)).toBe('1.33 minutes');
|
|
51
|
+
expect(df.formatPrecise(1, 100)).toBe('0.00017 minutes');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('correctly formats samples duration and return value without units', () => {
|
|
55
|
+
const df = getFormatter(160, 2, 'samples');
|
|
56
|
+
|
|
57
|
+
expect(df.suffix).toBe('minute');
|
|
58
|
+
expect(df.format(6000, 100, false)).toBe('1.00');
|
|
59
|
+
expect(df.format(100, 100, false)).toBe('0.02');
|
|
60
|
+
expect(df.format(2000, 100, false)).toBe('0.33');
|
|
61
|
+
expect(df.format(2012.3, 100, false)).toBe('0.34');
|
|
62
|
+
expect(df.format(8000, 100, false)).toBe('1.33');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('correctly formats trace samples', () => {
|
|
66
|
+
const df = getFormatter(80, 2, 'trace_samples');
|
|
67
|
+
|
|
68
|
+
expect(df.format(0.001, 100)).toBe('< 0.01 seconds');
|
|
69
|
+
expect(df.format(100, 100)).toBe('1.00 second');
|
|
70
|
+
expect(df.format(2000, 100)).toBe('20.00 seconds');
|
|
71
|
+
expect(df.format(2012.3, 100)).toBe('20.12 seconds');
|
|
72
|
+
expect(df.format(8000, 100)).toBe('80.00 seconds');
|
|
73
|
+
expect(df.formatPrecise(0.001, 100)).toBe('0.00001 seconds');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('correctly formats trace_samples duration when maxdur is less than second', () => {
|
|
77
|
+
const df = getFormatter(10, 100, 'trace_samples');
|
|
78
|
+
|
|
79
|
+
expect(df.format(55, 100)).toBe('550.00 ms');
|
|
80
|
+
expect(df.format(100, 100)).toBe('1000.00 ms');
|
|
81
|
+
expect(df.format(1.001, 100)).toBe('10.01 ms');
|
|
82
|
+
expect(df.format(9999, 100)).toBe('99990.00 ms');
|
|
83
|
+
expect(df.format(0.331, 100)).toBe('3.31 ms');
|
|
84
|
+
expect(df.format(0.0001, 100)).toBe('< 0.01 ms');
|
|
85
|
+
expect(df.formatPrecise(0.0001, 100)).toBe('0.001 ms');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('correctly formats trace_samples duration when maxdur is less than ms', () => {
|
|
89
|
+
const df = getFormatter(1, 10000, 'trace_samples');
|
|
90
|
+
|
|
91
|
+
expect(df.format(0.012, 100)).toBe('120.00 μs');
|
|
92
|
+
expect(df.format(0, 100)).toBe('0.00 μs');
|
|
93
|
+
expect(df.format(0.0091, 100)).toBe('91.00 μs');
|
|
94
|
+
expect(df.format(1.005199, 100)).toBe('10051.99 μs');
|
|
95
|
+
expect(df.format(1.1, 100)).toBe('11000.00 μs');
|
|
96
|
+
expect(df.format(0.000001, 100)).toBe('< 0.01 μs');
|
|
97
|
+
expect(df.formatPrecise(0.0000001, 100)).toBe('0.001 μs');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('correctly formats trace_samples duration when maxdur is hour', () => {
|
|
101
|
+
const hour = 3600;
|
|
102
|
+
let df = getFormatter(hour, 1, 'trace_samples');
|
|
103
|
+
|
|
104
|
+
expect(df.format(0, 100)).toBe('0.00 hours');
|
|
105
|
+
expect(df.format(hour * 100, 100)).toBe('1.00 hour');
|
|
106
|
+
expect(df.format(0.6 * hour * 100, 100)).toBe('0.60 hours');
|
|
107
|
+
expect(df.format(0.02 * hour * 100, 100)).toBe('0.02 hours');
|
|
108
|
+
expect(df.format(0.001 * hour * 100, 100)).toBe('< 0.01 hours');
|
|
109
|
+
expect(df.format(42.1 * hour * 100, 100)).toBe('42.10 hours');
|
|
110
|
+
expect(df.formatPrecise(0.001 * hour * 100, 100)).toBe('0.001 hours');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('correctly formats trace_samples duration when maxdur is day', () => {
|
|
114
|
+
const day = 24 * 60 * 60;
|
|
115
|
+
const df = getFormatter(day, 1, 'trace_samples');
|
|
116
|
+
|
|
117
|
+
expect(df.format(day * 100, 100)).toBe('1.00 day');
|
|
118
|
+
expect(df.format(12 * day * 100, 100)).toBe('12.00 days');
|
|
119
|
+
expect(df.format(2.29 * day * 100, 100)).toBe('2.29 days');
|
|
120
|
+
expect(df.format(0.11 * day * 100, 100)).toBe('0.11 days');
|
|
121
|
+
expect(df.format(0.001 * day * 100, 100)).toBe('< 0.01 days');
|
|
122
|
+
expect(df.formatPrecise(0.001 * day * 100, 100)).toBe('0.001 days');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('correctly formats trace_samples duration when maxdur = month', () => {
|
|
126
|
+
const month = 30 * 24 * 60 * 60;
|
|
127
|
+
const df = getFormatter(month, 1, 'trace_samples');
|
|
128
|
+
|
|
129
|
+
expect(df.format(month * 100, 100)).toBe('1.00 month');
|
|
130
|
+
expect(df.format(44 * month * 100, 100)).toBe('44.00 months');
|
|
131
|
+
expect(df.format(5.142 * month * 100, 100)).toBe('5.14 months');
|
|
132
|
+
expect(df.format(0.88 * month * 100, 100)).toBe('0.88 months');
|
|
133
|
+
expect(df.format(0.008 * month * 100, 100)).toBe('< 0.01 months');
|
|
134
|
+
expect(df.formatPrecise(0.008 * month * 100, 100)).toBe('0.008 months');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('correctly formats trace_samples duration when maxdur = year', () => {
|
|
138
|
+
const year = 12 * 30 * 24 * 60 * 60;
|
|
139
|
+
const df = getFormatter(year, 1, 'trace_samples');
|
|
140
|
+
|
|
141
|
+
expect(df.format(year * 100, 100)).toBe('1.00 year');
|
|
142
|
+
expect(df.format(12 * year * 100, 100)).toBe('12.00 years');
|
|
143
|
+
expect(df.format(3.414 * year * 100, 100)).toBe('3.41 years');
|
|
144
|
+
expect(df.format(0.12 * year * 100, 100)).toBe('0.12 years');
|
|
145
|
+
expect(df.format(0.008 * year * 100, 100)).toBe('< 0.01 years');
|
|
146
|
+
expect(df.formatPrecise(0.008 * year * 100, 100)).toBe('0.008 years');
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe('ObjectsFormatter', () => {
|
|
151
|
+
describe.each([
|
|
152
|
+
[1, -1, '-1.00 '],
|
|
153
|
+
[100_000, -1, '< 0.01 K'],
|
|
154
|
+
[1_000_000, -1, '< 0.01 M'],
|
|
155
|
+
[1_000_000_000, -1, '< 0.01 G'],
|
|
156
|
+
[1_000_000_000_000, -1, '< 0.01 T'],
|
|
157
|
+
[1_000_000_000_000_000, -1, '< 0.01 P'],
|
|
158
|
+
|
|
159
|
+
[1, 1, '1.00 '],
|
|
160
|
+
[100_000, 1, '< 0.01 K'],
|
|
161
|
+
[1_000_000, 1, '< 0.01 M'],
|
|
162
|
+
[1_000_000_000, 1, '< 0.01 G'],
|
|
163
|
+
[1_000_000_000_000, 1, '< 0.01 T'],
|
|
164
|
+
[1_000_000_000_000_000, 1, '< 0.01 P'],
|
|
165
|
+
|
|
166
|
+
// if the tests here feel random, that's because they are
|
|
167
|
+
// input and outputs were reproduced from real data
|
|
168
|
+
[829449, 829449, '829.45 K'],
|
|
169
|
+
[747270, 747270, '747.27 K'],
|
|
170
|
+
[747270, 273208, '273.21 K'],
|
|
171
|
+
[747270, 37257, '37.26 K'],
|
|
172
|
+
[747270, 140789, '140.79 K'],
|
|
173
|
+
[747270, 183646, '183.65 K'],
|
|
174
|
+
[747270, 67736, '67.74 K'],
|
|
175
|
+
[747270, 243513, '243.51 K'],
|
|
176
|
+
[747270, 55297, '55.30 K'],
|
|
177
|
+
[747270, 62261, '62.26 K'],
|
|
178
|
+
[747270, 98304, '98.30 K'],
|
|
179
|
+
[747270, 65536, '65.54 K'],
|
|
180
|
+
|
|
181
|
+
[280614985, 124590057, '124.59 M'],
|
|
182
|
+
[280614985, 15947382, '15.95 M'],
|
|
183
|
+
[280614985, 15949534, '15.95 M'],
|
|
184
|
+
[280614985, 23392042, '23.39 M'],
|
|
185
|
+
[280614985, 100988801, '100.99 M'],
|
|
186
|
+
[280614985, 280614985, '280.61 M'],
|
|
187
|
+
[280614985, 30556974, '30.56 M'],
|
|
188
|
+
[280614985, 51105740, '51.11 M'],
|
|
189
|
+
[280614985, 92737376, '92.74 M'],
|
|
190
|
+
|
|
191
|
+
[1536297877, 166358124, '0.17 G'],
|
|
192
|
+
[1536297877, 94577307, '0.09 G'],
|
|
193
|
+
[1536297877, 205971847, '0.21 G'],
|
|
194
|
+
[1536297877, 245667926, '0.25 G'],
|
|
195
|
+
])(
|
|
196
|
+
'new ObjectsFormatter(%i).format(%i, %i)',
|
|
197
|
+
(maxObjects: number, samples: number, expected: string) => {
|
|
198
|
+
it(`returns ${expected}`, () => {
|
|
199
|
+
// sampleRate is not used
|
|
200
|
+
const sampleRate = NaN;
|
|
201
|
+
const f = getFormatter(maxObjects, sampleRate, 'objects');
|
|
202
|
+
|
|
203
|
+
expect(f.format(samples, sampleRate)).toBe(expected);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
describe('ObjectsFormatter formatPrecise', () => {
|
|
210
|
+
describe.each([
|
|
211
|
+
[1, -1, '-1 '],
|
|
212
|
+
[100_000, -1, '-0.001 K'],
|
|
213
|
+
|
|
214
|
+
[1, 1, '1 '],
|
|
215
|
+
[100_000, 1, '0.001 K'],
|
|
216
|
+
])(
|
|
217
|
+
'new ObjectsFormatter(%i).format(%i, %i)',
|
|
218
|
+
(maxObjects: number, samples: number, expected: string) => {
|
|
219
|
+
it(`returns ${expected}`, () => {
|
|
220
|
+
// sampleRate is not used
|
|
221
|
+
const sampleRate = NaN;
|
|
222
|
+
const f = getFormatter(maxObjects, sampleRate, 'objects');
|
|
223
|
+
|
|
224
|
+
expect(f.formatPrecise(samples, sampleRate)).toBe(expected);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
describe('BytesFormatter', () => {
|
|
231
|
+
describe.each([
|
|
232
|
+
[1, -1, '-1.00 bytes'], // TODO is this correct?
|
|
233
|
+
[1024, -1, '< 0.01 KB'],
|
|
234
|
+
[1024 ** 2, -1, '< 0.01 MB'],
|
|
235
|
+
[1024 ** 3, -1, '< 0.01 GB'],
|
|
236
|
+
[1024 ** 4, -1, '< 0.01 TB'],
|
|
237
|
+
|
|
238
|
+
[1, 1, '1.00 bytes'],
|
|
239
|
+
[1024, 1, '< 0.01 KB'],
|
|
240
|
+
[1024 ** 2, 1, '< 0.01 MB'],
|
|
241
|
+
[1024 ** 3, 1, '< 0.01 GB'],
|
|
242
|
+
[1024 ** 4, 1, '< 0.01 TB'],
|
|
243
|
+
|
|
244
|
+
// if the tests here feel random, that's because they are
|
|
245
|
+
// input and outputs were reproduced from real data
|
|
246
|
+
[338855357, 269094260, '256.63 MB'],
|
|
247
|
+
[338855357, 21498656, '20.50 MB'],
|
|
248
|
+
[33261774660, 2369569091, '2.21 GB'],
|
|
249
|
+
[33261774660, 12110767522, '11.28 GB'],
|
|
250
|
+
])(
|
|
251
|
+
'new BytesFormatter(%i).format(%i, %i)',
|
|
252
|
+
(maxObjects: number, samples: number, expected: string) => {
|
|
253
|
+
it(`returns ${expected}`, () => {
|
|
254
|
+
// sampleRate is not used
|
|
255
|
+
const sampleRate = NaN;
|
|
256
|
+
const f = getFormatter(maxObjects, sampleRate, 'bytes');
|
|
257
|
+
|
|
258
|
+
expect(f.format(samples, sampleRate)).toBe(expected);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
describe('BytesFormatter', () => {
|
|
265
|
+
describe.each([
|
|
266
|
+
[1, -1, '-1 bytes'],
|
|
267
|
+
[1024, -1, '-0.00098 KB'],
|
|
268
|
+
[1024 ** 2, -10, '-0.00001 MB'],
|
|
269
|
+
[1024 ** 3, -10000, '-0.00001 GB'],
|
|
270
|
+
[1024 ** 4, -10000000, '-0.00001 TB'],
|
|
271
|
+
|
|
272
|
+
[1, 1, '1 bytes'],
|
|
273
|
+
[1024, 1, '0.00098 KB'],
|
|
274
|
+
[1024 ** 2, 10, '0.00001 MB'],
|
|
275
|
+
[1024 ** 3, 10000, '0.00001 GB'],
|
|
276
|
+
[1024 ** 4, 10000000, '0.00001 TB'],
|
|
277
|
+
])(
|
|
278
|
+
'new BytesFormatter(%i).format(%i, %i)',
|
|
279
|
+
(maxObjects: number, samples: number, expected: string) => {
|
|
280
|
+
it(`returns ${expected}`, () => {
|
|
281
|
+
// sampleRate is not used
|
|
282
|
+
const sampleRate = NaN;
|
|
283
|
+
const f = getFormatter(maxObjects, sampleRate, 'bytes');
|
|
284
|
+
|
|
285
|
+
expect(f.formatPrecise(samples, sampleRate)).toBe(expected);
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
);
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
});
|