@@ -9,28 +9,35 @@ import { prewalk, prefor } from './tree.js'
9
9
import { open } from '../util/opener'
10
10
import { remote } from 'electron'
11
11
12
- function namestring ( func , file , line ) {
12
+ function namestring ( func , file , line , classes ) {
13
13
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
+ )
15
20
}
16
21
17
22
function process ( view , tree ) {
18
23
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} ) => ( {
20
26
count,
27
+ classes,
21
28
children,
22
- onmouseover : ( ) => view . current = { func, location, line, count} ,
29
+ onmouseover : ( ) => view . current = { func, location, line, count, classes } ,
23
30
onmouseout : ( ) => view . current = null ,
24
31
onclick : ( ) => open ( path , line - 1 , { pending : true } )
25
32
} ) )
26
33
}
27
34
28
35
function flatten ( tree ) {
29
36
const cache = { }
30
- prefor ( tree , ( { path, line, count} ) => {
37
+ prefor ( tree , ( { path, line, count, classes } ) => {
31
38
const key = JSON . stringify ( [ path , line ] )
32
39
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 }
34
41
val . count += count
35
42
} )
36
43
@@ -43,10 +50,11 @@ function flatten (tree) {
43
50
}
44
51
45
52
export class ProfileViewer {
46
- constructor ( { data, save= null } ) {
53
+ constructor ( { data, customClass = '' , save= null } ) {
47
54
this . rawData = data
48
55
this . data = process ( this , data )
49
56
this . save = save
57
+ this . customClass = customClass
50
58
this . highlights = require ( '../editor/highlights' ) . profileLines ( flatten ( this . rawData ) )
51
59
52
60
this . toolbar = view ( ( ) => this . toolbarView ( this . current ) )
@@ -65,11 +73,11 @@ export class ProfileViewer {
65
73
< Button icon = 'file' alt = 'Save' disabled = { ! this . save } onclick = { ( ) => this . saveData ( ) } />
66
74
</ span >
67
75
if ( ! current ) return < span > { always } </ span >
68
- const { func, location, line, count} = current
76
+ const { func, location, line, count, classes } = current
69
77
return < span >
70
78
{ always }
71
79
< 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 >
73
81
</ span >
74
82
}
75
83
@@ -86,7 +94,7 @@ export class ProfileViewer {
86
94
}
87
95
88
96
render ( ) {
89
- return < Canopy data = { this . data } />
97
+ return < Canopy className = { this . customClass } data = { this . data } />
90
98
}
91
99
92
100
build ( ) {
0 commit comments