/** @jsx h */
import { Component, h } from 'preact';
import './JourneyView.css';
class JourneyView extends Component {
render() {
const journey = this.props.spec.journey;
if (journey.type === 'SPAWN_DIRECTLY') {
return this.renderSpawnDirectlyJourney();
} else if (journey.type === 'START_PRELOADER') {
return this.renderStartPreloaderJourney();
} else {
return this.renderSpawnThroughPreloaderJourney();
}
}
renderSpawnDirectlyJourney() {
const self = this;
function renderWrapperRows() {
if (!self.props.spec.journey.steps.SUBPROCESS_EXEC_WRAPPER) {
return [];
}
if (self.props.spec.config.wrapper_supplied_by_third_party) {
return [
(
{self.renderCell('subprocess', 'Initialize third-party wrapper',
['SUBPROCESS_EXEC_WRAPPER', 'SUBPROCESS_WRAPPER_PREPARATION'])}
),
(
{self.renderStepSeparator('subprocess')}
)
];
} else {
return [
(
{self.renderCell('subprocess', 'Initialize language runtime',
['SUBPROCESS_EXEC_WRAPPER', 'SUBPROCESS_WRAPPER_PREPARATION'])}
),
(
{self.renderStepSeparator('subprocess')}
)
];
}
}
return (
In {this.props.spec.short_program_name} core
PID {this.props.spec.diagnostics.core_process.pid}
In subprocess
PID {this.props.spec.diagnostics.subprocess.pid || 'unknown'}
{this.renderCell('server-core', 'Preparation work',
['SPAWNING_KIT_PREPARATION'])}
{this.renderStepSeparator('server-core')}
{this.renderCell('server-core', 'Spawn subprocess (fork())',
['SPAWNING_KIT_FORK_SUBPROCESS'])}
{this.renderProcessBoundaryArrow()}
{this.renderCell('subprocess', 'Basic initialization before exec()',
['SUBPROCESS_BEFORE_FIRST_EXEC'])}
{this.renderStepSeparator('server-core')}
{this.renderStepSeparator('subprocess')}
{this.renderCell('server-core', 'Handshake with subprocess',
['SPAWNING_KIT_HANDSHAKE_PERFORM'])}
{this.renderCell('subprocess', 'Setup environment (1)',
['SUBPROCESS_SPAWN_ENV_SETUPPER_BEFORE_SHELL'])}
{this.renderStepSeparator('server-core')}
{this.renderStepSeparator('subprocess')}
{this.renderCell('server-core', 'Finish',
['SPAWNING_KIT_FINISH'])}
{this.renderCell('subprocess', 'Load OS shell',
['SUBPROCESS_OS_SHELL'])}
{this.renderStepSeparator('subprocess')}
{this.renderCell('subprocess', 'Setup environment (2)',
['SUBPROCESS_SPAWN_ENV_SETUPPER_AFTER_SHELL'])}
{this.renderStepSeparator('subprocess')}
{renderWrapperRows()}
{this.renderCell('subprocess', 'Load or execute application',
['SUBPROCESS_APP_LOAD_OR_EXEC'])}
{this.renderStepSeparator('subprocess')}
{this.renderCell('subprocess', 'App start listening for requests',
['SUBPROCESS_LISTEN'])}
{this.renderStepSeparator('subprocess')}
{this.renderCell('subprocess', 'Finish',
['SUBPROCESS_FINISH'])}
);
}
renderStartPreloaderJourney() {
const self = this;
function renderWrapperRows() {
if (!self.props.spec.journey.steps.SUBPROCESS_EXEC_WRAPPER) {
return [];
}
if (self.props.spec.config.wrapper_supplied_by_third_party) {
return [
(
{self.renderCell('subprocess', 'Initialize language runtime',
['SUBPROCESS_EXEC_WRAPPER'])}
),
(
{self.renderStepSeparator('subprocess')}
),
(
{self.renderCell('subprocess', 'Initialize third-party preloading wrapper',
['SUBPROCESS_WRAPPER_PREPARATION'])}
),
(
{self.renderStepSeparator('subprocess')}
)
];
} else {
return [
(
{self.renderCell('subprocess', 'Initialize language runtime',
['SUBPROCESS_EXEC_WRAPPER'])}
),
(
{self.renderStepSeparator('subprocess')}
),
(
{self.renderCell('subprocess',
'Initialize ' + self.props.spec.short_program_name + '-internal preloading wrapper',
['SUBPROCESS_WRAPPER_PREPARATION'])}
),
(
{self.renderStepSeparator('subprocess')}
)
];
}
}
return (
In {this.props.spec.short_program_name} core
PID {this.props.spec.diagnostics.core_process.pid}
In subprocess
PID {this.props.spec.diagnostics.subprocess.pid || 'unknown'}
{this.renderCell('server-core', 'Preparation work',
['SPAWNING_KIT_PREPARATION'])}
{this.renderStepSeparator('server-core')}
{this.renderCell('server-core', 'Spawn subprocess (fork())',
['SPAWNING_KIT_FORK_SUBPROCESS'])}
{this.renderProcessBoundaryArrow()}
{this.renderCell('subprocess', 'Basic initialization before exec()',
['SUBPROCESS_BEFORE_FIRST_EXEC'])}
{this.renderStepSeparator('server-core')}
{this.renderStepSeparator('subprocess')}
{this.renderCell('server-core', 'Handshake with subprocess',
['SPAWNING_KIT_HANDSHAKE_PERFORM'])}
{this.renderCell('subprocess', 'Setup environment (1)',
['SUBPROCESS_SPAWN_ENV_SETUPPER_BEFORE_SHELL'])}
{this.renderStepSeparator('server-core')}
{this.renderStepSeparator('subprocess')}
{this.renderCell('server-core', 'Finish',
['SPAWNING_KIT_FINISH'])}
{this.renderCell('subprocess', 'Load OS shell',
['SUBPROCESS_OS_SHELL'])}
{this.renderStepSeparator('subprocess')}
{this.renderCell('subprocess', 'Setup environment (2)',
['SUBPROCESS_SPAWN_ENV_SETUPPER_AFTER_SHELL'])}
{this.renderStepSeparator('subprocess')}
{renderWrapperRows()}
{this.renderCell('subprocess', 'Load application',
['SUBPROCESS_APP_LOAD_OR_EXEC'])}
{this.renderStepSeparator('subprocess')}
{this.renderCell('subprocess', 'App start listening for preloader commands',
['SUBPROCESS_LISTEN'])}
{this.renderStepSeparator('subprocess')}
{this.renderCell('subprocess', 'Finish',
['SUBPROCESS_FINISH'])}
);
}
renderSpawnThroughPreloaderJourney() {
return (
In {this.props.spec.short_program_name}
PID {this.props.spec.diagnostics.core_process.pid}
In preloader
PID {this.props.spec.diagnostics.preloader_process.pid || 'unknown'}
In subprocess
PID {this.props.spec.diagnostics.subprocess.pid || 'unknown'}
{this.renderCell('server-core', 'Preparation work',
['SPAWNING_KIT_PREPARATION'])}
{this.renderStepSeparator('server-core')}
{this.renderCell('server-core', 'Tell preloader to spawn a subprocess',
['SPAWNING_KIT_CONNECT_TO_PRELOADER', 'SPAWNING_KIT_SEND_COMMAND_TO_PRELOADER'])}
{this.renderProcessBoundaryArrow('small')}
{this.renderCell('preloader', 'Preparation work',
['PRELOADER_PREPARATION'])}
{this.renderStepSeparator('server-core')}
{this.renderStepSeparator('preloader')}
{this.renderCell('server-core', 'Receive and process preloader response',
['SPAWNING_KIT_READ_RESPONSE_FROM_PRELOADER',
'SPAWNING_KIT_PARSE_RESPONSE_FROM_PRELOADER',
'SPAWNING_KIT_PROCESS_RESPONSE_FROM_PRELOADER'])}
{this.renderCell('preloader', 'Spawn subprocess (fork())',
['PRELOADER_FORK_SUBPROCESS'])}
{this.renderProcessBoundaryArrow('small')}
{this.renderCell('subprocess', 'Preparation',
['SUBPROCESS_PREPARE_AFTER_FORKING_FROM_PRELOADER'])}
{this.renderStepSeparator('server-core')}
{this.renderStepSeparator('preloader')}
{this.renderStepSeparator('subprocess')}
{this.renderCell('server-core', 'Handshake with subprocess',
['SPAWNING_KIT_HANDSHAKE_PERFORM'])}
{this.renderCell('preloader',
'Send response to ' + this.props.spec.short_program_name + ' core',
['PRELOADER_SEND_RESPONSE'])}
{this.renderCell('subprocess', 'App start listening',
['SUBPROCESS_LISTEN'])}
{this.renderStepSeparator('server-core')}
{this.renderStepSeparator('preloader')}
{this.renderStepSeparator('subprocess')}
{this.renderCell('server-core', 'Finish',
['SPAWNING_KIT_FINISH'])}
{this.renderCell('preloader', 'Finish',
['PRELOADER_FINISH'])}
{this.renderCell('subprocess', 'Finish',
['SUBPROCESS_FINISH'])}
);
}
renderCell(processName, title, steps) {
const journey = this.props.spec.journey;
function anyStepFailed() {
var i;
for (i = 0; i < steps.length; i++) {
var step = steps[i];
if (journey.steps[step].state === 'STEP_ERRORED') {
return true;
}
}
return false;
}
function allStepsDone() {
var i;
for (i = 0; i < steps.length; i++) {
var step = steps[i];
if (journey.steps[step].state !== 'STEP_PERFORMED') {
return false;
}
}
return true;
}
function allStepsNotStarted() {
var i;
for (i = 0; i < steps.length; i++) {
var step = steps[i];
if (journey.steps[step].state !== 'STEP_NOT_STARTED') {
return false;
}
}
return true;
}
function renderDuration() {
var i, totalDurationSec;
for (i = 0; i < steps.length; i++) {
var step = steps[i];
if (journey.steps[step].duration !== undefined) {
if (totalDurationSec === undefined) {
totalDurationSec = 0;
}
totalDurationSec += journey.steps[step].duration;
} else if (journey.steps[step].begin_time !== undefined) {
if (totalDurationSec === undefined) {
totalDurationSec = 0;
}
// relative_timestamp is negative
totalDurationSec -= journey.steps[step].begin_time.relative_timestamp;
}
}
if (totalDurationSec !== undefined) {
if (allStepsNotStarted()) {
return (— skipped );
} else {
return (— {totalDurationSec.toFixed(1)}s );
}
}
}
var statusClass, statusLabel;
if (anyStepFailed()) {
statusClass = 'error';
statusLabel = (
);
} else if (allStepsDone()) {
statusClass = 'done';
statusLabel = (
);
} else if (allStepsNotStarted()) {
statusClass = 'not-started';
statusLabel = (
);
} else {
statusClass = 'in-progress';
statusLabel = (
);
}
var className = processName + ' ' + statusClass;
return (
{statusLabel}
{title} {renderDuration()}
);
}
renderStepSeparator(componentName) {
return (
|
);
}
renderProcessBoundaryArrow(size) {
var width;
if (size === 'small') {
width = 90;
} else {
width = 130;
}
return (
)
}
}
export default JourneyView;