74 lines
		
	
	
	
		
			2.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			74 lines
		
	
	
	
		
			2.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
| #!/bin/bash
 | |
| File=$1
 | |
| CHeaderFile=$(dirname $File)/../include/rocksdb/c.h
 | |
| 
 | |
| echo "// **** DO NOT modify this file! ****"
 | |
| echo "// This file is generated by cmd:"
 | |
| echo "//   gen_perf_metrics.bash $@"
 | |
| echo ""
 | |
| echo "/// Rust representation of the performance metrics from RocksDB's perf_context"
 | |
| echo "#[derive(Debug, Copy, Clone, PartialEq, Eq)]"
 | |
| echo "#[repr(u32)]"
 | |
| echo "pub enum PerfMetric {"
 | |
| 
 | |
| # Extract the metric enum from c.h and generate our enum based on that ordering
 | |
| perl -n0e '
 | |
| # First find the enum block that contains rocksdb_user_key_comparison_count
 | |
| if (/enum\s*\{[^}]*rocksdb_user_key_comparison_count[^}]*\}/sm) {
 | |
|     $enum_block = $&;
 | |
|     
 | |
|     # Extract metrics from the enum, preserving order
 | |
|     @metrics = ();
 | |
|     $count = 0;
 | |
|     while ($enum_block =~ /rocksdb_(\w+)(?:\s*=\s*(\d+))?\s*,?/g) {
 | |
|         $metric = $1;
 | |
|         # If an explicit value is given, use it
 | |
|         if (defined $2) {
 | |
|             $count = $2;
 | |
|         }
 | |
|         push @metrics, [$metric, $count];
 | |
|         $count++;
 | |
|     }
 | |
|     
 | |
|     # Output the Rust enum variants
 | |
|     foreach $pair (@metrics) {
 | |
|         ($metric, $value) = @$pair;
 | |
|         # Convert snake_case to PascalCase
 | |
|         $name = $metric;
 | |
|         $name =~ s/(^|_)(\w)/\U$2/g;
 | |
|         print "    $name = $value,\n";
 | |
|     }
 | |
| }' $CHeaderFile
 | |
| 
 | |
| echo "}"
 | |
| echo ""
 | |
| echo "impl PerfMetric {"
 | |
| echo "    /// Returns the name of this metric as it appears in RocksDB C++"
 | |
| echo "    pub const fn name(&self) -> &'static str {"
 | |
| echo "        match self {"
 | |
| 
 | |
| # Generate name mappings for metrics from c.h
 | |
| perl -n0e '
 | |
| # Find the enum block that contains rocksdb_user_key_comparison_count
 | |
| if (/enum\s*\{[^}]*rocksdb_user_key_comparison_count[^}]*\}/sm) {
 | |
|     $enum_block = $&;
 | |
|     
 | |
|     %metric_names = ();
 | |
|     
 | |
|     # Extract metrics from the enum
 | |
|     while ($enum_block =~ /rocksdb_(\w+)/g) {
 | |
|         $metric = $1;
 | |
|         $name = $metric;
 | |
|         $name =~ s/(^|_)(\w)/\U$2/g;
 | |
|         $metric_names{$name} = $metric;
 | |
|     }
 | |
|     
 | |
|     # Output all mappings sorted by PascalCase name
 | |
|     foreach $name (sort keys %metric_names) {
 | |
|         print "            PerfMetric::$name => \"$metric_names{$name}\",\n";
 | |
|     }
 | |
| }' $CHeaderFile
 | |
| 
 | |
| echo "        }"
 | |
| echo "    }"
 | |
| echo "}"
 |