-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscan_block.jl
36 lines (29 loc) · 1.12 KB
/
scan_block.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
export scan_block
function scan_block(buf::IO, mem_block::Int, mem_trace::Int, keys::Array{String,1},
chunk_start::Int, file::String, th_byte2sample::Dict{String, Int32})
f = open(file)
swap_bytes = bswap_needed(f)
close(f)
# Calc info about this block
startbyte = position(buf) + chunk_start
ntraces_block = Int(mem_block/mem_trace)
headers = zeros(BinaryTraceHeader, ntraces_block)
count = 0
# Read all headers and record end byte
while !eof(buf) && count<ntraces_block
count += 1
read_traceheader!(buf, keys, th_byte2sample, headers[count]; swap_bytes=swap_bytes)
skip(buf, mem_trace-240)
end
endbyte = position(buf) + chunk_start
headers_block = view(headers,1:count)
# Parse headers for min/max
summary = Dict{String, Array{Int32,1}}()
for k in keys
tmp = Int32.([getfield((headers_block[i]), Symbol(k)) for i in 1:count])
summary["$k"] = [minimum(tmp); maximum(tmp)]
end # k
# Collect in BlockScan and return
scan = BlockScan(file, startbyte, endbyte, summary)
return scan
end