Skip to content

Commit 026a6b1

Browse files
authored
Merge pull request #247 from JunoLab/sp/newprofler
update profiler
2 parents 664101e + c6b829a commit 026a6b1

File tree

8 files changed

+76
-41
lines changed

8 files changed

+76
-41
lines changed

lib/debugger/stepper-view.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class StepperView
8484

8585
@view.parentElement.style.maxWidth = (window.innerWidth - RESULT_OFFSET - 10 - this.left) + 'px'
8686
@view.style.maxWidth = w + 'px'
87-
setTimeout((() => process.nextTick(() => window.requestAnimationFrame(@widthListener))), 15*1000/60)
87+
setTimeout((() => process.nextTick(() => window.requestAnimationFrame(@widthListener))), 300)
8888

8989
window.requestAnimationFrame(@widthListener)
9090

lib/editor/highlights.coffee

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,26 @@ module.exports =
2424
watch.dispose()
2525
m.destroy() for m in markers
2626

27+
profileLineView: (ed, count, classes) ->
28+
v = document.createElement 'div'
29+
v.classList.add('ink-profile-line')
30+
v.classList.add(cl) for cl in classes
31+
32+
v.style.width = count*ed.preferredLineLength*ed.defaultCharWidth + 'px'
33+
v
34+
2735
profileLines: (ls) ->
2836
markers = []
29-
watch = @observeLines ls, (ed, {line, count}) =>
30-
m = ed.markBufferRange [[line, 0], [line, 1+Math.round(count*ed.preferredLineLength)]],
31-
invalidate: 'touch'
37+
watch = @observeLines ls, (ed, {line, count, classes}) =>
38+
m = ed.markBufferRange [[line, 0], [line, 0]],
39+
invalidate: 'never'
3240
markers.push m
3341
ed.decorateMarker m,
34-
type: 'highlight'
35-
class: 'ink-profile-line'
42+
type: 'overlay'
43+
item: @profileLineView ed, count, classes
44+
class: 'ink-profile-overlay'
45+
avoidOverflow: false
46+
3647
destroy: =>
3748
watch.dispose()
3849
m.destroy() for m in markers

lib/editor/result-view.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ export default class ResultView {
163163
}
164164

