rust-rocksdb-zaidoon1/librocksdb-sys/gen_statistics.bash
rockeet 638af3fab7 Improve statistics by auto gen enum Ticker & enum Histogram (#924)
* Improve statistics by auto gen enum Ticker & enum Histogram

1. librocksdb-sys/Makefile: Add gen_statistics and gen_statistics.bash,
     make -C librocksdb-sys gen_statistics will generate 2 files:
       src/statistics_enum_ticker.rs
       src/statistics_enum_histogram.rs

2. In statistics.rs, we include! these 2 files and remove old hand
   writing enum Tickers & enum Histograms.

3. File gen_statistics.bash is used for generating these 2 files
   which is called in Makefile.
2024-09-08 12:12:47 -04:00

19 lines
589 B
Bash

File=$1
EnumType=$2
echo "// **** DO NOT modify this file! ****"
echo "// This file is generated by cmd:"
echo "// gen_statistics.bash $@"
echo "iterable_named_enum! {"
echo " #[derive(Debug, Copy, Clone, PartialEq, Eq)]"
echo " #[repr(u32)]"
echo " pub enum $EnumType {"
perl -n0e '/const std::vector<std::pair<'$EnumType's, std::string>> '$EnumType'sNameMap.*?\};/sm && print $&' $File |
perl -n0e '
while (/\{\s*([\w_]+)\s*,.*?"(.*?)"/smg) {
$val = $2;
$name = lc($1);
$name =~ s/(\b|_)(\w)/\U$2/g;
print " $name(\"$val\"),\n"
}'
echo " }"
echo "}"