Calculate IPC time.

This commit is contained in:
yaoweiprc
2024-10-31 19:21:54 +08:00
parent 0de2f6e9fa
commit aaa08e168e
5 changed files with 57 additions and 3 deletions

View File

@@ -34,7 +34,7 @@ export interface SpecificQuery {
}
export type ChangeType = 'insert' | 'update' | 'remove';
export const database = {
const database = {
// Get all documents of a certain type
all: async function<T extends BaseModel>(type: string) {
if (db._empty) {
@@ -669,6 +669,49 @@ export const database = {
},
};
const isMainProcess = process.type === 'browser';
let countIsExecuting = 0;
let startTime: undefined | number = undefined;
let totalExecutingTime = 0;
for (let asyncMethodName of Object.keys(database).filter(key => {
return typeof database[key] === 'function'
&& key !== 'onChange'
&& key !== 'offChange';
})) {
const oriFunction = database[asyncMethodName];
database[asyncMethodName] = function () {
if (countIsExecuting === 0) {
if (startTime !== undefined) {
console.warn('startTime is not undefined when start');
}
startTime = Date.now();
}
countIsExecuting++;
return oriFunction.apply(this, arguments).finally(() => {
countIsExecuting--;
if (countIsExecuting === 0) {
if (startTime === undefined) {
console.warn('startTime is undefined when end');
}
const time = Date.now() - startTime;
startTime = undefined;
totalExecutingTime += time;
}
});
};
}
setInterval(() => {
console.log(`----------------${isMainProcess ? 'Main' : 'Renderer'} process has been executing for ${totalExecutingTime} ms----------------------`);
}, 1000);
export { database };
interface DB {
[index: string]: NeDB;
}

View File

@@ -5,6 +5,7 @@ import { parse } from 'yaml';
import { httpClient } from './http-client';
import { convertToPosixSep } from './path-sep';
import { gitCallbacks } from './utils';
import { time, timeEnd } from 'console';
export interface GitAuthor {
name: string;
@@ -508,7 +509,9 @@ export class GitVCS {
staged: { path: string; status: [git.HeadStatus, git.WorkdirStatus, git.StageStatus]; name: string }[];
unstaged: { path: string; status: [git.HeadStatus, git.WorkdirStatus, git.StageStatus]; name: string }[];
}> {
console.time('statusWithContent');
const status = await this.statusWithContent();
console.timeEnd('statusWithContent');
const unstagedChanges = status.filter(({ workdir, stage }) => stage.status !== workdir.status);
const stagedChanges = status.filter(({ head, stage }) => stage.status !== head.status);

View File

@@ -36,6 +36,7 @@ export class NeDBClient {
filePath: string,
options?: BufferEncoding | { encoding?: BufferEncoding },
) {
console.count('readFile');
filePath = path.normalize(filePath);
options = options || {};
@@ -80,6 +81,7 @@ export class NeDBClient {
}
async writeFile(filePath: string, data: Buffer | string) {
console.count('writeFile');
filePath = path.normalize(filePath);
const { root, id, type } = parseGitPath(filePath);
@@ -110,6 +112,7 @@ export class NeDBClient {
}
async unlink(filePath: string) {
console.count('unlink');
filePath = path.normalize(filePath);
const { id, type } = parseGitPath(filePath);
@@ -130,6 +133,7 @@ export class NeDBClient {
// and returns a list of all the files/folders which should be in the directory
// according to the what entities are children of the workspace
async readdir(filePath: string) {
console.count('readdir');
filePath = path.normalize(filePath);
const { root, type, id } = parseGitPath(filePath);
let docs: BaseModel[] = [];
@@ -194,6 +198,7 @@ export class NeDBClient {
}
async stat(filePath: string) {
console.count('stat');
filePath = path.normalize(filePath);
let fileBuff: Buffer | string | null = null;
let dir: string[] | null = null;

View File

@@ -268,7 +268,7 @@ export const GitSyncDropdown: FC<Props> = ({ gitRepository, isInsomniaSyncEnable
action: () => setIsGitRepoSettingsModalOpen(true),
}]);
useInterval(() => {
/* useInterval(() => {
gitFetchFetcher.submit(
{},
{
@@ -276,7 +276,7 @@ export const GitSyncDropdown: FC<Props> = ({ gitRepository, isInsomniaSyncEnable
method: 'post',
}
);
}, 1000 * 60 * 5);
}, 1000 * 60 * 5); */
const status = gitStatusFetcher.data?.status;

View File

@@ -32,6 +32,7 @@ import {
SegmentEvent,
vcsSegmentEventProperties,
} from '../analytics';
import { time, timeEnd } from 'console';
// Loaders
export type GitRepoLoaderData =
@@ -294,6 +295,7 @@ export interface GitChangesLoaderData {
export const gitChangesLoader: LoaderFunction = async ({
params,
}): Promise<GitChangesLoaderData> => {
console.time('gitChangesLoader');
const { workspaceId } = params;
invariant(typeof workspaceId === 'string', 'Workspace Id is required');
@@ -326,6 +328,7 @@ export const gitChangesLoader: LoaderFunction = async ({
models.workspaceMeta.updateByParentId(workspaceId, {
hasUncommittedChanges,
});
console.timeEnd('gitChangesLoader');
return {
branch,
changes,