165165
// only read from the DOM
166-
decideUpdateWidth (edRect) {
166+
decideUpdateWidth (edRect, winWidth) {
167+
this.edRect = edRect
168+
this.winWidth = winWidth
167169
this.isVisible = false
168170
this.left = 0
169171
this.shouldRedraw = false
@@ -179,7 +181,7 @@ export default class ResultView {
179181
}
180182

181183
// only write to the DOM
182-
updateWidth (edRect, winWidth) {
184+
updateWidth () {
183185
if (!!this.isVisible || this.model.expanded) {
184186
this.getView().style.visibility = 'visible'
185187
this.getView().style.pointerEvents = 'auto'
@@ -188,16 +190,16 @@ export default class ResultView {
188190
this.getView().style.pointerEvents = 'none'
189191
}
190192
if (!!this.isVisible && (this.shouldRedraw || this.modelUpdated)) {
191-
let w = edRect.right - RESULT_OFFSET - 10 - this.left
193+
let w = this.edRect.right - RESULT_OFFSET - 10 - this.left
192194
if (w < MIN_RESULT_WIDTH) w = MIN_RESULT_WIDTH
193-
if (edRect.width > 0 && this.left + RESULT_OFFSET + w > edRect.right) {
194-
this.getView().style.left = (edRect.right - w - 10 - this.left) + 'px'
195+
if (this.edRect.width > 0 && this.left + RESULT_OFFSET + w > this.edRect.right) {
196+
this.getView().style.left = (this.edRect.right - w - 10 - this.left) + 'px'
195197
this.getView().style.opacity = 0.75
196198
} else {
197199
this.getView().style.left = RESULT_OFFSET + 'px'
198200
this.getView().style.opacity = 1.0
199201
}
200-
this.getView().parentElement.style.maxWidth = (winWidth - RESULT_OFFSET - 10 - this.left) + 'px'
202+
this.getView().parentElement.style.maxWidth = (this.winWidth - RESULT_OFFSET - 10 - this.left) + 'px'
201203
this.getView().style.maxWidth = w + 'px'
202204
this.modelUpdated = false
203205
}

lib/editor/result.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ export default class Result {
256256
}))
257257

258258
let listener = () => {
259+
let allresults = []
259260
for (let edid in layers) {
260261
let res = layers[edid].getMarkers().map((m) => m.result)
261262
res = res.filter((r) => r.type === 'inline')
@@ -267,16 +268,19 @@ export default class Result {
267268
}
268269
let winWidth = window.innerWidth;
269270

270-
res.forEach((r) => r.view.decideUpdateWidth(rect))
271-
272-
// DOM writes
273-
res.forEach((r) => r.view.updateWidth(rect, winWidth))
271+
res.forEach((r) => r.view.decideUpdateWidth(rect, winWidth))
272+
allresults.push(...res)
274273
}
275274

275+
// DOM writes
276+
allresults.forEach((r) => r.view.updateWidth())
277+
278+
276279
setTimeout(() => {
277280
process.nextTick(() => window.requestAnimationFrame(listener))
278-
}, 500)
281+
}, 400)
279282
}
283+
280284
window.requestAnimationFrame(listener)
281285
return
282286
}
@@ -288,5 +292,5 @@ export default class Result {
288292

289293
// stopgap for https://github.com/atom/atom/issues/16454
290294
function uniqueEditorID(editor) {
291-
return editor.id + '_' + editor.buffer.id
295+
return editor.id
292296
}

lib/plots/canopy.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class Pannable extends Etch {
100100
this.outerContainerRect = this.refs.outerContainer.getBoundingClientRect()
101101

102102
this.setInitialScale(this.item)
103-
103+
104104
etch.update(this)
105105
}
106106

@@ -214,8 +214,8 @@ export class Pannable extends Etch {
214214

215215
class NodeView extends Etch {
216216
render() {
217-
let {height, width, top, left, onclick, onmouseover, onmouseout} = this.props;
218-
return <Clickable onclick={onclick}><div className='node' {...{onmouseover, onmouseout}} style={{
217+
const {height, width, top, left, onclick, classes, onmouseover, onmouseout} = this.props;
218+
return <Clickable onclick={onclick}><div className={`node ${classes.join(' ')}`} {...{onmouseover, onmouseout}} style={{
219219
height: 100*height+'%',
220220
width: 100*width +'%',
221221
top: 100*top +'%',
@@ -227,12 +227,13 @@ class NodeView extends Etch {
227227
}
228228

229229
export default class Canopy extends Etch {
230-
update({data}) {}
230+
update({data, className}) {}
231231
render() {
232-
let nodes = [];
233-
prefor(dims(this.props.data), node => nodes.push(<NodeView {...node} />));
234-
return <div className="ink-canopy">
232+
const nodes = []
233+
const className = this.props.className || ''
234+
prefor(dims(this.props.data), node => nodes.push(<NodeView {...node} />))
235+
return <div className={"ink-canopy " + className}>
235236
{nodes}
236-
</div>;
237+
</div>
237238
}
238239
}

lib/plots/profiler.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,35 @@ import { prewalk, prefor } from './tree.js'
99
import { open } from '../util/opener'
1010
import { remote } from 'electron'
1111

12-
function namestring (func, file, line) {
12+
function namestring (func, file, line, classes) {
1313
if (!func && !file) { return "Program" }
14-
return (func ? func + " at " : "") + file + (line == -1 ? "" : ":"+line)
14+
return (
15+
(func ? func + " at " : "") +
16+
file +
17+
(line === -1 ? "" : ":" + line) +
18+
(classes.length === 0 ? "" : " (" + classes.join(", ") + ")")
19+
)
1520
}
1621

1722
function process (view, tree) {
1823
tree.name = "Program"
19-
return prewalk(tree, ({count, children, location, func, path, line}) => ({
24+
return prewalk(tree, ({count, classes, children,
25+
location, func, path, line}) => ({
2026
count,
27+
classes,
2128
children,
22-
onmouseover: () => view.current = {func, location, line, count},
29+
onmouseover: () => view.current = {func, location, line, count, classes},
2330
onmouseout: () => view.current = null,
2431
onclick: () => open(path, line-1, {pending: true})
2532
}))
2633
}
2734

2835
function flatten (tree) {
2936
const cache = {}
30-
prefor(tree, ({path, line, count}) => {
37+
prefor(tree, ({path, line, count, classes}) => {
3138
const key = JSON.stringify([path, line])
3239
let val = cache[key]
33-
if (!val) val = cache[key] = {file: path, line: line-1, count: 0}
40+
if (!val) val = cache[key] = {file: path, line: line-1, count: 0, classes}
3441
val.count += count
3542
})
3643

@@ -43,10 +50,11 @@ function flatten (tree) {
4350
}
4451

4552
export class ProfileViewer {
46-
constructor ({data, save=null}) {
53+
constructor ({data, customClass='', save=null}) {
4754
this.rawData = data
4855
this.data = process(this, data)
4956
this.save = save
57+
this.customClass = customClass
5058
this.highlights = require('../editor/highlights').profileLines(flatten(this.rawData))
5159

5260
this.toolbar = view(() => this.toolbarView(this.current))
@@ -65,11 +73,11 @@ export class ProfileViewer {
6573
<Button icon='file' alt='Save' disabled={!this.save} onclick={() => this.saveData()}/>
6674
</span>
6775
if (!current) return <span>{always}</span>
68-
const {func, location, line, count} = current
76+
const {func, location, line, count, classes} = current
6977
return <span>
7078
{always}
7179
<span className='inline-block'><Badge>{count}</Badge></span>
72-
<span style='vertical-align:middle'>{namestring(func, location, line)}</span>
80+
<span style='vertical-align:middle'>{namestring(func, location, line, classes)}</span>
7381
</span>
7482
}
7583

@@ -86,7 +94,7 @@ export class ProfileViewer {
8694
}
8795

8896
render () {
89-
return <Canopy data={this.data} />
97+
return <Canopy className={this.customClass} data={this.data} />
9098
}
9199

92100
build () {

styles/canopy.less

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
padding: 1px;
1111
position: absolute;
1212
}
13+
1314
.node > div {
1415
width: 100%;
1516
height: 100%;
16-
border: solid @base-border-color 2px;
1717
border-radius: 5px;
18-
background: fade(@background-color-info,10%);
18+
border: solid fade(@background-color-info, 20%) 1px;
19+
background: fade(@background-color-info, 10%);
1920
&:hover {
20-
background: fade(@background-color-info,20%);
21+
background: fade(@background-color-info, 20%);
2122
}
2223
transition: all 0.2s;
2324

styles/ink.less

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,16 @@
135135
}
136136
}
137137

138-
.ink-profile-line {
139-
background: fade(@background-color-info, 20%);
138+
atom-overlay.ink-profile-overlay{
139+
pointer-events: none;
140+
z-index: 0 !important;
141+
.ink-profile-line {
142+
position: relative;
143+
height: 1.5em;
144+
top: -1.5em;
145+
border-radius: 0px 5px 5px 0px;
146+
background: fade(@background-color-info, 20%);
147+
}
140148
}
141149

142150
atom-text-editor {

0 commit comments

Comments
 (0)