1
2
3
4
5
6
7
8
9
10
11
12
13
14 package xfs_test
15
16 import (
17 "reflect"
18 "strings"
19 "testing"
20
21 "github.com/prometheus/procfs/xfs"
22 )
23
24 func TestParseStats(t *testing.T) {
25 tests := []struct {
26 name string
27 s string
28 fs bool
29 stats *xfs.Stats
30 invalid bool
31 }{
32 {
33 name: "empty file OK",
34 },
35 {
36 name: "short or empty lines and unknown labels ignored",
37 s: "one\n\ntwo 1 2 3\n",
38 stats: &xfs.Stats{},
39 },
40 {
41 name: "bad uint32",
42 s: "extent_alloc XXX",
43 invalid: true,
44 },
45 {
46 name: "bad uint64",
47 s: "xpc XXX",
48 invalid: true,
49 },
50 {
51 name: "extent_alloc bad",
52 s: "extent_alloc 1",
53 invalid: true,
54 },
55 {
56 name: "extent_alloc OK",
57 s: "extent_alloc 1 2 3 4",
58 stats: &xfs.Stats{
59 ExtentAllocation: xfs.ExtentAllocationStats{
60 ExtentsAllocated: 1,
61 BlocksAllocated: 2,
62 ExtentsFreed: 3,
63 BlocksFreed: 4,
64 },
65 },
66 },
67 {
68 name: "abt bad",
69 s: "abt 1",
70 invalid: true,
71 },
72 {
73 name: "abt OK",
74 s: "abt 1 2 3 4",
75 stats: &xfs.Stats{
76 AllocationBTree: xfs.BTreeStats{
77 Lookups: 1,
78 Compares: 2,
79 RecordsInserted: 3,
80 RecordsDeleted: 4,
81 },
82 },
83 },
84 {
85 name: "blk_map bad",
86 s: "blk_map 1",
87 invalid: true,
88 },
89 {
90 name: "blk_map OK",
91 s: "blk_map 1 2 3 4 5 6 7",
92 stats: &xfs.Stats{
93 BlockMapping: xfs.BlockMappingStats{
94 Reads: 1,
95 Writes: 2,
96 Unmaps: 3,
97 ExtentListInsertions: 4,
98 ExtentListDeletions: 5,
99 ExtentListLookups: 6,
100 ExtentListCompares: 7,
101 },
102 },
103 },
104 {
105 name: "bmbt bad",
106 s: "bmbt 1",
107 invalid: true,
108 },
109 {
110 name: "bmbt OK",
111 s: "bmbt 1 2 3 4",
112 stats: &xfs.Stats{
113 BlockMapBTree: xfs.BTreeStats{
114 Lookups: 1,
115 Compares: 2,
116 RecordsInserted: 3,
117 RecordsDeleted: 4,
118 },
119 },
120 },
121 {
122 name: "dir bad",
123 s: "dir 1",
124 invalid: true,
125 },
126 {
127 name: "dir OK",
128 s: "dir 1 2 3 4",
129 stats: &xfs.Stats{
130 DirectoryOperation: xfs.DirectoryOperationStats{
131 Lookups: 1,
132 Creates: 2,
133 Removes: 3,
134 Getdents: 4,
135 },
136 },
137 },
138 {
139 name: "trans bad",
140 s: "trans 1",
141 invalid: true,
142 },
143 {
144 name: "trans OK",
145 s: "trans 1 2 3",
146 stats: &xfs.Stats{
147 Transaction: xfs.TransactionStats{
148 Sync: 1,
149 Async: 2,
150 Empty: 3,
151 },
152 },
153 },
154 {
155 name: "ig bad",
156 s: "ig 1",
157 invalid: true,
158 },
159 {
160 name: "ig OK",
161 s: "ig 1 2 3 4 5 6 7",
162 stats: &xfs.Stats{
163 InodeOperation: xfs.InodeOperationStats{
164 Attempts: 1,
165 Found: 2,
166 Recycle: 3,
167 Missed: 4,
168 Duplicate: 5,
169 Reclaims: 6,
170 AttributeChange: 7,
171 },
172 },
173 },
174 {
175 name: "log bad",
176 s: "log 1",
177 invalid: true,
178 },
179 {
180 name: "log OK",
181 s: "log 1 2 3 4 5",
182 stats: &xfs.Stats{
183 LogOperation: xfs.LogOperationStats{
184 Writes: 1,
185 Blocks: 2,
186 NoInternalBuffers: 3,
187 Force: 4,
188 ForceSleep: 5,
189 },
190 },
191 },
192 {
193 name: "rw bad",
194 s: "rw 1",
195 invalid: true,
196 },
197 {
198 name: "rw OK",
199 s: "rw 1 2",
200 stats: &xfs.Stats{
201 ReadWrite: xfs.ReadWriteStats{
202 Write: 1,
203 Read: 2,
204 },
205 },
206 },
207 {
208 name: "attr bad",
209 s: "attr 1",
210 invalid: true,
211 },
212 {
213 name: "attr OK",
214 s: "attr 1 2 3 4",
215 stats: &xfs.Stats{
216 AttributeOperation: xfs.AttributeOperationStats{
217 Get: 1,
218 Set: 2,
219 Remove: 3,
220 List: 4,
221 },
222 },
223 },
224 {
225 name: "icluster bad",
226 s: "icluster 1",
227 invalid: true,
228 },
229 {
230 name: "icluster OK",
231 s: "icluster 1 2 3",
232 stats: &xfs.Stats{
233 InodeClustering: xfs.InodeClusteringStats{
234 Iflush: 1,
235 Flush: 2,
236 FlushInode: 3,
237 },
238 },
239 },
240 {
241 name: "vnodes bad",
242 s: "vnodes 1",
243 invalid: true,
244 },
245 {
246 name: "vnodes (missing free) OK",
247 s: "vnodes 1 2 3 4 5 6 7",
248 stats: &xfs.Stats{
249 Vnode: xfs.VnodeStats{
250 Active: 1,
251 Allocate: 2,
252 Get: 3,
253 Hold: 4,
254 Release: 5,
255 Reclaim: 6,
256 Remove: 7,
257 },
258 },
259 },
260 {
261 name: "vnodes (with free) OK",
262 s: "vnodes 1 2 3 4 5 6 7 8",
263 stats: &xfs.Stats{
264 Vnode: xfs.VnodeStats{
265 Active: 1,
266 Allocate: 2,
267 Get: 3,
268 Hold: 4,
269 Release: 5,
270 Reclaim: 6,
271 Remove: 7,
272 Free: 8,
273 },
274 },
275 },
276 {
277 name: "buf bad",
278 s: "buf 1",
279 invalid: true,
280 },
281 {
282 name: "buf OK",
283 s: "buf 1 2 3 4 5 6 7 8 9",
284 stats: &xfs.Stats{
285 Buffer: xfs.BufferStats{
286 Get: 1,
287 Create: 2,
288 GetLocked: 3,
289 GetLockedWaited: 4,
290 BusyLocked: 5,
291 MissLocked: 6,
292 PageRetries: 7,
293 PageFound: 8,
294 GetRead: 9,
295 },
296 },
297 },
298 {
299 name: "xpc bad",
300 s: "xpc 1",
301 invalid: true,
302 },
303 {
304 name: "xpc OK",
305 s: "xpc 1 2 3",
306 stats: &xfs.Stats{
307 ExtendedPrecision: xfs.ExtendedPrecisionStats{
308 FlushBytes: 1,
309 WriteBytes: 2,
310 ReadBytes: 3,
311 },
312 },
313 },
314 {
315 name: "xstrat bad",
316 s: "xstrat 1",
317 invalid: true,
318 },
319 {
320 name: "xstrat OK",
321 s: "xstrat 1 2",
322 stats: &xfs.Stats{
323 Xstrat: xfs.XstratStats{
324 Quick: 1,
325 Split: 2,
326 },
327 },
328 },
329 {
330 name: "push_ail bad",
331 s: "push_ail 1 2 3 4 5",
332 invalid: true,
333 },
334 {
335 name: "push_ail OK",
336 s: "push_ail 1 2 3 4 5 6 7 8 9 10",
337 stats: &xfs.Stats{
338 PushAil: xfs.PushAilStats{
339 TryLogspace: 1,
340 SleepLogspace: 2,
341 Pushes: 3,
342 Success: 4,
343 PushBuf: 5,
344 Pinned: 6,
345 Locked: 7,
346 Flushing: 8,
347 Restarts: 9,
348 Flush: 10,
349 },
350 },
351 },
352 {
353 name: "debug bad",
354 s: "debug 1 2",
355 invalid: true,
356 },
357 {
358 name: "debug OK",
359 s: "debug 1",
360 stats: &xfs.Stats{
361 Debug: xfs.DebugStats{
362 Enabled: 1,
363 },
364 },
365 },
366 {
367 name: "qm bad",
368 s: "qm 1 2 3 4 5 6 7",
369 invalid: true,
370 },
371 {
372 name: "qm bad",
373 s: "qm 1 2 3 4 5 6 7 8 9 10",
374 invalid: true,
375 },
376 {
377 name: "qm OK",
378 s: "qm 1 2 3 4 5 6 7 8",
379 stats: &xfs.Stats{
380 QuotaManager: xfs.QuotaManagerStats{
381 Reclaims: 1,
382 ReclaimMisses: 2,
383 DquoteDups: 3,
384 CacheMisses: 4,
385 CacheHits: 5,
386 Wants: 6,
387 ShakeReclaims: 7,
388 InactReclaims: 8,
389 },
390 },
391 },
392 {
393 name: "qm OK",
394 s: "qm 1 2 3 4 5 6 7 8 9",
395 stats: &xfs.Stats{
396 QuotaManager: xfs.QuotaManagerStats{
397 Reclaims: 1,
398 ReclaimMisses: 2,
399 DquoteDups: 3,
400 CacheMisses: 4,
401 CacheHits: 5,
402 Wants: 6,
403 ShakeReclaims: 7,
404 InactReclaims: 8,
405 Unused: 9,
406 },
407 },
408 },
409 {
410 name: "abtb2 bad",
411 s: "abtb2 1 2 3 4 5 6",
412 invalid: true,
413 },
414 {
415 name: "abtb2 OK",
416 s: "abtb2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",
417 stats: &xfs.Stats{
418 BtreeAllocBlocks2: xfs.BtreeAllocBlocks2Stats{
419 Lookup: 1,
420 Compare: 2,
421 Insrec: 3,
422 Delrec: 4,
423 NewRoot: 5,
424 KillRoot: 6,
425 Increment: 7,
426 Decrement: 8,
427 Lshift: 9,
428 Rshift: 10,
429 Split: 11,
430 Join: 12,
431 Alloc: 13,
432 Free: 14,
433 Moves: 15,
434 },
435 },
436 },
437 {
438 name: "abtc2 bad",
439 s: "abtc2 1 2 3 4 5 6",
440 invalid: true,
441 },
442 {
443 name: "abtc2 OK",
444 s: "abtc2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",
445 stats: &xfs.Stats{
446 BtreeAllocContig2: xfs.BtreeAllocContig2Stats{
447 Lookup: 1,
448 Compare: 2,
449 Insrec: 3,
450 Delrec: 4,
451 NewRoot: 5,
452 KillRoot: 6,
453 Increment: 7,
454 Decrement: 8,
455 Lshift: 9,
456 Rshift: 10,
457 Split: 11,
458 Join: 12,
459 Alloc: 13,
460 Free: 14,
461 Moves: 15,
462 },
463 },
464 },
465 {
466 name: "bmbt2 bad",
467 s: "bmbt2 1 2 3 4 5 6",
468 invalid: true,
469 },
470 {
471 name: "bmbt2 OK",
472 s: "bmbt2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",
473 stats: &xfs.Stats{
474 BtreeBlockMap2: xfs.BtreeBlockMap2Stats{
475 Lookup: 1,
476 Compare: 2,
477 Insrec: 3,
478 Delrec: 4,
479 NewRoot: 5,
480 KillRoot: 6,
481 Increment: 7,
482 Decrement: 8,
483 Lshift: 9,
484 Rshift: 10,
485 Split: 11,
486 Join: 12,
487 Alloc: 13,
488 Free: 14,
489 Moves: 15,
490 },
491 },
492 },
493 {
494 name: "ibt2 bad",
495 s: "ibt2 1 2 3 4 5 6",
496 invalid: true,
497 },
498 {
499 name: "ibt2 OK",
500 s: "ibt2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",
501 stats: &xfs.Stats{
502 BtreeInode2: xfs.BtreeInode2Stats{
503 Lookup: 1,
504 Compare: 2,
505 Insrec: 3,
506 Delrec: 4,
507 NewRoot: 5,
508 KillRoot: 6,
509 Increment: 7,
510 Decrement: 8,
511 Lshift: 9,
512 Rshift: 10,
513 Split: 11,
514 Join: 12,
515 Alloc: 13,
516 Free: 14,
517 Moves: 15,
518 },
519 },
520 },
521 {
522 name: "fixtures OK",
523 fs: true,
524 stats: &xfs.Stats{
525 ExtentAllocation: xfs.ExtentAllocationStats{
526 ExtentsAllocated: 92447,
527 BlocksAllocated: 97589,
528 ExtentsFreed: 92448,
529 BlocksFreed: 93751,
530 },
531 AllocationBTree: xfs.BTreeStats{
532 Lookups: 0,
533 Compares: 0,
534 RecordsInserted: 0,
535 RecordsDeleted: 0,
536 },
537 BlockMapping: xfs.BlockMappingStats{
538 Reads: 1767055,
539 Writes: 188820,
540 Unmaps: 184891,
541 ExtentListInsertions: 92447,
542 ExtentListDeletions: 92448,
543 ExtentListLookups: 2140766,
544 ExtentListCompares: 0,
545 },
546 BlockMapBTree: xfs.BTreeStats{
547 Lookups: 0,
548 Compares: 0,
549 RecordsInserted: 0,
550 RecordsDeleted: 0,
551 },
552 DirectoryOperation: xfs.DirectoryOperationStats{
553 Lookups: 185039,
554 Creates: 92447,
555 Removes: 92444,
556 Getdents: 136422,
557 },
558 Transaction: xfs.TransactionStats{
559 Sync: 706,
560 Async: 944304,
561 Empty: 0,
562 },
563 InodeOperation: xfs.InodeOperationStats{
564 Attempts: 185045,
565 Found: 58807,
566 Recycle: 0,
567 Missed: 126238,
568 Duplicate: 0,
569 Reclaims: 33637,
570 AttributeChange: 22,
571 },
572 LogOperation: xfs.LogOperationStats{
573 Writes: 2883,
574 Blocks: 113448,
575 NoInternalBuffers: 9,
576 Force: 17360,
577 ForceSleep: 739,
578 },
579 ReadWrite: xfs.ReadWriteStats{
580 Write: 107739,
581 Read: 94045,
582 },
583 AttributeOperation: xfs.AttributeOperationStats{
584 Get: 4,
585 Set: 0,
586 Remove: 0,
587 List: 0,
588 },
589 InodeClustering: xfs.InodeClusteringStats{
590 Iflush: 8677,
591 Flush: 7849,
592 FlushInode: 135802,
593 },
594 Vnode: xfs.VnodeStats{
595 Active: 92601,
596 Allocate: 0,
597 Get: 0,
598 Hold: 0,
599 Release: 92444,
600 Reclaim: 92444,
601 Remove: 92444,
602 Free: 0,
603 },
604 Buffer: xfs.BufferStats{
605 Get: 2666287,
606 Create: 7122,
607 GetLocked: 2659202,
608 GetLockedWaited: 3599,
609 BusyLocked: 2,
610 MissLocked: 7085,
611 PageRetries: 0,
612 PageFound: 10297,
613 GetRead: 7085,
614 },
615 ExtendedPrecision: xfs.ExtendedPrecisionStats{
616 FlushBytes: 399724544,
617 WriteBytes: 92823103,
618 ReadBytes: 86219234,
619 },
620 PushAil: xfs.PushAilStats{
621 TryLogspace: 945014,
622 SleepLogspace: 0,
623 Pushes: 134260,
624 Success: 15483,
625 PushBuf: 0,
626 Pinned: 3940,
627 Locked: 464,
628 Flushing: 159985,
629 Restarts: 0,
630 Flush: 40,
631 },
632 Xstrat: xfs.XstratStats{
633 Quick: 92447,
634 Split: 0,
635 },
636 Debug: xfs.DebugStats{
637 Enabled: 0,
638 },
639 QuotaManager: xfs.QuotaManagerStats{
640 Reclaims: 0,
641 ReclaimMisses: 0,
642 DquoteDups: 0,
643 CacheMisses: 0,
644 CacheHits: 0,
645 Wants: 0,
646 ShakeReclaims: 0,
647 InactReclaims: 0,
648 },
649 BtreeAllocBlocks2: xfs.BtreeAllocBlocks2Stats{
650 Lookup: 184941,
651 Compare: 1277345,
652 Insrec: 13257,
653 Delrec: 13278,
654 NewRoot: 0,
655 KillRoot: 0,
656 Increment: 0,
657 Decrement: 0,
658 Lshift: 0,
659 Rshift: 0,
660 Split: 0,
661 Join: 0,
662 Alloc: 0,
663 Free: 0,
664 Moves: 2746147,
665 },
666
667 BtreeAllocContig2: xfs.BtreeAllocContig2Stats{
668 Lookup: 345295,
669 Compare: 2416764,
670 Insrec: 172637,
671 Delrec: 172658,
672 NewRoot: 0,
673 KillRoot: 0,
674 Increment: 0,
675 Decrement: 0,
676 Lshift: 0,
677 Rshift: 0,
678 Split: 0,
679 Join: 0,
680 Alloc: 0,
681 Free: 0,
682 Moves: 21406023,
683 },
684
685 BtreeBlockMap2: xfs.BtreeBlockMap2Stats{
686 Lookup: 0,
687 Compare: 0,
688 Insrec: 0,
689 Delrec: 0,
690 NewRoot: 0,
691 KillRoot: 0,
692 Increment: 0,
693 Decrement: 0,
694 Lshift: 0,
695 Rshift: 0,
696 Split: 0,
697 Join: 0,
698 Alloc: 0,
699 Free: 0,
700 Moves: 0,
701 },
702
703 BtreeInode2: xfs.BtreeInode2Stats{
704 Lookup: 343004,
705 Compare: 1358467,
706 Insrec: 0,
707 Delrec: 0,
708 NewRoot: 0,
709 KillRoot: 0,
710 Increment: 0,
711 Decrement: 0,
712 Lshift: 0,
713 Rshift: 0,
714 Split: 0,
715 Join: 0,
716 Alloc: 0,
717 Free: 0,
718 Moves: 0,
719 },
720 },
721 },
722 }
723
724 for _, tt := range tests {
725 var (
726 stats *xfs.Stats
727 err error
728 )
729
730 if tt.s != "" {
731 stats, err = xfs.ParseStats(strings.NewReader(tt.s))
732 }
733 if tt.fs {
734 xfs, err := xfs.NewFS("testdata/fixtures/proc", "testdata/fixtures/sys")
735 if err != nil {
736 t.Fatalf("failed to access xfs fs: %v", err)
737 }
738 stats, err = xfs.ProcStat()
739 if err != nil {
740 t.Fatalf("failed to gather xfs stats: %v", err)
741 }
742 }
743
744 if tt.invalid && err == nil {
745 t.Error("expected an error, but none occurred")
746 }
747 if !tt.invalid && err != nil {
748 t.Errorf("unexpected error: %v", err)
749 }
750
751 if want, have := tt.stats, stats; !reflect.DeepEqual(want, have) {
752 t.Errorf("unexpected XFS stats:\nwant:\n%v\nhave:\n%v", want, have)
753 }
754 }
755 }
756
View as plain text