Skip to content
Permalink
Browse files

[DDW-656] Log Daedalus state snapshot

  • Loading branch information...
DeeJayElly committed Jul 12, 2019
1 parent 2506429 commit 1dc7741bf058f9a0bd10177092b45e91d9c3481c
@@ -78,11 +78,11 @@ export type GetStateDirectoryPathRendererRequest = string | any;
export type GetStateDirectoryPathMainResponse = any;

/**
* Channel for getting log state snapshot
* Channel for setting log state snapshot
*/
export const GET_LOG_STATE_SNAPSHOT_CHANNEL = 'GetLogStateSnapshotChannel';
export type GetLogStateSnapshotRendererRequest = any;
export type GetLogStateSnapshotMainResponse = any;
export const SET_LOG_STATE_SNAPSHOT_CHANNEL = 'SetLogStateSnapshotChannel';
export type SetLogStateSnapshotRendererRequest = any;
export type SetLogStateSnapshotMainResponse = any;

/**
* Channel for loading a base64 encoded asset from within the `source/renderer` folder
@@ -4,7 +4,7 @@ import path from 'path';
import { app, BrowserWindow, shell } from 'electron';
import { client } from 'electron-connect';
import { Logger } from './utils/logging';
import { setupLogging, logSystemInfo } from './utils/setupLogging';
import {setupLogging, logSystemInfo, logStateSnapshot} from './utils/setupLogging';
import { getNumberOfEpochsConsolidated } from './utils/getNumberOfEpochsConsolidated';
import { handleDiskSpace } from './utils/handleDiskSpace';
import { createMainWindow } from './windows/main';
@@ -31,6 +31,7 @@ import { getStateDirectoryPathChannel } from './ipc/getStateDirectoryPathChannel
import { CardanoNodeStates } from '../common/types/cardano-node.types';
import type { CheckDiskSpaceResponse } from '../common/types/no-disk-space.types';
import { logUsedVersion } from './utils/logUsedVersion';
import { setLogStateSnapshotChannel } from './ipc/set-log-state-snapshot';

/* eslint-disable consistent-return */

@@ -156,6 +157,10 @@ const onAppReady = async () => {

getNumberOfEpochsConsolidated();

setLogStateSnapshotChannel.onReceive(data =>
logStateSnapshot(data)
);

getStateDirectoryPathChannel.onRequest(() =>
Promise.resolve(stateDirectoryPath)
);
@@ -0,0 +1,14 @@
// @flow
import { MainIpcChannel } from './lib/MainIpcChannel';
import { SET_LOG_STATE_SNAPSHOT_CHANNEL } from '../../common/ipc/api';
import type {
SetLogStateSnapshotRendererRequest,
SetLogStateSnapshotMainResponse,
} from '../../common/ipc/api';

// IpcChannel<Incoming, Outgoing>

export const setLogStateSnapshotChannel: MainIpcChannel<
SetLogStateSnapshotRendererRequest,
SetLogStateSnapshotMainResponse
> = new MainIpcChannel(SET_LOG_STATE_SNAPSHOT_CHANNEL);

This file was deleted.

@@ -0,0 +1,13 @@
// @flow
import { RendererIpcChannel } from './lib/RendererIpcChannel';
import { SET_LOG_STATE_SNAPSHOT_CHANNEL } from '../../../common/ipc/api';
import type {
SetLogStateSnapshotRendererRequest,
SetLogStateSnapshotMainResponse,
} from '../../../common/ipc/api';

export const setLogStateSnapshotChannel: // IpcChannel<Incoming, Outgoing>
RendererIpcChannel<
SetLogStateSnapshotMainResponse,
SetLogStateSnapshotRendererRequest
> = new RendererIpcChannel(SET_LOG_STATE_SNAPSHOT_CHANNEL);
@@ -23,7 +23,7 @@ import {
import { CardanoNodeStates } from '../../../common/types/cardano-node.types';
import { getDiskSpaceStatusChannel } from '../ipc/getDiskSpaceChannel.js';
import { getStateDirectoryPathChannel } from '../ipc/getStateDirectoryPathChannel';
import { getLogStateSnapshotChannel } from '../ipc/getLogStateSnapshotChannel';
import { setLogStateSnapshotChannel } from '../ipc/setLogStateSnapshotChannel';
import type { GetNetworkStatusResponse } from '../api/nodes/types';
import type {
CardanoNodeState,
@@ -586,6 +586,17 @@ export default class NetworkStatusStore extends Store {
openLocalDirectoryChannel.send(path);
}

convertBytesToSize = (bytes: number): string => {
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes === 0) return 'n/a';
const i = parseInt(
Math.floor(Math.log(Math.abs(bytes)) / Math.log(1024)),
10
);
if (i === 0) return `${bytes} ${sizes[i]})`;
return `${(bytes / 1024 ** i).toFixed(1)} ${sizes[i]}`;
};

@action _onCheckDiskSpace = ({
isNotEnoughDiskSpace,
diskSpaceRequired,
@@ -616,7 +627,47 @@ export default class NetworkStatusStore extends Store {
};

@action _logStateSnapshot = () => {
getLogStateSnapshotChannel.send();
const stateSnapshotData = {
availableDiskSpace: this.diskSpaceAvailable,
cardanoAPIPort: this.tlsConfig ? this.tlsConfig.port : 0,
cardanoNetwork: this.environment.network,
cardanoNodeState: this.cardanoNodeState,
cardanoProcessID: this.cardanoNodeID,
cardanoVersion: this.environment.buildNumber,
cpu: this.environment.cpu[0].model,
current: this.environment.current,
currentLocale: this.stores.profile.currentLocale,
daedalusVersion: this.environment.version,
daedalusMainProcessID: this.environment.mainProcessID,
daedalusProcessID: this.environment.rendererProcessID,
daedalusStateDirectoryPath: this.stateDirectoryPath,
isConnected: this.isConnected,
isDev: this.isConnected,
isForceCheckingNodeTime: this.forceCheckTimeDifferenceRequest.isExecuting,
isInSafeMode: this.environment.isInSafeMode,
isMainnet: this.environment.isMainnet,
isNodeInSync: this.isNodeInSync,
isNodeResponding: this.isNodeResponding,
isNodeSubscribed: this.isNodeSubscribed,
isNodeSyncing: this.isNodeSyncing,
isNodeTimeCorrect: this.isNodeTimeCorrect,
isStaging: this.environment.isStaging,
isSynced: this.isSynced,
isSystemTimeCorrect: this.isSystemTimeCorrect,
isSystemTimeIgnored: this.isSystemTimeIgnored,
isTestnet: this.environment.isTestnet,
latestLocalBlockTimestamp: this.latestLocalBlockTimestamp,
latestNetworkBlockTimestamp: this.latestNetworkBlockTimestamp,
localBlockHeight: this.localBlockHeight,
localTimeDifference: this.localTimeDifference,
networkBlockHeight: this.networkBlockHeight,
platform: this.environment.os,
platformVersion: this.environment.platformVersion,
ram: this.convertBytesToSize(this.environment.ram),
startTime: new Date().toISOString(),
syncPercentage: this.syncPercentage,
};
setLogStateSnapshotChannel.send(stateSnapshotData);
};

// DEFINE COMPUTED VALUES

0 comments on commit 1dc7741

Please sign in to comment.
You can’t perform that action at this time.