/src/fluent-bit/lib/chunkio/src/cio_stats.c
Line | Count | Source |
1 | | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* Chunk I/O |
4 | | * ========= |
5 | | * Copyright 2019 Eduardo Silva <eduardo@monkey.io> |
6 | | * |
7 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | | * you may not use this file except in compliance with the License. |
9 | | * You may obtain a copy of the License at |
10 | | * |
11 | | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | | * |
13 | | * Unless required by applicable law or agreed to in writing, software |
14 | | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | | * See the License for the specific language governing permissions and |
17 | | * limitations under the License. |
18 | | */ |
19 | | |
20 | | #include <stdio.h> |
21 | | #include <string.h> |
22 | | |
23 | | #include <chunkio/chunkio_compat.h> |
24 | | #include <chunkio/chunkio.h> |
25 | | #include <chunkio/cio_chunk.h> |
26 | | #include <chunkio/cio_stats.h> |
27 | | |
28 | | void cio_stats_get(struct cio_ctx *ctx, struct cio_stats *stats) |
29 | 971 | { |
30 | 971 | struct mk_list *head; |
31 | 971 | struct mk_list *f_head; |
32 | 971 | struct cio_chunk *ch; |
33 | 971 | struct cio_stream *stream; |
34 | | |
35 | 971 | memset(stats, 0, sizeof(struct cio_stats)); |
36 | | |
37 | | /* Iterate each stream */ |
38 | 1.45k | mk_list_foreach(head, &ctx->streams) { |
39 | 1.45k | stream = mk_list_entry(head, struct cio_stream, _head); |
40 | 1.45k | stats->streams_total++; |
41 | | |
42 | | /* Iterate chunks */ |
43 | 1.45k | mk_list_foreach(f_head, &stream->chunks) { |
44 | 0 | stats->chunks_total++; |
45 | |
|
46 | 0 | if (stream->type == CIO_STORE_MEM) { |
47 | 0 | stats->chunks_mem++; |
48 | 0 | continue; |
49 | 0 | } |
50 | | |
51 | | /* Only applicable for 'file' type chunks */ |
52 | 0 | ch = mk_list_entry(f_head, struct cio_chunk, _head); |
53 | 0 | stats->chunks_fs++; |
54 | |
|
55 | 0 | if (cio_chunk_is_up(ch) == CIO_TRUE) { |
56 | 0 | stats->chunks_fs_up++; |
57 | 0 | } |
58 | 0 | else { |
59 | 0 | stats->chunks_fs_down++; |
60 | 0 | } |
61 | 0 | } |
62 | 1.45k | } |
63 | 971 | } |
64 | | |
65 | | void cio_stats_print_summary(struct cio_ctx *ctx) |
66 | 0 | { |
67 | 0 | struct cio_stats st; |
68 | | |
69 | | /* retrieve stats */ |
70 | 0 | cio_stats_get(ctx, &st); |
71 | |
|
72 | 0 | printf("======== Chunk I/O Stats ========\n"); |
73 | 0 | printf("- streams total : %i\n", st.streams_total); |
74 | 0 | printf("- chunks total : %i\n", st.chunks_total); |
75 | 0 | printf("- chunks memfs total: %i\n", st.chunks_mem); |
76 | 0 | printf("- chunks file total : %i\n", st.chunks_fs); |
77 | 0 | printf(" - files up : %i\n", st.chunks_fs_up); |
78 | 0 | printf(" - files down : %i\n", st.chunks_fs_down); |
79 | 0 | } |