Skip to content

Commit

Permalink
Review comments: Show only the call tree for the comparison track
Browse files Browse the repository at this point in the history
  • Loading branch information
julienw committed Jul 12, 2019
1 parent ed4852c commit 99e9e5d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/selectors/per-thread/composed.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,16 @@ export function getComposedSelectorsPerThread(
* when it's absurd.
*/
const getUsefulTabs: Selector<$ReadOnlyArray<TabSlug>> = createSelector(
threadSelectors.getThread,
threadSelectors.getIsNetworkChartEmptyInFullRange,
threadSelectors.getJsTracerTable,
(isNetworkChartEmpty, jsTracerTable) => {
({ processType }, isNetworkChartEmpty, jsTracerTable) => {
if (processType === 'comparison') {
// For a diffing tracks, we display only the calltree tab for now, because
// other views make no or not much sense.
return ['calltree'];
}

let visibleTabs = tabSlugs;
if (isNetworkChartEmpty) {
visibleTabs = visibleTabs.filter(
Expand Down
18 changes: 18 additions & 0 deletions src/test/fixtures/profiles/processed-profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
getEmptyJsTracerTable,
resourceTypes,
} from '../../../profile-logic/data-structures';
import { mergeProfiles } from '../../../profile-logic/comparison';
import { stateFromLocation } from '../../../app-logic/url-handling';
import { UniqueStringArray } from '../../../utils/unique-string-array';

import type {
Expand Down Expand Up @@ -531,6 +533,22 @@ function _buildThreadFromTextOnlyStacks(
return thread;
}

/**
* This returns a merged profile from a number of profile strings.
*/
export function getMergedProfileFromTextSamples(...profileStrings: string[]) {
const profiles = profileStrings.map(
str => getProfileFromTextSamples(str).profile
);
const profileState = stateFromLocation({
pathname: '/public/fakehash1/',
search: '?thread=0&v=3',
hash: '',
});
const { profile } = mergeProfiles(profiles, profiles.map(() => profileState));
return profile;
}

type NetworkMarkersOptions = {|
uri: string,
id: number,
Expand Down
25 changes: 25 additions & 0 deletions src/test/store/profile-view.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { TabSlug } from '../../app-logic/tabs-handling';

import {
getProfileFromTextSamples,
getMergedProfileFromTextSamples,
getProfileWithMarkers,
getNetworkTrackProfile,
getScreenshotTrackProfile,
Expand Down Expand Up @@ -443,6 +444,30 @@ describe('actions/ProfileView', function() {
});
});

describe('with a comparison profile', function() {
it('selects the calltree tab when selecting the diffing track', function() {
const diffingTrackReference = {
type: 'global',
trackIndex: 2,
};

const profile = getMergedProfileFromTextSamples('A B C', 'A B B');
const { getState, dispatch } = storeWithProfile(profile);

dispatch(App.changeSelectedTab('flame-graph'));
expect(UrlStateSelectors.getSelectedThreadIndex(getState())).toEqual(0);
expect(UrlStateSelectors.getSelectedTab(getState())).toEqual(
'flame-graph'
);

dispatch(ProfileView.selectTrack(diffingTrackReference));
expect(UrlStateSelectors.getSelectedThreadIndex(getState())).toEqual(2);
expect(UrlStateSelectors.getSelectedTab(getState())).toEqual(
'calltree'
);
});
});

describe('when the loaded panel is not the call tree', function() {
it('stays in the same panel when selecting another track', function() {
const { getState, dispatch, parentTrack } = setup('marker-chart');
Expand Down
22 changes: 22 additions & 0 deletions src/test/store/useful-tabs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getProfileWithMarkers,
getNetworkMarkers,
getProfileWithJsTracerEvents,
getMergedProfileFromTextSamples,
} from '../fixtures/profiles/processed-profile';

describe('getUsefulTabs', function() {
Expand Down Expand Up @@ -51,4 +52,25 @@ describe('getUsefulTabs', function() {
'js-tracer',
]);
});

it('shows only the call tree when a diffing track is selected', function() {
const profile = getMergedProfileFromTextSamples('A B C', 'A B B');
const { getState, dispatch } = storeWithProfile(profile);
expect(selectedThreadSelectors.getUsefulTabs(getState())).toEqual([
'calltree',
'flame-graph',
'stack-chart',
'marker-chart',
'marker-table',
]);

dispatch({
type: 'SELECT_TRACK',
selectedThreadIndex: 2,
selectedTab: 'calltree',
});
expect(selectedThreadSelectors.getUsefulTabs(getState())).toEqual([
'calltree',
]);
});
});

0 comments on commit 99e9e5d

Please sign in to comment.