1 /*- 2 * BSD LICENSE 3 * 4 * Copyright (c) Intel Corporation. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * * Neither the name of Intel Corporation nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #include "spdk/stdinc.h" 35 36 #include "spdk/env.h" 37 #include "spdk/util.h" 38 #include "spdk/histogram_data.h" 39 40 /* 41 * This applications is a simple test app used to test the performance of 42 * tallying datapoints with struct spdk_histogram_data. It can be used 43 * to measure the effect of changes to the spdk_histogram_data implementation. 44 * 45 * There are no command line parameters currently - it just tallies 46 * datapoints for 10 seconds in a default-sized histogram structure and 47 * then prints out the number of tallies performed. 48 */ 49 50 static void 51 usage(const char *prog) 52 { 53 printf("usage: %s\n", prog); 54 printf("Options:\n"); 55 } 56 57 int 58 main(int argc, char **argv) 59 { 60 struct spdk_histogram_data *h; 61 struct spdk_env_opts opts; 62 uint64_t tsc[128], t, end_tsc, count; 63 uint32_t i; 64 int ch; 65 int rc = 0; 66 67 while ((ch = getopt(argc, argv, "")) != -1) { 68 switch (ch) { 69 default: 70 usage(argv[0]); 71 return 1; 72 } 73 } 74 75 spdk_env_opts_init(&opts); 76 if (spdk_env_init(&opts)) { 77 printf("Err: Unable to initialize SPDK env\n"); 78 return 1; 79 } 80 81 for (i = 0; i < SPDK_COUNTOF(tsc); i++) { 82 tsc[i] = spdk_get_ticks(); 83 } 84 85 end_tsc = spdk_get_ticks() + (10 * spdk_get_ticks_hz()); 86 count = 0; 87 h = spdk_histogram_data_alloc(); 88 89 while (true) { 90 t = spdk_get_ticks(); 91 spdk_histogram_data_tally(h, t - tsc[count % 128]); 92 count++; 93 if (t > end_tsc) { 94 break; 95 } 96 } 97 98 printf("count = %ju\n", count); 99 spdk_histogram_data_free(h); 100 101 spdk_env_fini(); 102 return rc; 103 } 104