-
Notifications
You must be signed in to change notification settings - Fork 484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add trace visualization as a FlameGraph #976
Merged
yurishkuro
merged 3 commits into
jaegertracing:main
from
pyroscope-io:viz-trace-flamegraph
Aug 10, 2022
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
65 changes: 65 additions & 0 deletions
65
packages/jaeger-ui/src/components/TracePage/TraceFlamegraph/__snapshots__/index.test.js.snap
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,65 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<TraceFlamegraph /> renders as expected 1`] = ` | ||
<div | ||
className="Flamegraph-wrapper" | ||
> | ||
<dg | ||
colorMode="light" | ||
profile={ | ||
Object { | ||
"flamebearer": Object { | ||
"levels": Array [ | ||
Array [ | ||
0, | ||
1181596, | ||
0, | ||
0, | ||
], | ||
Array [ | ||
0, | ||
1181596, | ||
213262, | ||
1, | ||
], | ||
Array [ | ||
0, | ||
968334, | ||
1268, | ||
2, | ||
], | ||
Array [ | ||
0, | ||
967066, | ||
733, | ||
3, | ||
], | ||
Array [ | ||
0, | ||
966333, | ||
966333, | ||
4, | ||
], | ||
], | ||
"maxSelf": 0, | ||
"names": Array [ | ||
"total", | ||
"load-generator: OrderVehicle", | ||
"load-generator: HTTP GET", | ||
"ride-sharing-app: BikeHandler", | ||
"ride-sharing-app: FindNearestVehicle", | ||
], | ||
"numTicks": 1181596, | ||
}, | ||
"metadata": Object { | ||
"format": "single", | ||
"sampleRate": 1000000, | ||
"spyName": "tracing", | ||
"units": "trace_samples", | ||
}, | ||
"version": 1, | ||
} | ||
} | ||
/> | ||
</div> | ||
`; |
18 changes: 18 additions & 0 deletions
18
packages/jaeger-ui/src/components/TracePage/TraceFlamegraph/index.css
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,18 @@ | ||
/* | ||
Copyright (c) 2022 The Jaeger Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
.Flamegraph-wrapper { | ||
padding: 0 calc(1rem - 5px); | ||
} |
71 changes: 71 additions & 0 deletions
71
packages/jaeger-ui/src/components/TracePage/TraceFlamegraph/index.test.js
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,71 @@ | ||
// Copyright (c) 2022 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { convertJaegerTraceToProfile } from '@pyroscope/flamegraph'; | ||
|
||
import TraceFlamegraph from './index'; | ||
|
||
const testTrace = require('./testTrace.json'); | ||
|
||
const profile = convertJaegerTraceToProfile(testTrace.data); | ||
|
||
describe('convertJaegerTraceToProfile', () => { | ||
it('returns correct profile format', () => { | ||
expect(profile.version).toBe(1); | ||
|
||
expect(Array.isArray(profile.flamebearer.levels)).toBe(true); | ||
expect(profile.flamebearer.levels[0].every(el => typeof el === 'number')).toBe(true); | ||
expect(Array.isArray(profile.flamebearer.names)).toBe(true); | ||
expect(profile.flamebearer.names.every(el => typeof el === 'string')).toBe(true); | ||
expect(typeof profile.flamebearer.numTicks).toBe('number'); | ||
|
||
expect(typeof profile.metadata.format).toBe('string'); | ||
expect(typeof profile.metadata.sampleRate).toBe('number'); | ||
expect(typeof profile.metadata.spyName).toBe('string'); | ||
expect(typeof profile.metadata.units).toBe('string'); | ||
}); | ||
}); | ||
|
||
describe('<TraceFlamegraph />', () => { | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
const props = { trace: testTrace }; | ||
wrapper = shallow(<TraceFlamegraph {...props} />); | ||
}); | ||
|
||
it('renders as expected', () => { | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
it('does not explode', () => { | ||
expect(wrapper).toBeDefined(); | ||
expect(wrapper.find('.Flamegraph-wrapper').length).toBe(1); | ||
}); | ||
|
||
it('renders profile table and flamegraph', () => { | ||
expect(wrapper).toBeDefined(); | ||
expect(wrapper.html().includes('flamegraph-table')).toBe(true); | ||
expect(wrapper.html().includes('flamegraph-view')).toBe(true); | ||
}); | ||
|
||
it('may show no profile', () => { | ||
const props = {}; | ||
wrapper = shallow(<TraceFlamegraph {...props} />); | ||
expect(wrapper).toBeDefined(); | ||
expect(wrapper.html().includes('no-profiling-data')).toBe(true); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
packages/jaeger-ui/src/components/TracePage/TraceFlamegraph/index.tsx
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,30 @@ | ||
// Copyright (c) 2022 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
import React from 'react'; | ||
import { FlamegraphRenderer, convertJaegerTraceToProfile } from '@pyroscope/flamegraph'; | ||
|
||
import '@pyroscope/flamegraph/dist/index.css'; | ||
import './index.css'; | ||
|
||
const TraceFlamegraph = ({ trace }: any) => { | ||
const convertedProfile = trace && trace.data ? convertJaegerTraceToProfile(trace.data) : null; | ||
|
||
return ( | ||
<div className="Flamegraph-wrapper"> | ||
<FlamegraphRenderer colorMode="light" profile={convertedProfile} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default TraceFlamegraph; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add some basic tests like "does not explode" and snapshot?