Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Adds --json and other params #6

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Adds --json and other params #6

wants to merge 6 commits into from

Conversation

orta
Copy link

@orta orta commented Mar 27, 2021

  • Allows for arbitrary --opt flags
  • Adds --json flag where a JSON file is written
  • Adds flags for params:
    console.error(`          --thresholdDuration [default: 50000] How many ms should a span with children use for highlighting`);
    console.error(`          --minDuration       [default: 10000] How long should a single span take before being classed as interesting`);
    console.error(`          --minPercentage     [default: 0.6]   The threshold for being interesting based on % of call stack`);

The primary output asset is now a TreeNode, which is more editor focused, and from that we can derive a treeable tree for the same text output

@orta
Copy link
Author

orta commented Mar 27, 2021

I threw in some vendored files to make it easier to test too, they're npmignored

@orta
Copy link
Author

orta commented Mar 27, 2021

@orta
Copy link
Author

orta commented Mar 29, 2021

TODO: calling --json on the module shipped in ./bin should pass a different --json to each child process and then convert all those into a single json file

const args: string[] = []
const opts: Opts = {}

let foundOpt: string | undefined = undefined
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to just pull in yargs. It's already there indirectly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to come back, doh - OK, I'm good for this

}
});

if (args.length !== 3 && args.length != 4) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect you'll need to update these length checks.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yargs'll fix that

const thresholdDuration = 5E5; // microseconds
const minDuration = 1E5; // microseconds
const minPercentage = 0.6;
const thresholdDuration = Number(opts.thresholdDuration) || 5E5; // microseconds
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignorant question: is this different from +opts.thresholdDuration? I've been using that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, basically the exact same, I just find Number to feel more explicit

await makeHotStacks(root);
}

type TreeNode = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interface?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, maybe that doesn't work with recursive types?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interface will be fine, they can recurse too

const path = require("path");
console.error(`Usage: ${path.basename(process.argv[0])} ${path.basename(process.argv[1])} trace_path [type_path]`);
console.error(`Options: --json [path] Prints a JSON object of the results to stdout`);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it print to stdout or path?

if (Object.entries(tree).length) {

if (tree && Object.entries(tree).length) {
if (opts.json) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intuitively, I would have expected json output to replace the normal output, not supplement it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're not wrong to feel that, but I think there's still value in keeping the logs (for example, we can show the terminal output in a build log)

// Sort slow to fast
let childTree = {};

async function makePrintableTree(curr: EventSpan, currentFile: string | undefined, positionMap: PositionMap): Promise<TreeNode | undefined> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Printable" was my word for "treeify-compatible", so "makeTree" is probably fine now.

treeNode.message = `Compare types ${args.sourceId} and ${args.targetId}`;
treeNode.terseMessage = `Compare types ${args.sourceId} and ${args.targetId}`;
// TODO: Add start and end links
return
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return treeNode?

}
}
return undefined;
}
}

function updateTypeTreePositions(typeTree: any): any {
function updateTypeTreePositions(node: TreeNode, typeTree: any): any {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is a TreeNode required?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing in a root node so it can recurse, maybe I should rename it to say it will recurse

// If it's going to include a JSON path, make it per-trace
let jsonPath: string | undefined = undefined
if (opts.includes("--json")) {
const hash = crypto.createHash('sha256').update(project.tracePath).digest("hex");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we hashing files? I don't think there's a way to update one trace out of a family - are we guarding against having to redo work on crash?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically you ask the project "give me a JSON file at this path" - but to generate that each sub-project in the project will generate its own JSON file and these need unique names, so we take the path to the project and turn it into a SHA so they don't collide

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants