Skip to content

Commit

Permalink
Add missing godocs
Browse files Browse the repository at this point in the history
  • Loading branch information
aalda committed Mar 25, 2019
1 parent ce186ff commit 12c6586
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 69 deletions.
82 changes: 82 additions & 0 deletions rocksdb/histogram.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
Copyright 2018-2019 Banco Bilbao Vizcaya Argentaria, S.A.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package rocksdb

// #include "extended.h"
import (
"C"
)

type HistogramData struct {
c *C.rocksdb_histogram_data_t
}

// NewHistogramData constructs a HistogramData object.
func NewHistogramData() *HistogramData {
return &HistogramData{c: C.rocksdb_histogram_create_data()}
}

// GetAverage returns the average value.
func (d *HistogramData) GetAverage() float64 {
return float64(C.rocksdb_histogram_get_average(d.c))
}

// GetMedian returns the median value.
func (d *HistogramData) GetMedian() float64 {
return float64(C.rocksdb_histogram_get_median(d.c))
}

// GetPercentile95 returns the value of the percentile 95.
func (d *HistogramData) GetPercentile95() float64 {
return float64(C.rocksdb_histogram_get_percentile95(d.c))
}

// GetPercentile99 returns the value of the percentile 99.
func (d *HistogramData) GetPercentile99() float64 {
return float64(C.rocksdb_histogram_get_percentile99(d.c))
}

// GetStandardDeviation returns the value of the standard deviation.
func (d *HistogramData) GetStandardDeviation() float64 {
return float64(C.rocksdb_histogram_get_stdev(d.c))
}

// GetMax returns the max value.
func (d *HistogramData) GetMax() float64 {
return float64(C.rocksdb_histogram_get_max(d.c))
}

// GetCount returns the total number of measure.
func (d *HistogramData) GetCount() uint64 {
return uint64(C.rocksdb_histogram_get_count(d.c))
}

// GetSum returns the sum of all measures.
func (d *HistogramData) GetSum() uint64 {
return uint64(C.rocksdb_histogram_get_sum(d.c))
}

// GetMin returns the min value.
func (d *HistogramData) GetMin() float64 {
return float64(C.rocksdb_histogram_get_min(d.c))
}

// Destroy deallocates the HistogramData object.
func (d *HistogramData) Destroy() {
C.rocksdb_histogram_data_destroy(d.c)
d.c = nil
}
30 changes: 30 additions & 0 deletions rocksdb/histogram_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright 2018-2019 Banco Bilbao Vizcaya Argentaria, S.A.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package rocksdb

// #include "extended.h"
import (
"C"
)

// HistogramType is the logical mapping of histograms defined in rocksdb:Histogram.
type HistogramType uint32

const (
// HistogramBytesPerRead is value size distribution in read operations.
HistogramBytesPerRead = HistogramType(C.BYTES_PER_READ)
)
91 changes: 22 additions & 69 deletions rocksdb/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,56 +22,54 @@ import (
"C"
)

type TickerType uint32

const (
// The number of uncompressed bytes issued by db.Put(), db.Delete(),
// db.Merge(), and db.Write().
TickerBytesWritten = TickerType(C.BYTES_WRITTEN)
// TickerBytesRead is the number of uncompressed bytes read from db.Get().
// It could be either from memtables, cache, or table files.
// For the number of logical bytes read from db.MultiGet(),
// please use NumberMultiGetBytesRead.
TickerBytesRead = TickerType(C.BYTES_READ)
)

type HistogramType uint32

const (
HistogramBytesPerRead = HistogramType(C.BYTES_PER_READ)
)

// StatsLevel is the level of Statistics to report.
type StatsLevel uint32

const (
// All collect all stats, including measuring duration of mutex operations.
// LevelExceptHistogramOrTimers disables timer stats, and skip histogram stats.
LevelExceptHistogramOrTimers = StatsLevel(C.EXCEPT_HISTOGRAM_OR_TIMERS)
// LevelExceptTimers skips timer stats.
LevelExceptTimers = StatsLevel(C.EXCEPT_TIMERS)
// LevelExceptDetailedTimers collects all stats except time inside mutex lock
// AND time spent on compression.
LevelExceptDetailedTimers = StatsLevel(C.EXCEPT_DETAILED_TIMERS)
// LevelExceptTimeForMutex collect all stats except the counters requiring to get time
// inside the mutex lock.
LevelExceptTimeForMutex = StatsLevel(C.EXCEPT_TIME_FOR_MUTEX)
// LevelAll collects all stats, including measuring duration of mutex operations.
// If getting time is expensive on the platform to run, it can
// reduce scalability to more threads, especially for writes.
LevelAll = StatsLevel(C.ALL)
)

