Skip to content

Commit f1b04ae

Browse files
Mihai Budiuryzhyk
authored andcommitted
[Self-profiler revamp 1/2]: Profile browser.
This is the first part of the self-profiler revamp. The self-profiler remains a useful tool for troubleshooting DDlog performance issues. It runs with low overhead, allows enabling/disabling CPU and change profiling at runtime to only instrument parts of the program, and because it is integrated into the DDlog runtime it can precisely match each DD operator to the corresponding DDlog operator. DDshow does not currently have these features. However, the self-profiler tends to produce profiles that are hard to parse even for people familiar with compiler internals. We therefore set out to revamp the self-profiler to improve its ergonomics. The new self-profiler will have the following features: - It will produce profiles in the form of interactive HTML tables. Each row in the table represents a DD operator and contains operator description, e.g., "Arrange relation 'Rel1' by 'x,y,z'" along with links to one or more source code location that this operator corresponds to (e.g., all locations where this specific arrangement of 'Rel1' is used). - The new `dump_profile` API will dump the profile into an HTML file on the disk instead of returning it as a string. All profiles generated by the same process are generated in the same folder, even if the process creates multiple instances of DDlog. This folder will also contain a complete snapshot of all DDlog code in the program, so that the profiler can show program sources even when the program does not run on the same system where it was compiled. - Internally, the self-profiler will represent profiles using a well-defined JSON format. New APIs will be added to extract each of the four profiles currently supported by DDlog (arrangement size profile, peak arrangement size profile, change profile, and CPU profile) in the JSON format, for automatic processing by third-party tools. This commit adds a TypeScript implementation of the profile browser. The browser renders JSON profiles as HTML tables. The user can expand a table record, at which point the browser will load associated code from the source code directory. Since browsers these days refuse to open arbitrary files even in the same directory, the browser expects the DDlog source code to be stored as a JS program consisting of a single statement that inserts a string (the DDlog source code) in a global map. Signed-off-by: Mihai Budiu <[email protected]>
1 parent 15259e1 commit f1b04ae

File tree

8 files changed

+1090
-0
lines changed

8 files changed

+1090
-0
lines changed

tools/profiler_ui/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
ui.js
3+
*.map

tools/profiler_ui/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
all: ui.html ui.css ui.ts
2+
tsc
3+
4+
dependencies:
5+
npm install

tools/profiler_ui/package-lock.json

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/profiler_ui/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "profiler_ui",
3+
"version": "1.0.0",
4+
"description": "DDlog profiler UI",
5+
"main": "index.html",
6+
"dependencies": {
7+
"source-map": "^0.7.3",
8+
"source-map-support": "^0.5.20",
9+
"typescript": "^4.4.4"
10+
},
11+
"devDependencies": {},
12+
"scripts": {
13+
"test": "echo \"Error: no test specified\" && exit 1"
14+
},
15+
"author": "[email protected]",
16+
"license": "MIT"
17+
}

tools/profiler_ui/tsconfig.json

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"compilerOptions": {
3+
/* Visit https://aka.ms/tsconfig.json to read more about this file */
4+
5+
/* Basic Options */
6+
// "incremental": true, /* Enable incremental compilation */
7+
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
8+
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
9+
// "lib": [], /* Specify library files to be included in the compilation. */
10+
// "allowJs": true, /* Allow javascript files to be compiled. */
11+
// "checkJs": true, /* Report errors in .js files. */
12+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
13+
// "declaration": true, /* Generates corresponding '.d.ts' file. */
14+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
15+
"sourceMap": true, /* Generates corresponding '.map' file. */
16+
// "outFile": "./", /* Concatenate and emit output to single file. */
17+
// "outDir": "./", /* Redirect output structure to the directory. */
18+
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
19+
// "composite": true, /* Enable project compilation */
20+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
21+
// "removeComments": true, /* Do not emit comments to output. */
22+
// "noEmit": true, /* Do not emit outputs. */
23+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
24+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
25+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
26+
27+
/* Strict Type-Checking Options */
28+
"strict": true, /* Enable all strict type-checking options. */
29+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
30+
// "strictNullChecks": true, /* Enable strict null checks. */
31+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
32+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
33+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
34+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
35+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
36+
37+
/* Additional Checks */
38+
// "noUnusedLocals": true, /* Report errors on unused locals. */
39+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
40+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
41+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
42+
43+
/* Module Resolution Options */
44+
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
45+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
46+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
47+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
48+
// "typeRoots": [], /* List of folders to include type definitions from. */
49+
"types": [], /* Type declaration files to be included in compilation. */
50+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
51+
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
52+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
53+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
54+
// "resolveJsonModule": true,
55+
56+
/* Source Map Options */
57+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
58+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
59+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
60+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
61+
62+
/* Experimental Options */
63+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
64+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
65+
66+
/* Advanced Options */
67+
"skipLibCheck": true, /* Skip type checking of declaration files. */
68+
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
69+
"lib": [
70+
"dom",
71+
"es6",
72+
"scripthost",
73+
"es2015.collection"
74+
]
75+
}
76+
}

