|
|
@@ -1,94 +0,0 @@
|
|
1
|
|
-extern crate osmpbf;
|
|
2
|
|
-extern crate crossbeam;
|
|
3
|
|
-
|
|
4
|
|
-use osmpbf::*;
|
|
5
|
|
-use std::fs::File;
|
|
6
|
|
-use std::sync::mpsc::sync_channel;
|
|
7
|
|
-
|
|
8
|
|
-
|
|
9
|
|
-enum WorkerMessage<'a> {
|
|
10
|
|
- PleaseStop,
|
|
11
|
|
- DoBlob(MmapBlob<'a>),
|
|
12
|
|
-}
|
|
13
|
|
-
|
|
14
|
|
-fn stats(file: &File) {
|
|
15
|
|
- let mmap = Mmap::from_file(file).unwrap();
|
|
16
|
|
-
|
|
17
|
|
- crossbeam::scope(|scope| {
|
|
18
|
|
- let mut iter = MmapBlobIter::new(&mmap);
|
|
19
|
|
-
|
|
20
|
|
- let num_threads = 4_usize;
|
|
21
|
|
- let mut chans = Vec::with_capacity(num_threads);
|
|
22
|
|
-
|
|
23
|
|
- let (result_tx, result_rx) = sync_channel::<(usize, usize)>(0);
|
|
24
|
|
-
|
|
25
|
|
- for thread_id in 0..num_threads {
|
|
26
|
|
- let result_tx = result_tx.clone();
|
|
27
|
|
-
|
|
28
|
|
- let (request_tx, request_rx) = sync_channel::<WorkerMessage>(0);
|
|
29
|
|
- chans.push(request_tx);
|
|
30
|
|
-
|
|
31
|
|
- scope.spawn(move || {
|
|
32
|
|
- loop {
|
|
33
|
|
- match request_rx.recv().unwrap() {
|
|
34
|
|
- WorkerMessage::PleaseStop => return,
|
|
35
|
|
- WorkerMessage::DoBlob(mmap_blob) => {
|
|
36
|
|
- let count = if let BlobDecode::OsmData(block) = mmap_blob.decode() {
|
|
37
|
|
- block.groups()
|
|
38
|
|
- .flat_map(|g| g.dense_nodes())
|
|
39
|
|
- .count()
|
|
40
|
|
- } else {
|
|
41
|
|
- 0
|
|
42
|
|
- };
|
|
43
|
|
- match result_tx.send((thread_id, count)) {
|
|
44
|
|
- Ok(_) => {},
|
|
45
|
|
- Err(_) => {
|
|
46
|
|
- println!("Thread id {}, Err", thread_id);
|
|
47
|
|
- return;
|
|
48
|
|
- },
|
|
49
|
|
- };
|
|
50
|
|
- },
|
|
51
|
|
- };
|
|
52
|
|
- }
|
|
53
|
|
- });
|
|
54
|
|
- }
|
|
55
|
|
-
|
|
56
|
|
- //TODO fix dead lock when number of blobs is less than number of threads
|
|
57
|
|
- for (thread_id, mmap_blob) in iter.by_ref().take(num_threads).enumerate() {
|
|
58
|
|
- chans[thread_id].send(WorkerMessage::DoBlob(mmap_blob)).unwrap();
|
|
59
|
|
- }
|
|
60
|
|
-
|
|
61
|
|
- let mut stopped = 0;
|
|
62
|
|
- let mut nodes = 0;
|
|
63
|
|
- loop {
|
|
64
|
|
- let (thread_id, count) = result_rx.recv().unwrap();
|
|
65
|
|
- nodes += count;
|
|
66
|
|
-
|
|
67
|
|
- if let Some(mmap_blob) = iter.next() {
|
|
68
|
|
- match chans[thread_id].send(WorkerMessage::DoBlob(mmap_blob)) {
|
|
69
|
|
- Ok(_) => {},
|
|
70
|
|
- Err(_) => {println!("Err");},
|
|
71
|
|
- };
|
|
72
|
|
- } else {
|
|
73
|
|
- match chans[thread_id].send(WorkerMessage::PleaseStop) {
|
|
74
|
|
- Ok(_) => {},
|
|
75
|
|
- Err(_) => {
|
|
76
|
|
- }
|
|
77
|
|
- };
|
|
78
|
|
- stopped += 1;
|
|
79
|
|
- if stopped == num_threads {
|
|
80
|
|
- break;
|
|
81
|
|
- }
|
|
82
|
|
- }
|
|
83
|
|
- }
|
|
84
|
|
-
|
|
85
|
|
- println!("Number of nodes: {}", nodes);
|
|
86
|
|
- });
|
|
87
|
|
-}
|
|
88
|
|
-
|
|
89
|
|
-fn main() {
|
|
90
|
|
- let path = std::env::args_os().nth(1).unwrap();
|
|
91
|
|
- let f = std::fs::File::open(path).unwrap();
|
|
92
|
|
-
|
|
93
|
|
- stats(&f);
|
|
94
|
|
-}
|