// Statistics is used to analyze the performance of a db. Pointer for
// statistics object is managed by Option class.
type Statistics struct {
c *C.rocksdb_statistics_t
}

// NewStatistics is the constructor for a Statistics struct.
func NewStatistics() *Statistics {
return &Statistics{c: C.rocksdb_create_statistics()}
}

// GetTickerCount gets the count for a ticker.
func (s *Statistics) GetTickerCount(tickerType TickerType) uint64 {
return uint64(C.rocksdb_statistics_get_ticker_count(
s.c,
C.rocksdb_tickers_t(tickerType),
))
}

// GetAndResetTickerCount get the count for a ticker and reset the tickers count.
func (s *Statistics) GetAndResetTickerCount(tickerType TickerType) uint64 {
return uint64(C.rocksdb_statistics_get_and_reset_ticker_count(
s.c,
C.rocksdb_tickers_t(tickerType),
))
}

// GetHistogramData gets the histogram data for a particular histogram.
func (s *Statistics) GetHistogramData(histogramType HistogramType) *HistogramData {
data := NewHistogramData()
C.rocksdb_statistics_histogram_data(
Expand All @@ -82,69 +80,24 @@ func (s *Statistics) GetHistogramData(histogramType HistogramType) *HistogramDat
return data
}

// Reset resets all ticker and histogram stats.
func (s *Statistics) Reset() {
C.rocksdb_statistics_reset(s.c)
}

// StatsLevel gets the current stats level.
func (s *Statistics) StatsLevel() StatsLevel {
return StatsLevel(C.rocksdb_statistics_stats_level(s.c))
}

// SetStatsLevel sets the stats level.
func (s *Statistics) SetStatsLevel(statsLevel StatsLevel) {
C.rocksdb_statistics_set_stats_level(
s.c, C.rocksdb_stats_level_t(statsLevel))
}

// Destroy deallocates the Statistics object.
func (s *Statistics) Destroy() {
C.rocksdb_statistics_destroy(s.c)
s.c = nil
}

type HistogramData struct {
c *C.rocksdb_histogram_data_t
}

func NewHistogramData() *HistogramData {
return &HistogramData{c: C.rocksdb_histogram_create_data()}
}

func (d *HistogramData) GetAverage() float64 {
return float64(C.rocksdb_histogram_get_average(d.c))
}

func (d *HistogramData) GetMedian() float64 {
return float64(C.rocksdb_histogram_get_median(d.c))
}

func (d *HistogramData) GetPercentile95() float64 {
return float64(C.rocksdb_histogram_get_percentile95(d.c))
}

func (d *HistogramData) GetPercentile99() float64 {
return float64(C.rocksdb_histogram_get_percentile99(d.c))
}

func (d *HistogramData) GetStandardDeviation() float64 {
return float64(C.rocksdb_histogram_get_stdev(d.c))
}

func (d *HistogramData) GetMax() float64 {
return float64(C.rocksdb_histogram_get_max(d.c))
}

func (d *HistogramData) GetCount() uint64 {
return uint64(C.rocksdb_histogram_get_count(d.c))
}

func (d *HistogramData) GetSum() uint64 {
return uint64(C.rocksdb_histogram_get_sum(d.c))
}

func (d *HistogramData) GetMin() float64 {
return float64(C.rocksdb_histogram_get_min(d.c))
}

func (d *HistogramData) Destroy() {
C.rocksdb_histogram_data_destroy(d.c)
d.c = nil
}
36 changes: 36 additions & 0 deletions rocksdb/ticker_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2018-2019 Banco Bilbao Vizcaya Argentaria, S.A.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package rocksdb

// #include "extended.h"
import (
"C"
)

// TickerType is the logical mapping of tickers defined in rocksdb::Tickers.
type TickerType uint32

const (
// TickerBytesWritten is the number of uncompressed bytes issued by db.Put(),
// db.Delete(), db.Merge(), and db.Write().
TickerBytesWritten = TickerType(C.BYTES_WRITTEN)
// TickerBytesRead is the number of uncompressed bytes read from db.Get().
// It could be either from memtables, cache, or table files.
// For the number of logical bytes read from db.MultiGet(),
// please use NumberMultiGetBytesRead.
TickerBytesRead = TickerType(C.BYTES_READ)
)

0 comments on commit 12c6586

Please sign in to comment.