tools/profiler_ui/ui.css

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
table {
2+
border-collapse: collapse;
3+
}
4+
5+
td {
6+
border: 1px solid black;
7+
}
8+
9+
td.noborder {}
10+
11+
tr:hover {
12+
background-color: beige;
13+
}
14+
15+
thead {
16+
background-color: lightgrey;
17+
font-weight: bold;
18+
}
19+
20+
tr:nth-child(even) {
21+
background-color: lightgray;
22+
}
23+
24+
tr:nth-child(even):hover {
25+
background-color: beige;
26+
}
27+
28+
td.cpu_us {
29+
text-align: right;
30+
}
31+
32+
svg.dataRange {
33+
height: 10px;
34+
display: inline-block;
35+
}
36+
37+
svg.dataRange > g {
38+
transform: scale(100, 10);
39+
}
40+
41+
td.size {
42+
text-align: right;
43+
}
44+
45+
.clickable {
46+
cursor: pointer;
47+
}
48+
49+
td.invocations {
50+
text-align:right;
51+
}
52+
53+
.error {
54+
color: red;
55+
}
56+
57+
.filename {
58+
background: pink;
59+
}
60+
61+
.console {
62+
font-family: monospace;
63+
white-space: pre-wrap;
64+
word-break: break-all;
65+
background: #f0f0f0;
66+
}
67+
68+
.code {
69+
font-family: monospace;
70+
white-space: pre-wrap;
71+
word-break: break-all;
72+
background: #f0f0f0;
73+
}
74+
75+
.highlight {
76+
background: lightyellow;
77+
}
78+
79+
/* close, minimize, help page elements */
80+
.close {
81+
font-weight: bold;
82+
color: red;
83+
cursor: pointer;
84+
float: right;
85+
clear: right;
86+
}
87+
88+
.minimize {
89+
font-size: 20px;
90+
font-weight: bold;
91+
cursor: pointer;
92+
margin-left: 2px;
93+
margin-right: 2px;
94+
}

tools/profiler_ui/ui.html

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<html lang="en">
4+
5+
<head>
6+
<meta charset="UTF-8">
7+
<title>Profile view</title>
8+
<!-- Perhaps the following is not necessary, but I couldn't figure out how else to do it:
9+
https://stackoverflow.com/questions/43042889/typescript-referenceerror-exports-is-not-defined -->
10+
<link rel="stylesheet" href="ui.css">
11+
<script>var exports = {"__esModule": true};</script>
12+
<!-- The following file should define a variable named 'profiles' -->
13+
<script src="profile.js"></script>
14+
<script src="ui.js"></script>
15+
<script>
16+
// Each javascript loaded dynamically should insert an entry into this map.
17+
const globalMap = new Map();
18+
19+
// Return the value deposited in the globalMap, and remove it.
20+
function getGlobalMapValue(k) {
21+
var result = globalMap.get(k);
22+
globalMap.delete(k);
23+
return result;
24+
}
25+
26+
function loaded() {
27+
createUI(profiles);
28+
}
29+
</script>
30+
</head>
31+
32+
<body onload="loaded()">
33+
<div id="top">
34+
<!--
35+
<div id="dropbox" style="height:30px; background: grey; border-width: 1px; align-content: center">
36+
Drop file to display here.
37+
</div>
38+
-->
39+
</div>
40+
</body>
41+
</html>

0 commit comments

Comments
 (0)