2
2
3
3
module Profile
4
4
5
- import Base: hash, == , show_spec_linfo
5
+ import Base: show_spec_linfo
6
+ import Base. StackTraces: lookup, UNKNOWN
6
7
7
8
export @profile
8
9
117
118
118
119
function getdict (data:: Vector{UInt} )
119
120
uip = unique (data)
120
- Dict {UInt, LineInfo } ([ip=> lookup (ip) for ip in uip])
121
+ Dict {UInt, StackFrame } ([ip=> lookup (ip) for ip in uip])
121
122
end
122
123
123
124
# TODO update signature in docstring.
@@ -165,37 +166,6 @@ Julia, and examine the resulting `*.mem` files.
165
166
"""
166
167
clear_malloc_data () = ccall (:jl_clear_malloc_data , Void, ())
167
168
168
-
169
- # ###
170
- # ### Internal interface
171
- # ###
172
- immutable LineInfo
173
- func:: ByteString
174
- inlined_file:: ByteString
175
- inlined_line:: Int
176
- file:: ByteString
177
- line:: Int
178
- outer_linfo:: Nullable{LambdaStaticData}
179
- fromC:: Bool
180
- ip:: Int64 # large enough that this struct can be losslessly read on any machine (32 or 64 bit)
181
- end
182
-
183
- const UNKNOWN = LineInfo (" ?" , " ?" , - 1 , " ?" , - 1 , Nullable {LambdaStaticData} (), true , 0 )
184
-
185
- #
186
- # If the LineInfo has function and line information, we consider two of them the same
187
- # if they share the same function/line information. For unknown functions, line==ip
188
- # so we never actually need to consider the .ip field.
189
- #
190
- == (a:: LineInfo , b:: LineInfo ) = a. line == b. line && a. fromC == b. fromC && a. func == b. func && a. file == b. file
191
-
192
- function hash (li:: LineInfo , h:: UInt )
193
- h += 0xf4fbda67fe20ce88 % UInt
194
- h = hash (li. line, h)
195
- h = hash (li. file, h)
196
- h = hash (li. func, h)
197
- end
198
-
199
169
# C wrappers
200
170
start_timer () = ccall (:jl_profile_start_timer , Cint, ())
201
171
@@ -209,24 +179,6 @@ len_data() = convert(Int, ccall(:jl_profile_len_data, Csize_t, ()))
209
179
210
180
maxlen_data () = convert (Int, ccall (:jl_profile_maxlen_data , Csize_t, ()))
211
181
212
- const empty_sym = Symbol (" " )
213
- function lookup (ip:: Ptr{Void} )
214
- info = ccall (:jl_lookup_code_address , Any, (Ptr{Void},Cint), ip, false )
215
- if length (info) == 8
216
- is_inlined = (info[4 ] != = empty_sym)
217
- return LineInfo (string (info[1 ]),
218
- is_inlined ? string (info[2 ]) : " " ,
219
- is_inlined ? Int (info[3 ]) : - 1 ,
220
- string (is_inlined ? info[4 ] : info[2 ]),
221
- Int (is_inlined ? info[5 ] : info[3 ]),
222
- info[6 ] === nothing ? Nullable {LambdaStaticData} () : Nullable {LambdaStaticData} (info[6 ]),
223
- info[7 ], Int64 (info[8 ]))
224
- else
225
- return UNKNOWN
226
- end
227
- end
228
- lookup (ip:: UInt ) = lookup (convert (Ptr{Void},ip))
229
-
230
182
error_codes = Dict {Int,ASCIIString} (
231
183
- 1 => " cannot specify signal action for profiling" ,
232
184
- 2 => " cannot create the timer for profiling" ,
@@ -291,7 +243,7 @@ function parse_flat(iplist, n, lidict, C::Bool)
291
243
# The ones with no line number might appear multiple times in a single
292
244
# backtrace, giving the wrong impression about the total number of backtraces.
293
245
# Delete them too.
294
- keep = ! Bool[x == UNKNOWN || x. line == 0 || (x. fromC && ! C) for x in lilist]
246
+ keep = ! Bool[x == UNKNOWN || x. line == 0 || (x. from_c && ! C) for x in lilist]
295
247
n = n[keep]
296
248
lilist = lilist[keep]
297
249
lilist, n
@@ -310,7 +262,7 @@ function flat{T<:Unsigned}(io::IO, data::Vector{T}, lidict::Dict, C::Bool, combi
310
262
print_flat (io, lilist, n, combine, cols, sortedby)
311
263
end
312
264
313
- function print_flat (io:: IO , lilist:: Vector{LineInfo } , n:: Vector{Int} , combine:: Bool , cols:: Integer , sortedby)
265
+ function print_flat (io:: IO , lilist:: Vector{StackFrame } , n:: Vector{Int} , combine:: Bool , cols:: Integer , sortedby)
314
266
p = liperm (lilist)
315
267
lilist = lilist[p]
316
268
n = n[p]
@@ -339,8 +291,8 @@ function print_flat(io::IO, lilist::Vector{LineInfo}, n::Vector{Int}, combine::B
339
291
maxfunc = 10
340
292
for li in lilist
341
293
maxline = max (maxline, li. line)
342
- maxfile = max (maxfile, length (li. file))
343
- maxfunc = max (maxfunc, length (li. func))
294
+ maxfile = max (maxfile, length (string ( li. file) ))
295
+ maxfunc = max (maxfunc, length (string ( li. func) ))
344
296
end
345
297
wline = max (5 , ndigits (maxline))
346
298
ntext = cols - wcounts - wline - 3
@@ -389,9 +341,9 @@ function tree_aggregate{T<:Unsigned}(data::Vector{T})
389
341
bt, counts
390
342
end
391
343
392
- tree_format_linewidth (x:: LineInfo ) = ndigits (x. line)+ 6
344
+ tree_format_linewidth (x:: StackFrame ) = ndigits (x. line)+ 6
393
345
394
- function tree_format (lilist:: Vector{LineInfo } , counts:: Vector{Int} , level:: Int , cols:: Integer )
346
+ function tree_format (lilist:: Vector{StackFrame } , counts:: Vector{Int} , level:: Int , cols:: Integer )
395
347
nindent = min (cols>> 1 , level)
396
348
ndigcounts = ndigits (maximum (counts))
397
349
ndigline = maximum ([tree_format_linewidth (x) for x in lilist])
@@ -412,20 +364,22 @@ function tree_format(lilist::Vector{LineInfo}, counts::Vector{Int}, level::Int,
412
364
if showextra
413
365
base = string (base, " +" , nextra, " " )
414
366
end
415
- if li. line == li. ip
367
+ if li. line == li. pointer
416
368
strs[i] = string (base,
417
369
rpad (string (counts[i]), ndigcounts, " " ),
418
- " " ," unknown function (ip: 0x" ,hex (li. ip,2 * sizeof (Ptr{Void})),
370
+ " " ,
371
+ " unknown function (pointer: 0x" ,
372
+ hex (li. pointer,2 * sizeof (Ptr{Void})),
419
373
" )" )
420
374
else
421
- fname = li. func
375
+ fname = string ( li. func)
422
376
if ! li. fromC && ! isnull (li. outer_linfo)
423
377
fname = sprint (show_spec_linfo, Symbol (li. func), get (li. outer_linfo))
424
378
end
425
379
strs[i] = string (base,
426
380
rpad (string (counts[i]), ndigcounts, " " ),
427
381
" " ,
428
- rtruncto (li. file, widthfile),
382
+ rtruncto (string ( li. file) , widthfile),
429
383
" :" ,
430
384
li. line == - 1 ? " ?" : string (li. line),
431
385
" ; " ,
@@ -446,7 +400,7 @@ function tree{T<:Unsigned}(io::IO, bt::Vector{Vector{T}}, counts::Vector{Int}, l
446
400
# Organize backtraces into groups that are identical up to this level
447
401
if combine
448
402
# Combine based on the line information
449
- d = Dict {LineInfo ,Vector{Int}} ()
403
+ d = Dict {StackFrame ,Vector{Int}} ()
450
404
for i = 1 : length (bt)
451
405
ip = bt[i][level+ 1 ]
452
406
key = lidict[ip]
@@ -459,7 +413,7 @@ function tree{T<:Unsigned}(io::IO, bt::Vector{Vector{T}}, counts::Vector{Int}, l
459
413
end
460
414
# Generate counts
461
415
dlen = length (d)
462
- lilist = Array (LineInfo , dlen)
416
+ lilist = Array (StackFrame , dlen)
463
417
group = Array (Vector{Int}, dlen)
464
418
n = Array (Int, dlen)
465
419
i = 1
@@ -483,7 +437,7 @@ function tree{T<:Unsigned}(io::IO, bt::Vector{Vector{T}}, counts::Vector{Int}, l
483
437
end
484
438
# Generate counts, and do the code lookup
485
439
dlen = length (d)
486
- lilist = Array (LineInfo , dlen)
440
+ lilist = Array (StackFrame , dlen)
487
441
group = Array (Vector{Int}, dlen)
488
442
n = Array (Int, dlen)
489
443
i = 1
@@ -534,7 +488,7 @@ function tree{T<:Unsigned}(io::IO, data::Vector{T}, lidict::Dict, C::Bool, combi
534
488
end
535
489
536
490
function callersf (matchfunc:: Function , bt:: Vector{UInt} , lidict)
537
- counts = Dict {LineInfo , Int} ()
491
+ counts = Dict {StackFrame , Int} ()
538
492
lastmatched = false
539
493
for id in bt
540
494
if id == 0
@@ -574,8 +528,10 @@ function ltruncto(str::ByteString, w::Int)
574
528
end
575
529
576
530
531
+ truncto (str:: Symbol , w:: Int ) = truncto (string (str), w)
532
+
577
533
# Order alphabetically (file, function) and then by line number
578
- function liperm (lilist:: Vector{LineInfo } )
534
+ function liperm (lilist:: Vector{StackFrame } )
579
535
comb = Array (ByteString, length (lilist))
580
536
for i = 1 : length (lilist)
581
537
li = lilist[i]
@@ -594,7 +550,7 @@ warning_empty() = warn("""
594
550
Profile.init().""" )
595
551
596
552
function purgeC (data, lidict)
597
- keep = Bool[d == 0 || lidict[d]. fromC == false for d in data]
553
+ keep = Bool[d == 0 || lidict[d]. from_c == false for d in data]
598
554
data[keep]
599
555
end
600
556
0 commit comments