Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright (C) 2021 Intel Corporation. 3 : : * All rights reserved. 4 : : */ 5 : : 6 : : #include "spdk/stdinc.h" 7 : : #include "spdk/zipf.h" 8 : : #include "spdk/histogram_data.h" 9 : : #include "spdk/string.h" 10 : : 11 : : static void 12 : 0 : usage(const char *prog) 13 : : { 14 [ # # ]: 0 : printf("usage: %s <theta> <range> <count>\n", prog); 15 : 0 : } 16 : : 17 : : static void 18 : 0 : print_bucket(void *ctx, uint64_t start, uint64_t end, uint64_t count, 19 : : uint64_t total, uint64_t so_far) 20 : : { 21 : : double so_far_pct; 22 : 0 : char range[64]; 23 : : 24 [ # # ]: 0 : if (count == 0) { 25 : 0 : return; 26 : : } 27 : : 28 : 0 : so_far_pct = (double)so_far * 100 / total; 29 [ # # ]: 0 : snprintf(range, sizeof(range), "[%ju, %ju)", start, end); 30 [ # # ]: 0 : printf("%24s: %9.4f%% (%9ju)\n", range, so_far_pct, count); 31 : : } 32 : : 33 : : int 34 : 0 : main(int argc, char **argv) 35 : : { 36 : 0 : struct spdk_zipf *zipf; 37 : : struct spdk_histogram_data *h; 38 : : float theta; 39 : : int range, count, i; 40 : : 41 [ # # ]: 0 : if (argc < 4) { 42 : 0 : usage(argv[0]); 43 : 0 : return 1; 44 : : } 45 : : 46 [ # # ]: 0 : theta = atof(argv[1]); 47 : 0 : range = spdk_strtol(argv[2], 10); 48 : 0 : count = spdk_strtol(argv[3], 10); 49 : : 50 [ # # # # ]: 0 : if (range <= 0 || count <= 0) { 51 : 0 : printf("range and count must be positive integers\n"); 52 : 0 : usage(argv[0]); 53 : 0 : return 1; 54 : : } 55 : : 56 : 0 : zipf = spdk_zipf_create(range, theta, time(NULL)); 57 : 0 : h = spdk_histogram_data_alloc(); 58 [ # # # # ]: 0 : if (zipf == NULL || h == NULL) { 59 : 0 : spdk_zipf_free(&zipf); 60 : 0 : spdk_histogram_data_free(h); 61 : 0 : printf("out of resource\n"); 62 : 0 : return 1; 63 : : } 64 : : 65 [ # # ]: 0 : for (i = 0; i < count; i++) { 66 : 0 : spdk_histogram_data_tally(h, spdk_zipf_generate(zipf)); 67 : : } 68 : : 69 : 0 : spdk_histogram_data_iterate(h, print_bucket, NULL); 70 : 0 : spdk_histogram_data_free(h); 71 : 0 : spdk_zipf_free(&zipf); 72 : : 73 : 0 : return 0; 74 : : }