Skip to content

Commit

Permalink
refactor: use Date.now() instead of process.hrtime()
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed May 5, 2020
1 parent e0fa501 commit 9fccd87
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 38 deletions.
8 changes: 3 additions & 5 deletions lib/datasource/rubygems/get-rubygems-org.ts
@@ -1,4 +1,3 @@
import { hrtime } from 'process';
import { logger } from '../../logger';
import { Http } from '../../util/http';
import { DatasourceError, ReleaseResult } from '../common';
Expand All @@ -24,11 +23,10 @@ async function updateRubyGemsVersions(): Promise<void> {
let newLines: string;
try {
logger.debug('Rubygems: Fetching rubygems.org versions');
const startTime = hrtime();
const startTime = Date.now();
newLines = (await http.get(url, options)).body;
const duration = hrtime(startTime);
const seconds = Math.round(duration[0] + duration[1] / 1e9);
logger.debug({ seconds }, 'Rubygems: Fetched rubygems.org versions');
const durationMs = Math.round(Date.now() - startTime);
logger.debug({ durationMs }, 'Rubygems: Fetched rubygems.org versions');
} catch (err) /* istanbul ignore next */ {
if (err.statusCode !== 416) {
contentLength = 0;
Expand Down
18 changes: 6 additions & 12 deletions lib/platform/git/storage.ts
@@ -1,6 +1,5 @@
import { join } from 'path';
import URL from 'url';
import convertHrtime from 'convert-hrtime';
import fs from 'fs-extra';
import Git from 'simple-git/promise';
import {
Expand Down Expand Up @@ -145,17 +144,14 @@ export class Storage {
try {
this._git = Git(cwd).silent(true);
await this._git.raw(['remote', 'set-url', 'origin', config.url]);
const fetchStart = process.hrtime();
const fetchStart = Date.now();
await this._git.fetch(['--depth=10']);
await setBaseBranchToDefault(this._git);
await this._resetToBranch(config.baseBranch);
await this._cleanLocalBranches();
await this._git.raw(['remote', 'prune', 'origin']);
const fetchSeconds =
Math.round(
1 + 10 * convertHrtime(process.hrtime(fetchStart)).seconds
) / 10;
logger.debug({ fetchSeconds }, 'git fetch completed');
const durationMs = Math.round(Date.now() - fetchStart);
logger.debug({ durationMs }, 'git fetch completed');
clone = false;
} catch (err) /* istanbul ignore next */ {
logger.error({ err }, 'git fetch error');
Expand All @@ -164,7 +160,7 @@ export class Storage {
if (clone) {
await fs.emptyDir(cwd);
this._git = Git(cwd).silent(true);
const cloneStart = process.hrtime();
const cloneStart = Date.now();
try {
// clone only the default branch
let opts = ['--depth=2'];
Expand All @@ -178,10 +174,8 @@ export class Storage {
logger.debug({ err }, 'git clone error');
throw new Error(PLATFORM_FAILURE);
}
const seconds =
Math.round(1 + 10 * convertHrtime(process.hrtime(cloneStart)).seconds) /
10;
logger.debug({ seconds }, 'git clone completed');
const durationMs = Math.round(Date.now() - cloneStart);
logger.debug({ durationMs }, 'git clone completed');
}
const submodules = await this.getSubmodules();
for (const submodule of submodules) {
Expand Down
8 changes: 3 additions & 5 deletions lib/util/exec/index.ts
@@ -1,6 +1,5 @@
import { ExecOptions as ChildProcessExecOptions } from 'child_process';
import { dirname, join } from 'path';
import { hrtime } from 'process';
import { RenovateConfig } from '../../config/common';
import { logger } from '../../logger';
import {
Expand Down Expand Up @@ -140,7 +139,7 @@ export async function exec(

let res: ExecResult | null = null;
for (const rawExecCommand of commands) {
const startTime = hrtime();
const startTime = Date.now();
let timer;
const { timeout } = rawExecOptions;
if (useDocker) {
Expand Down Expand Up @@ -168,13 +167,12 @@ export async function exec(
throw err;
}
clearTimeout(timer);
const duration = hrtime(startTime);
const seconds = Math.round(duration[0] + duration[1] / 1e9);
const durationMs = Math.round(Date.now() - startTime);
if (res) {
logger.debug(
{
cmd: rawExecCommand,
seconds,
durationMs,
stdout: res.stdout,
stderr: res.stderr,
},
Expand Down
8 changes: 3 additions & 5 deletions lib/workers/repository/process/extract-update.ts
@@ -1,4 +1,3 @@
import { hrtime } from 'process';
import { RenovateConfig } from '../../../config';
import { logger } from '../../../logger';
import { PackageFile } from '../../../manager/common';
Expand Down Expand Up @@ -46,12 +45,11 @@ function extractStats(packageFiles: Record<string, PackageFile[]>): any {

export async function extract(config: RenovateConfig): Promise<ExtractResult> {
logger.debug('extractAndUpdate()');
const startTime = hrtime();
const startTime = Date.now();
const packageFiles = await extractAllDependencies(config);
const duration = hrtime(startTime);
const seconds = Math.round(duration[0] + duration[1] / 1e9);
const durationMs = Math.round(Date.now() - startTime);
const stats = extractStats(packageFiles);
logger.info({ stats, seconds }, `Dependency extraction complete`);
logger.info({ stats, durationMs }, `Dependency extraction complete`);
logger.trace({ config: packageFiles }, 'packageFiles');
await fetchUpdates(config, packageFiles);
logger.debug({ config: packageFiles }, 'packageFiles with updates');
Expand Down
8 changes: 3 additions & 5 deletions lib/workers/repository/process/fetch.ts
@@ -1,4 +1,3 @@
import { hrtime } from 'process';
import pAll from 'p-all';
import {
ManagerConfig,
Expand Down Expand Up @@ -115,12 +114,11 @@ export async function fetchUpdates(
packageFiles: Record<string, PackageFile[]>
): Promise<void> {
const managers = Object.keys(packageFiles);
const startTime = hrtime();
const startTime = Date.now();
const allManagerJobs = managers.map((manager) =>
fetchManagerUpdates(config, packageFiles, manager)
);
await Promise.all(allManagerJobs);
const duration = hrtime(startTime);
const seconds = Math.round(duration[0] + duration[1] / 1e9);
logger.info({ seconds }, 'Package releases lookups complete');
const durationMs = Math.round(Date.now() - startTime);
logger.info({ durationMs }, 'Package releases lookups complete');
}
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -121,7 +121,6 @@
"clean-git-ref": "2.0.1",
"commander": "5.1.0",
"conventional-commits-detector": "1.0.2",
"convert-hrtime": "3.0.0",
"deepmerge": "4.2.2",
"delay": "4.3.0",
"detect-indent": "6.0.0",
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Expand Up @@ -2903,11 +2903,6 @@ conventional-commits-parser@^3.0.0, conventional-commits-parser@^3.0.7:
through2 "^3.0.0"
trim-off-newlines "^1.0.0"

convert-hrtime@3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/convert-hrtime/-/convert-hrtime-3.0.0.tgz#62c7593f5809ca10be8da858a6d2f702bcda00aa"
integrity sha512-7V+KqSvMiHp8yWDuwfww06XleMWVVB9b9tURBx+G7UTADuo5hYPuowKloz4OzOqbPezxgo+fdQ1522WzPG4OeA==

convert-source-map@^1.1.0, convert-source-map@^1.4.0, convert-source-map@^1.6.0, convert-source-map@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.7.0.tgz#17a2cb882d7f77d3490585e2ce6c524424a3a442"
Expand Down

0 comments on commit 9fccd87

Please sign in to comment.