tools/PTE/pte-snapshot.js
/**
 * get snapshot generation time
 *
 * @param {int} freq The snapshot generation time poll frequency
 * @param {int} blk The block number of the snapshot generation time to be polled
 * @param {boolean} isKube The isKube environment
 * @returns {int} The integer: 0: failed, 1: succeeded, 2: in progress
 */
get snapshot generation time
@param {int} freq The snapshot generation time poll frequency
@param {int} blk The block number of the snapshot generation time to be polled
@param {boolean} isKube The isKube environment
@returns {int} The integer: 0: failed, 1: succeeded, 2: in progress
get snapshot generation time @param { int } freq The snapshot generation time poll frequency @param { int } blk The block number of the snapshot generation time to be polled @param { boolean } isKube The isKube environment @returns { int } The integer : 0 : failed 1 : succeeded 2 : in progress
async function snapshotGenTime(freq, blk, isKube) {
    let peer = snapshot.peerName;
    let cmd = await genTimeCmd(peer, blk, isKube);
    logger.info('[snapshotGenTime] Poll the snapshot generation time for block (%d) in peer (%s)', blk, peer);
    let rtn = await pollTimestamp(cmd.subcmd1);
    if (!rtn.cmdStatus) {
        snapshotFailed ++;
        if ( snapshotFailed >= 3 ) {
            logger.warn('[snapshotGenTime] Poll snapshot generation time for block (%d) in peer (%s) failed (%d)', blk, peer, snapshotFailed);
            snapshotFailed = 0;
            return 0;
        } else {
            logger.info('[snapshotGenTime] Poll snapshot generating time for block (%d) in peer (%s) failed (%d), try again later', blk, peer, snapshotFailed);
            return 2;
        }
    }
    let t1 = rtn.t;
    rtn = await pollTimestamp(cmd.subcmd2);
    if (!rtn.cmdStatus) {
        logger.info('[snapshotGenTime] The snapshot for block (%d) in peer (%s) is being generated ... ', blk, peer);
        return 2;
    }
    let t2 = rtn.t;
    let snapshotRpt = 'snapshotReport.json';
    let buff = {};
    buff["peer"] = peer;
    buff["height"] = blk;
    buff["start"] = new Date(t1).toISOString();
    buff["end"] = new Date(t2).toISOString();
    buff["total(sec)"] = (t2-t1)/1000;
    fs.appendFileSync(snapshotRpt, JSON.stringify(buff));
    fs.appendFileSync(snapshotRpt, '\n');
    snapshotFailed = 0;
    logger.info('[snapshotGenTime] snapshot generation:', JSON.stringify(buff));
    return 1;
}
async function snapshotGenTime ( freq , blk , isKube ) { let peer = snapshot . peerName ; let cmd = await genTimeCmd ( peer , blk , isKube ) ; logger . info ( '[snapshotGenTime] Poll the snapshot generation time for block (%d) in peer (%s)' , blk , peer ) ; let rtn = await pollTimestamp ( cmd . subcmd1 ) ; if ( ! rtn . cmdStatus ) { snapshotFailed ++ ; if ( snapshotFailed >= 3 ) { logger . warn ( '[snapshotGenTime] Poll snapshot generation time for block (%d) in peer (%s) failed (%d)' , blk , peer , snapshotFailed ) ; snapshotFailed = 0 ; return 0 ; } else { logger . info ( '[snapshotGenTime] Poll snapshot generating time for block (%d) in peer (%s) failed (%d), try again later' , blk , peer , snapshotFailed ) ; return 2 ; } } let t1 = rtn . t ; rtn = await pollTimestamp ( cmd . subcmd2 ) ; if ( ! rtn . cmdStatus ) { logger . info ( '[snapshotGenTime] The snapshot for block (%d) in peer (%s) is being generated ... ' , blk , peer ) ; return 2 ; } let t2 = rtn . t ; let snapshotRpt = 'snapshotReport.json' ; let buff = { } ; buff [ "peer" ] = peer ; buff [ "height" ] = blk ; buff [ "start" ] = new Date ( t1 ) . toISOString ( ) ; buff [ "end" ] = new Date ( t2 ) . toISOString ( ) ; buff [ "total(sec)" ] = ( t2 - t1 ) / 1000 ; fs . appendFileSync ( snapshotRpt , JSON . stringify ( buff ) ) ; fs . appendFileSync ( snapshotRpt , '\n' ) ; snapshotFailed = 0 ; logger . info ( '[snapshotGenTime] snapshot generation:' , JSON . stringify ( buff ) ) ; return 1 ; }
get snapshot generation time
 @param {int} freq The snapshot generation time poll frequency
 @param {int} blk The block number of the snapshot generation time to be polled
 @param {boolean} isKube The isKube environment
 @returns {int} The integer: 0: failed, 1: succeeded, 2: in progress
get snapshot generation time @param { int } freq The snapshot generation time poll frequency @param { int } blk The block number of the snapshot generation time to be polled @param { boolean } isKube The isKube environment @returns { int } The integer : 0 : failed 1 : succeeded 2 : in progress
// generate report