Skip to content

Commit

Permalink
Cleanup after the new active tab timeline component (Merge PR firefox…
Browse files Browse the repository at this point in the history
  • Loading branch information
canova committed Apr 21, 2020
2 parents 0468900 + bd7560d commit 7dc1bac
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 308 deletions.
103 changes: 1 addition & 102 deletions src/actions/receive-profile.js
Expand Up @@ -41,10 +41,6 @@ import {
initializeHiddenGlobalTracks,
getVisibleThreads,
} from '../profile-logic/tracks';
import {
computeActiveTabHiddenGlobalTracks,
computeActiveTabHiddenLocalTracksByPid,
} from '../profile-logic/active-tab';
import { getProfileOrNull, getProfile } from '../selectors/profile';
import { getView } from '../selectors/app';
import { setDataSource } from './profile-view';
Expand Down Expand Up @@ -293,107 +289,10 @@ export function finalizeActiveTabProfileView(
selectedThreadIndex: ThreadIndex,
showTabOnly?: BrowsingContextID | null
): ThunkAction<void> {
return (dispatch, getState) => {
const hasUrlInfo = selectedThreadIndex !== null;

const globalTracks = computeGlobalTracks(profile);
const globalTrackOrder = initializeGlobalTrackOrder(
globalTracks,
hasUrlInfo ? getGlobalTrackOrder(getState()) : null,
getLegacyThreadOrder(getState())
);
let hiddenGlobalTracks = initializeHiddenGlobalTracks(
globalTracks,
profile,
globalTrackOrder,
hasUrlInfo ? getHiddenGlobalTracks(getState()) : null,
getLegacyHiddenThreads(getState())
);
// Pre-compute which tracks are not available for the active tab.
const activeTabHiddenGlobalTracksGetter = () =>
computeActiveTabHiddenGlobalTracks(
globalTracks,
getState() // we need to access per thread selectors inside
);
const localTracksByPid = computeLocalTracksByPid(profile);
const localTrackOrderByPid = initializeLocalTrackOrderByPid(
hasUrlInfo ? getLocalTrackOrderByPid(getState()) : null,
localTracksByPid,
getLegacyThreadOrder(getState())
);
let hiddenLocalTracksByPid = initializeHiddenLocalTracksByPid(
hasUrlInfo ? getHiddenLocalTracksByPid(getState()) : null,
localTracksByPid,
profile,
getLegacyHiddenThreads(getState())
);
// Pre-compute which local tracks are not available for the active tab.
const activeTabHiddenLocalTracksByPidGetter = () =>
computeActiveTabHiddenLocalTracksByPid(
localTracksByPid,
getState() // we need to access per thread selectors inside
);
let visibleThreadIndexes = getVisibleThreads(
globalTracks,
hiddenGlobalTracks,
localTracksByPid,
hiddenLocalTracksByPid
);

// This validity check can't be extracted into a separate function, as it needs
// to update a lot of the local variables in this function.
if (visibleThreadIndexes.length === 0) {
// All threads are hidden, since this can't happen normally, revert them all.
visibleThreadIndexes = profile.threads.map(
(_, threadIndex) => threadIndex
);
hiddenGlobalTracks = new Set();
const newHiddenTracksByPid = new Map();
for (const [pid] of hiddenLocalTracksByPid) {
newHiddenTracksByPid.set(pid, new Set());
}
hiddenLocalTracksByPid = newHiddenTracksByPid;
}

selectedThreadIndex = initializeSelectedThreadIndex(
selectedThreadIndex,
visibleThreadIndexes,
profile
);

// If all of the local tracks were hidden for a process, and the main thread was
// not recorded for that process, hide the (empty) process track as well.
for (const [pid, localTracks] of localTracksByPid) {
const hiddenLocalTracks = hiddenLocalTracksByPid.get(pid);
if (!hiddenLocalTracks) {
continue;
}
if (hiddenLocalTracks.size === localTracks.length) {
// All of the local tracks were hidden.
const globalTrackIndex = globalTracks.findIndex(
globalTrack =>
globalTrack.type === 'process' &&
globalTrack.pid === pid &&
globalTrack.mainThreadIndex === null
);
if (globalTrackIndex !== -1) {
// An empty global track was found, hide it.
hiddenGlobalTracks.add(globalTrackIndex);
}
}
}

return dispatch => {
dispatch({
type: 'VIEW_ACTIVE_TAB_PROFILE',
selectedThreadIndex,
globalTracks,
globalTrackOrder,
hiddenGlobalTracks,
localTracksByPid,
hiddenLocalTracksByPid,
localTrackOrderByPid,
activeTabHiddenGlobalTracksGetter,
activeTabHiddenLocalTracksByPidGetter,
showTabOnly,
});
};
Expand Down
12 changes: 4 additions & 8 deletions src/reducers/profile-view.js
Expand Up @@ -92,7 +92,6 @@ const profile: Reducer<Profile | null> = (state = null, action) => {
const globalTracks: Reducer<GlobalTrack[]> = (state = [], action) => {
switch (action.type) {
case 'VIEW_FULL_PROFILE':
case 'VIEW_ACTIVE_TAB_PROFILE':
return action.globalTracks;
default:
return state;
Expand All @@ -109,7 +108,6 @@ const localTracksByPid: Reducer<Map<Pid, LocalTrack[]>> = (
) => {
switch (action.type) {
case 'VIEW_FULL_PROFILE':
case 'VIEW_ACTIVE_TAB_PROFILE':
return action.localTracksByPid;
default:
return state;
Expand All @@ -126,8 +124,6 @@ const activeTabHiddenGlobalTracksGetter: Reducer<() => Set<TrackIndex>> = (
action
) => {
switch (action.type) {
case 'VIEW_ACTIVE_TAB_PROFILE':
return action.activeTabHiddenGlobalTracksGetter;
default:
return state;
}
Expand All @@ -141,8 +137,6 @@ const activeTabHiddenLocalTracksByPidGetter: Reducer<
() => Map<Pid, Set<TrackIndex>>
> = (state = () => new Map(), action) => {
switch (action.type) {
case 'VIEW_ACTIVE_TAB_PROFILE':
return action.activeTabHiddenLocalTracksByPidGetter;
default:
return state;
}
Expand Down Expand Up @@ -619,9 +613,11 @@ const profileViewReducer: Reducer<ProfileViewState> = wrapReducerInResetter(
rightClickedCallNode,
rightClickedMarker,
}),
globalTracks,
localTracksByPid,
profile,
full: combineReducers({
globalTracks,
localTracksByPid,
}),
activeTab: combineReducers({
hiddenGlobalTracksGetter: activeTabHiddenGlobalTracksGetter,
hiddenLocalTracksByPidGetter: activeTabHiddenLocalTracksByPidGetter,
Expand Down
4 changes: 0 additions & 4 deletions src/reducers/url-state.js
Expand Up @@ -286,7 +286,6 @@ const showJsTracerSummary: Reducer<boolean> = (state = false, action) => {
const globalTrackOrder: Reducer<TrackIndex[]> = (state = [], action) => {
switch (action.type) {
case 'VIEW_FULL_PROFILE':
case 'VIEW_ACTIVE_TAB_PROFILE':
case 'CHANGE_GLOBAL_TRACK_ORDER':
return action.globalTrackOrder;
case 'SANITIZED_PROFILE_PUBLISHED':
Expand All @@ -304,7 +303,6 @@ const hiddenGlobalTracks: Reducer<Set<TrackIndex>> = (
) => {
switch (action.type) {
case 'VIEW_FULL_PROFILE':
case 'VIEW_ACTIVE_TAB_PROFILE':
case 'ISOLATE_LOCAL_TRACK':
case 'ISOLATE_PROCESS':
case 'ISOLATE_PROCESS_MAIN_THREAD':
Expand Down Expand Up @@ -335,7 +333,6 @@ const hiddenLocalTracksByPid: Reducer<Map<Pid, Set<TrackIndex>>> = (
) => {
switch (action.type) {
case 'VIEW_FULL_PROFILE':
case 'VIEW_ACTIVE_TAB_PROFILE':
return action.hiddenLocalTracksByPid;
case 'HIDE_LOCAL_TRACK': {
const hiddenLocalTracksByPid = new Map(state);
Expand Down Expand Up @@ -371,7 +368,6 @@ const localTrackOrderByPid: Reducer<Map<Pid, TrackIndex[]>> = (
) => {
switch (action.type) {
case 'VIEW_FULL_PROFILE':
case 'VIEW_ACTIVE_TAB_PROFILE':
return action.localTrackOrderByPid;
case 'CHANGE_LOCAL_TRACK_ORDER': {
const localTrackOrderByPid = new Map(state);
Expand Down
9 changes: 6 additions & 3 deletions src/selectors/profile.js
Expand Up @@ -54,12 +54,15 @@ import type {
State,
ProfileViewState,
SymbolicationStatus,
FullProfileViewState,
ActiveTabProfileViewState,
} from '../types/state';
import type { $ReturnType } from '../types/utils';

export const getProfileView: Selector<ProfileViewState> = state =>
state.profileView;
export const getFullProfileView: Selector<FullProfileViewState> = state =>
getProfileView(state).full;
export const getActiveTabProfileView: Selector<ActiveTabProfileViewState> = state =>
getProfileView(state).activeTab;

Expand Down Expand Up @@ -237,7 +240,7 @@ export const getIPCMarkerCorrelations: Selector<IPCMarkerCorrelations> = createS
* They're uniquely referenced by a TrackReference.
*/
export const getGlobalTracks: Selector<GlobalTrack[]> = state =>
getProfileView(state).globalTracks;
getFullProfileView(state).globalTracks;

/**
* This returns all TrackReferences for global tracks.
Expand Down Expand Up @@ -304,7 +307,7 @@ export const getGlobalTrackAndIndexByPid: DangerousSelectorWithArguments<
* This returns a map of local tracks from a pid.
*/
export const getLocalTracksByPid: Selector<Map<Pid, LocalTrack[]>> = state =>
getProfileView(state).localTracksByPid;
getFullProfileView(state).localTracksByPid;

/**
* This selectors performs a simple look up in a Map, throws an error if it doesn't exist,
Expand All @@ -316,7 +319,7 @@ export const getLocalTracks: DangerousSelectorWithArguments<
Pid
> = (state, pid) =>
ensureExists(
getProfileView(state).localTracksByPid.get(pid),
getFullProfileView(state).localTracksByPid.get(pid),
'Unable to get the tracks for the given pid.'
);

Expand Down
13 changes: 0 additions & 13 deletions src/test/components/TrackContextMenu.test.js
Expand Up @@ -13,7 +13,6 @@ import {
changeSelectedThread,
changeRightClickedTrack,
} from '../../actions/profile-view';
import { changeViewAndRecomputeProfileData } from '../../actions/receive-profile';
import TrackContextMenu from '../../components/timeline/TrackContextMenu';
import { getGlobalTracks, getLocalTracks } from '../../selectors/profile';
import {
Expand Down Expand Up @@ -199,18 +198,6 @@ describe('timeline/TrackContextMenu', function() {
// use the functions used by context menu directly and gives us wrong results.
expect(container.firstChild).toMatchSnapshot();
});

it('network track will be hidden when a number is set for showTabOnly', () => {
const { dispatch, container } = setupGlobalTrack(
getNetworkTrackProfile(),
0
);
// parameter doesn't matter here, it can be anything except null.
dispatch(changeViewAndRecomputeProfileData(111));
// We can't use getHumanReadableTracks here because that function doesn't
// use the functions used by context menu directly and gives us wrong results.
expect(container.firstChild).toMatchSnapshot();
});
});

describe('selected local track', function() {
Expand Down
41 changes: 0 additions & 41 deletions src/test/components/__snapshots__/TrackContextMenu.test.js.snap
Expand Up @@ -225,47 +225,6 @@ exports[`timeline/TrackContextMenu selected global track network track will be d
</nav>
`;

exports[`timeline/TrackContextMenu selected global track network track will be hidden when a number is set for showTabOnly 1`] = `
<nav
class="react-contextmenu timeline-context-menu"
role="menu"
style="position: fixed; opacity: 0; pointer-events: none;"
tabindex="-1"
>
<div>
<div
aria-disabled="false"
class="react-contextmenu-item timelineTrackContextMenuItem checkable checked"
role="menuitem"
tabindex="-1"
title="Process 0 (Process ID: 0)"
>
<span>
Process 0
</span>
<span
class="timelineTrackContextMenuSpacer"
/>
<span
class="timelineTrackContextMenuPid"
>
(
0
)
</span>
</div>
<div
aria-disabled="false"
class="react-contextmenu-item checkable indented checked"
role="menuitem"
tabindex="-1"
>
Empty
</div>
</div>
</nav>
`;

exports[`timeline/TrackContextMenu selected local track matches the snapshot of a local track 1`] = `
<nav
class="react-contextmenu timeline-context-menu"
Expand Down

0 comments on commit 7dc1bac

Please sign in to comment.