-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
feat(debug): Add timing information about time to first image/all images, and query time #3681
Changes from 1 commit
11cb76c
bfc7a00
40a52e1
9307305
4c5859d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { log, Types } from '@ohif/core'; | ||
import { EVENTS } from '@cornerstonejs/core'; | ||
|
||
const { TimingEnum } = Types; | ||
|
||
const IMAGE_TIMING_KEYS = [ | ||
TimingEnum.DISPLAY_SETS_TO_ALL_IMAGES, | ||
TimingEnum.DISPLAY_SETS_TO_FIRST_IMAGE, | ||
TimingEnum.STUDY_TO_FIRST_IMAGE, | ||
]; | ||
|
||
const imageTiming = { | ||
viewportsWaiting: 0, | ||
}; | ||
|
||
/** | ||
* Defines the initial view timing reporting. | ||
* This allows knowing how many viewports are waiting for initial views and | ||
* when the IMAGE_RENDERED gets sent out. | ||
* The first image rendered will fire the FIRST_IMAGE timeEnd logs, while | ||
* the last of the enabled viewport will fire the ALL_IMAGES timeEnd logs. | ||
* | ||
*/ | ||
|
||
export default function initViewTiming({ element }) { | ||
if (!IMAGE_TIMING_KEYS.find(key => log.timingKeys[key])) { | ||
return; | ||
} | ||
imageTiming.viewportsWaiting += 1; | ||
element.addEventListener(EVENTS.IMAGE_RENDERED, imageRenderedListener); | ||
} | ||
|
||
function imageRenderedListener(evt) { | ||
if (evt.detail.viewportStatus === 'preRender') { | ||
return; | ||
} | ||
log.timeEnd(TimingEnum.DISPLAY_SETS_TO_FIRST_IMAGE); | ||
log.timeEnd(TimingEnum.STUDY_TO_FIRST_IMAGE); | ||
log.timeEnd(TimingEnum.SCRIPT_TO_VIEW); | ||
imageTiming.viewportsWaiting -= 1; | ||
evt.detail.element.removeEventListener(EVENTS.IMAGE_RENDERED, imageRenderedListener); | ||
if (!imageTiming.viewportsWaiting) { | ||
log.timeEnd(TimingEnum.DISPLAY_SETS_TO_ALL_IMAGES); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,23 @@ const log = { | |
info: console.log, | ||
trace: console.trace, | ||
debug: console.debug, | ||
time: console.time, | ||
timeEnd: console.timeEnd, | ||
time: key => { | ||
log.timingKeys[key] = true; | ||
console.time(key); | ||
}, | ||
timeEnd: key => { | ||
if (!log.timingKeys[key]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we consle.warn here before retun that key does not exist? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is specifically avoided - we get lots more time ends than we do time starts, and we don't care that the key doesn't exist any longer. |
||
return; | ||
} | ||
log.timingKeys[key] = false; | ||
console.timeEnd(key); | ||
}, | ||
// Store the timing keys to allow knowing whether or not to log events | ||
timingKeys: { | ||
// script time values are added before log is loaded, and the log | ||
// shouldn't depend on the enums, so for this case recreate the string. | ||
scriptToView: true, | ||
}, | ||
wayfarer3130 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
export default log; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export enum TimingEnum { | ||
STUDY_TO_DISPLAY_SETS = 'studyToDisplaySetsLoaded', | ||
STUDY_TO_FIRST_IMAGE = 'studyToFirstImage', | ||
DISPLAY_SETS_TO_FIRST_IMAGE = 'displaySetsToFirstImage', | ||
sedghi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
DISPLAY_SETS_TO_ALL_IMAGES = 'displaySetsToAllImages', | ||
wayfarer3130 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
SCRIPT_TO_VIEW = 'scriptToView', | ||
SEARCH_TO_LIST = 'searchToList', | ||
wayfarer3130 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
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.
this has a bug regarding which image rendered, you should check the viewportId and check if it is the same id no?
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.
No, because we only care that the count of viewports matches - we un subscribe after the first event that is rendered from each viewport, so each viewport can only get 1 count for it, and we have the total count number. The logic of the event handling deals with matching up viewport id's to renders. The logging isn't for this viewport rendered for first image, it is for any cornerstone viewport rendering.