diff options
Diffstat (limited to '')
-rw-r--r-- | src/tests/nidstool.cpp | 115 |
1 files changed, 94 insertions, 21 deletions
diff --git a/src/tests/nidstool.cpp b/src/tests/nidstool.cpp index 546534e..1becba5 100644 --- a/src/tests/nidstool.cpp +++ b/src/tests/nidstool.cpp | |||
@@ -5,6 +5,13 @@ | |||
5 | 5 | ||
6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
7 | 7 | ||
8 | typedef struct Block | ||
9 | { | ||
10 | uint32_t uFirstBlock; | ||
11 | uint32_t uNextBlock; | ||
12 | uint32_t uBytesUsed; | ||
13 | } Block; | ||
14 | |||
8 | class Param : public Bu::ParamProc | 15 | class Param : public Bu::ParamProc |
9 | { | 16 | { |
10 | public: | 17 | public: |
@@ -14,7 +21,9 @@ public: | |||
14 | addParam("info", 'i', mkproc(Param::procInfo), | 21 | addParam("info", 'i', mkproc(Param::procInfo), |
15 | "Print some info about the file."); | 22 | "Print some info about the file."); |
16 | addParam("dump", 'd', mkproc(Param::procDump), | 23 | addParam("dump", 'd', mkproc(Param::procDump), |
17 | "Dump a stream to a file"); | 24 | "Dump a stream to a file."); |
25 | addParam("analyze", 'a', mkproc(Param::procAnalyze), | ||
26 | "Analyze a nids file."); | ||
18 | addParam("help", 'h', mkproc(Bu::ParamProc::help), "This help."); | 27 | addParam("help", 'h', mkproc(Bu::ParamProc::help), "This help."); |
19 | process( argc, argv ); | 28 | process( argc, argv ); |
20 | } | 29 | } |
@@ -23,6 +32,20 @@ public: | |||
23 | { | 32 | { |
24 | } | 33 | } |
25 | 34 | ||
35 | void printInfo( Bu::Nids &n ) | ||
36 | { | ||
37 | printf("File info:\n"); | ||
38 | printf(" Header overhead: %db\n", n.getBlockStart() ); | ||
39 | printf(" Block size: %db\n", n.getBlockSize() ); | ||
40 | printf(" Block count: %d\n", n.getNumBlocks() ); | ||
41 | printf(" Blocks used: %d (%d%%)\n", n.getNumUsedBlocks(), | ||
42 | n.getNumUsedBlocks()*100/n.getNumBlocks() ); | ||
43 | printf(" Block overhead: %db\n", n.getBlockOverhead() ); | ||
44 | printf(" Block storage: %db (%d%%)\n", | ||
45 | n.getBlockSize()-n.getBlockOverhead(), | ||
46 | (n.getBlockSize()-n.getBlockOverhead())*100/n.getBlockSize() ); | ||
47 | } | ||
48 | |||
26 | int procInfo( int argc, char *argv[] ) | 49 | int procInfo( int argc, char *argv[] ) |
27 | { | 50 | { |
28 | if( argc < 1 ) | 51 | if( argc < 1 ) |
@@ -35,27 +58,10 @@ public: | |||
35 | Bu::Nids n( fIn ); | 58 | Bu::Nids n( fIn ); |
36 | n.initialize(); | 59 | n.initialize(); |
37 | 60 | ||
38 | printf("Block size: %db\n", n.getBlockSize() ); | 61 | printInfo( n ); |
39 | printf("Block count: %d\n", n.getNumBlocks() ); | ||
40 | printf("Blocks used: %d (%d%%)\n", n.getNumUsedBlocks(), | ||
41 | n.getNumUsedBlocks()*100/n.getNumBlocks() ); | ||
42 | printf("Block start: %db\n", n.getBlockStart() ); | ||
43 | printf("Block overhead: %db\n", n.getBlockOverhead() ); | ||
44 | printf("Block storage: %db (%d%%)\n", | ||
45 | n.getBlockSize()-n.getBlockOverhead(), | ||
46 | (n.getBlockSize()-n.getBlockOverhead())*100/n.getBlockSize() ); | ||
47 | 62 | ||
48 | if( argc >= 2 ) | 63 | if( argc >= 2 ) |
49 | { | 64 | { |
50 | typedef struct Block | ||
51 | { | ||
52 | uint32_t uFirstBlock; | ||
53 | uint32_t uNextBlock; | ||
54 | uint32_t uPrevBlock; | ||
55 | uint32_t uBytesUsed; | ||
56 | uint32_t uReserved; | ||
57 | } Block; | ||
58 | |||
59 | uint32_t uStream = strtoul( argv[1], NULL, 0 ); | 65 | uint32_t uStream = strtoul( argv[1], NULL, 0 ); |
60 | uint32_t uBlock = uStream; | 66 | uint32_t uBlock = uStream; |
61 | 67 | ||
@@ -65,8 +71,8 @@ public: | |||
65 | { | 71 | { |
66 | fIn.setPos( n.getBlockStart()+n.getBlockSize()*uBlock ); | 72 | fIn.setPos( n.getBlockStart()+n.getBlockSize()*uBlock ); |
67 | fIn.read( &b, sizeof(Block) ); | 73 | fIn.read( &b, sizeof(Block) ); |
68 | printf("Stream %u: block %u, next %u, prev %u, %ub used.\n", | 74 | printf("Stream %u: block %u, next %u, %ub used.\n", |
69 | uStream, uBlock, b.uNextBlock, b.uPrevBlock, b.uBytesUsed | 75 | uStream, uBlock, b.uNextBlock, b.uBytesUsed |
70 | ); | 76 | ); |
71 | if( b.uNextBlock == 0xFFFFFFFFUL ) | 77 | if( b.uNextBlock == 0xFFFFFFFFUL ) |
72 | break; | 78 | break; |
@@ -112,6 +118,73 @@ public: | |||
112 | return 3; | 118 | return 3; |
113 | } | 119 | } |
114 | 120 | ||
121 | int procAnalyze( int argc, char *argv[] ) | ||
122 | { | ||
123 | if( argc < 1 ) | ||
124 | { | ||
125 | printf("You must provide a file name.\n"); | ||
126 | exit( 1 ); | ||
127 | } | ||
128 | |||
129 | Bu::File fIn( argv[0], Bu::File::Read ); | ||
130 | Bu::Nids n( fIn ); | ||
131 | n.initialize(); | ||
132 | |||
133 | printInfo( n ); | ||
134 | |||
135 | int iStreamCnt = 0; | ||
136 | int iStreamTotal = 0; | ||
137 | int iOneBlock = 0; | ||
138 | uint32_t iLargest = 0; | ||
139 | uint32_t iSmallest = 0; | ||
140 | int iWaste = 0; | ||
141 | int iUsable = n.getBlockSize()-n.getBlockOverhead(); | ||
142 | Block b; | ||
143 | for( int j = 0; j < n.getNumBlocks(); j++ ) | ||
144 | { | ||
145 | fIn.setPos( n.getBlockStart()+n.getBlockSize()*j ); | ||
146 | fIn.read( &b, sizeof(Block) ); | ||
147 | if( b.uFirstBlock != (uint32_t)j ) | ||
148 | continue; | ||
149 | |||
150 | iStreamCnt++; | ||
151 | iStreamTotal += b.uBytesUsed; | ||
152 | |||
153 | if( b.uNextBlock == 0xFFFFFFFFUL ) | ||
154 | { | ||
155 | iOneBlock++; | ||
156 | iWaste += iUsable - b.uBytesUsed; | ||
157 | } | ||
158 | else | ||
159 | { | ||
160 | iWaste += iUsable - (b.uBytesUsed%iUsable); | ||
161 | } | ||
162 | |||
163 | if( j == 0 ) | ||
164 | { | ||
165 | iSmallest = iLargest = b.uBytesUsed; | ||
166 | } | ||
167 | else | ||
168 | { | ||
169 | if( iLargest < b.uBytesUsed ) | ||
170 | iLargest = b.uBytesUsed; | ||
171 | if( iSmallest > b.uBytesUsed ) | ||
172 | iSmallest = b.uBytesUsed; | ||
173 | } | ||
174 | } | ||
175 | printf("Steam analysis:\n"); | ||
176 | printf(" Stream count: %d\n", iStreamCnt ); | ||
177 | printf(" Stream size: %db/%db/%db (min/avr/max)\n", | ||
178 | iSmallest, iStreamTotal/iStreamCnt, iLargest ); | ||
179 | printf(" One-block streams: %d (%d%%)\n", | ||
180 | iOneBlock, iOneBlock*100/iStreamCnt ); | ||
181 | printf(" Total wasted space: %db (%d%%)\n", | ||
182 | iWaste, iWaste*100/iStreamTotal ); | ||
183 | printf(" Avr blocks-per-stream: %f%%\n", | ||
184 | (float)n.getNumBlocks()/(float)iStreamCnt ); | ||
185 | |||
186 | return 1; | ||
187 | } | ||
115 | }; | 188 | }; |
116 | 189 | ||
117 | 190 | ||