repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
tecbot/gorocksdb
db.go
ListColumnFamilies
func ListColumnFamilies(opts *Options, name string) ([]string, error) { var ( cErr *C.char cLen C.size_t cName = C.CString(name) ) defer C.free(unsafe.Pointer(cName)) cNames := C.rocksdb_list_column_families(opts.c, cName, &cLen, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } namesLen := int(cLen) names := make([]string, namesLen) cNamesArr := (*[1 << 30]*C.char)(unsafe.Pointer(cNames))[:namesLen:namesLen] for i, n := range cNamesArr { names[i] = C.GoString(n) } C.rocksdb_list_column_families_destroy(cNames, cLen) return names, nil }
go
func ListColumnFamilies(opts *Options, name string) ([]string, error) { var ( cErr *C.char cLen C.size_t cName = C.CString(name) ) defer C.free(unsafe.Pointer(cName)) cNames := C.rocksdb_list_column_families(opts.c, cName, &cLen, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } namesLen := int(cLen) names := make([]string, namesLen) cNamesArr := (*[1 << 30]*C.char)(unsafe.Pointer(cNames))[:namesLen:namesLen] for i, n := range cNamesArr { names[i] = C.GoString(n) } C.rocksdb_list_column_families_destroy(cNames, cLen) return names, nil }
[ "func", "ListColumnFamilies", "(", "opts", "*", "Options", ",", "name", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "var", "(", "cErr", "*", "C", ".", "char", "\n", "cLen", "C", ".", "size_t", "\n", "cName", "=", "C", ".", "CS...
// ListColumnFamilies lists the names of the column families in the DB.
[ "ListColumnFamilies", "lists", "the", "names", "of", "the", "column", "families", "in", "the", "DB", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L186-L206
train
tecbot/gorocksdb
db.go
Get
func (db *DB) Get(opts *ReadOptions, key []byte) (*Slice, error) { var ( cErr *C.char cValLen C.size_t cKey = byteToChar(key) ) cValue := C.rocksdb_get(db.c, opts.c, cKey, C.size_t(len(key)), &cValLen, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } return NewSlice(cValue, cValLen), nil }
go
func (db *DB) Get(opts *ReadOptions, key []byte) (*Slice, error) { var ( cErr *C.char cValLen C.size_t cKey = byteToChar(key) ) cValue := C.rocksdb_get(db.c, opts.c, cKey, C.size_t(len(key)), &cValLen, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } return NewSlice(cValue, cValLen), nil }
[ "func", "(", "db", "*", "DB", ")", "Get", "(", "opts", "*", "ReadOptions", ",", "key", "[", "]", "byte", ")", "(", "*", "Slice", ",", "error", ")", "{", "var", "(", "cErr", "*", "C", ".", "char", "\n", "cValLen", "C", ".", "size_t", "\n", "cK...
// Get returns the data associated with the key from the database.
[ "Get", "returns", "the", "data", "associated", "with", "the", "key", "from", "the", "database", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L219-L231
train
tecbot/gorocksdb
db.go
GetBytes
func (db *DB) GetBytes(opts *ReadOptions, key []byte) ([]byte, error) { var ( cErr *C.char cValLen C.size_t cKey = byteToChar(key) ) cValue := C.rocksdb_get(db.c, opts.c, cKey, C.size_t(len(key)), &cValLen, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } if cValue == nil { return nil, nil } defer C.free(unsafe.Pointer(cValue)) return C.GoBytes(unsafe.Pointer(cValue), C.int(cValLen)), nil }
go
func (db *DB) GetBytes(opts *ReadOptions, key []byte) ([]byte, error) { var ( cErr *C.char cValLen C.size_t cKey = byteToChar(key) ) cValue := C.rocksdb_get(db.c, opts.c, cKey, C.size_t(len(key)), &cValLen, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } if cValue == nil { return nil, nil } defer C.free(unsafe.Pointer(cValue)) return C.GoBytes(unsafe.Pointer(cValue), C.int(cValLen)), nil }
[ "func", "(", "db", "*", "DB", ")", "GetBytes", "(", "opts", "*", "ReadOptions", ",", "key", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "(", "cErr", "*", "C", ".", "char", "\n", "cValLen", "C", ".", "size_t", ...
// GetBytes is like Get but returns a copy of the data.
[ "GetBytes", "is", "like", "Get", "but", "returns", "a", "copy", "of", "the", "data", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L234-L250
train
tecbot/gorocksdb
db.go
MultiGet
func (db *DB) MultiGet(opts *ReadOptions, keys ...[]byte) (Slices, error) { cKeys, cKeySizes := byteSlicesToCSlices(keys) defer cKeys.Destroy() vals := make(charsSlice, len(keys)) valSizes := make(sizeTSlice, len(keys)) rocksErrs := make(charsSlice, len(keys)) C.rocksdb_multi_get( db.c, opts.c, C.size_t(len(keys)), cKeys.c(), cKeySizes.c(), vals.c(), valSizes.c(), rocksErrs.c(), ) var errs []error for i, rocksErr := range rocksErrs { if rocksErr != nil { defer C.free(unsafe.Pointer(rocksErr)) err := fmt.Errorf("getting %q failed: %v", string(keys[i]), C.GoString(rocksErr)) errs = append(errs, err) } } if len(errs) > 0 { return nil, fmt.Errorf("failed to get %d keys, first error: %v", len(errs), errs[0]) } slices := make(Slices, len(keys)) for i, val := range vals { slices[i] = NewSlice(val, valSizes[i]) } return slices, nil }
go
func (db *DB) MultiGet(opts *ReadOptions, keys ...[]byte) (Slices, error) { cKeys, cKeySizes := byteSlicesToCSlices(keys) defer cKeys.Destroy() vals := make(charsSlice, len(keys)) valSizes := make(sizeTSlice, len(keys)) rocksErrs := make(charsSlice, len(keys)) C.rocksdb_multi_get( db.c, opts.c, C.size_t(len(keys)), cKeys.c(), cKeySizes.c(), vals.c(), valSizes.c(), rocksErrs.c(), ) var errs []error for i, rocksErr := range rocksErrs { if rocksErr != nil { defer C.free(unsafe.Pointer(rocksErr)) err := fmt.Errorf("getting %q failed: %v", string(keys[i]), C.GoString(rocksErr)) errs = append(errs, err) } } if len(errs) > 0 { return nil, fmt.Errorf("failed to get %d keys, first error: %v", len(errs), errs[0]) } slices := make(Slices, len(keys)) for i, val := range vals { slices[i] = NewSlice(val, valSizes[i]) } return slices, nil }
[ "func", "(", "db", "*", "DB", ")", "MultiGet", "(", "opts", "*", "ReadOptions", ",", "keys", "...", "[", "]", "byte", ")", "(", "Slices", ",", "error", ")", "{", "cKeys", ",", "cKeySizes", ":=", "byteSlicesToCSlices", "(", "keys", ")", "\n", "defer",...
// MultiGet returns the data associated with the passed keys from the database
[ "MultiGet", "returns", "the", "data", "associated", "with", "the", "passed", "keys", "from", "the", "database" ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L268-L306
train
tecbot/gorocksdb
db.go
MultiGetCF
func (db *DB) MultiGetCF(opts *ReadOptions, cf *ColumnFamilyHandle, keys ...[]byte) (Slices, error) { cfs := make(ColumnFamilyHandles, len(keys)) for i := 0; i < len(keys); i++ { cfs[i] = cf } return db.MultiGetCFMultiCF(opts, cfs, keys) }
go
func (db *DB) MultiGetCF(opts *ReadOptions, cf *ColumnFamilyHandle, keys ...[]byte) (Slices, error) { cfs := make(ColumnFamilyHandles, len(keys)) for i := 0; i < len(keys); i++ { cfs[i] = cf } return db.MultiGetCFMultiCF(opts, cfs, keys) }
[ "func", "(", "db", "*", "DB", ")", "MultiGetCF", "(", "opts", "*", "ReadOptions", ",", "cf", "*", "ColumnFamilyHandle", ",", "keys", "...", "[", "]", "byte", ")", "(", "Slices", ",", "error", ")", "{", "cfs", ":=", "make", "(", "ColumnFamilyHandles", ...
// MultiGetCF returns the data associated with the passed keys from the column family
[ "MultiGetCF", "returns", "the", "data", "associated", "with", "the", "passed", "keys", "from", "the", "column", "family" ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L309-L315
train
tecbot/gorocksdb
db.go
Put
func (db *DB) Put(opts *WriteOptions, key, value []byte) error { var ( cErr *C.char cKey = byteToChar(key) cValue = byteToChar(value) ) C.rocksdb_put(db.c, opts.c, cKey, C.size_t(len(key)), cValue, C.size_t(len(value)), &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
go
func (db *DB) Put(opts *WriteOptions, key, value []byte) error { var ( cErr *C.char cKey = byteToChar(key) cValue = byteToChar(value) ) C.rocksdb_put(db.c, opts.c, cKey, C.size_t(len(key)), cValue, C.size_t(len(value)), &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
[ "func", "(", "db", "*", "DB", ")", "Put", "(", "opts", "*", "WriteOptions", ",", "key", ",", "value", "[", "]", "byte", ")", "error", "{", "var", "(", "cErr", "*", "C", ".", "char", "\n", "cKey", "=", "byteToChar", "(", "key", ")", "\n", "cValu...
// Put writes data associated with a key to the database.
[ "Put", "writes", "data", "associated", "with", "a", "key", "to", "the", "database", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L361-L373
train
tecbot/gorocksdb
db.go
Delete
func (db *DB) Delete(opts *WriteOptions, key []byte) error { var ( cErr *C.char cKey = byteToChar(key) ) C.rocksdb_delete(db.c, opts.c, cKey, C.size_t(len(key)), &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
go
func (db *DB) Delete(opts *WriteOptions, key []byte) error { var ( cErr *C.char cKey = byteToChar(key) ) C.rocksdb_delete(db.c, opts.c, cKey, C.size_t(len(key)), &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
[ "func", "(", "db", "*", "DB", ")", "Delete", "(", "opts", "*", "WriteOptions", ",", "key", "[", "]", "byte", ")", "error", "{", "var", "(", "cErr", "*", "C", ".", "char", "\n", "cKey", "=", "byteToChar", "(", "key", ")", "\n", ")", "\n", "C", ...
// Delete removes the data associated with the key from the database.
[ "Delete", "removes", "the", "data", "associated", "with", "the", "key", "from", "the", "database", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L391-L402
train
tecbot/gorocksdb
db.go
Write
func (db *DB) Write(opts *WriteOptions, batch *WriteBatch) error { var cErr *C.char C.rocksdb_write(db.c, opts.c, batch.c, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
go
func (db *DB) Write(opts *WriteOptions, batch *WriteBatch) error { var cErr *C.char C.rocksdb_write(db.c, opts.c, batch.c, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
[ "func", "(", "db", "*", "DB", ")", "Write", "(", "opts", "*", "WriteOptions", ",", "batch", "*", "WriteBatch", ")", "error", "{", "var", "cErr", "*", "C", ".", "char", "\n", "C", ".", "rocksdb_write", "(", "db", ".", "c", ",", "opts", ".", "c", ...
// Write writes a WriteBatch to the database
[ "Write", "writes", "a", "WriteBatch", "to", "the", "database" ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L450-L458
train
tecbot/gorocksdb
db.go
NewIterator
func (db *DB) NewIterator(opts *ReadOptions) *Iterator { cIter := C.rocksdb_create_iterator(db.c, opts.c) return NewNativeIterator(unsafe.Pointer(cIter)) }
go
func (db *DB) NewIterator(opts *ReadOptions) *Iterator { cIter := C.rocksdb_create_iterator(db.c, opts.c) return NewNativeIterator(unsafe.Pointer(cIter)) }
[ "func", "(", "db", "*", "DB", ")", "NewIterator", "(", "opts", "*", "ReadOptions", ")", "*", "Iterator", "{", "cIter", ":=", "C", ".", "rocksdb_create_iterator", "(", "db", ".", "c", ",", "opts", ".", "c", ")", "\n", "return", "NewNativeIterator", "(",...
// NewIterator returns an Iterator over the the database that uses the // ReadOptions given.
[ "NewIterator", "returns", "an", "Iterator", "over", "the", "the", "database", "that", "uses", "the", "ReadOptions", "given", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L462-L465
train
tecbot/gorocksdb
db.go
NewIteratorCF
func (db *DB) NewIteratorCF(opts *ReadOptions, cf *ColumnFamilyHandle) *Iterator { cIter := C.rocksdb_create_iterator_cf(db.c, opts.c, cf.c) return NewNativeIterator(unsafe.Pointer(cIter)) }
go
func (db *DB) NewIteratorCF(opts *ReadOptions, cf *ColumnFamilyHandle) *Iterator { cIter := C.rocksdb_create_iterator_cf(db.c, opts.c, cf.c) return NewNativeIterator(unsafe.Pointer(cIter)) }
[ "func", "(", "db", "*", "DB", ")", "NewIteratorCF", "(", "opts", "*", "ReadOptions", ",", "cf", "*", "ColumnFamilyHandle", ")", "*", "Iterator", "{", "cIter", ":=", "C", ".", "rocksdb_create_iterator_cf", "(", "db", ".", "c", ",", "opts", ".", "c", ","...
// NewIteratorCF returns an Iterator over the the database and column family // that uses the ReadOptions given.
[ "NewIteratorCF", "returns", "an", "Iterator", "over", "the", "the", "database", "and", "column", "family", "that", "uses", "the", "ReadOptions", "given", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L469-L472
train
tecbot/gorocksdb
db.go
NewSnapshot
func (db *DB) NewSnapshot() *Snapshot { cSnap := C.rocksdb_create_snapshot(db.c) return NewNativeSnapshot(cSnap) }
go
func (db *DB) NewSnapshot() *Snapshot { cSnap := C.rocksdb_create_snapshot(db.c) return NewNativeSnapshot(cSnap) }
[ "func", "(", "db", "*", "DB", ")", "NewSnapshot", "(", ")", "*", "Snapshot", "{", "cSnap", ":=", "C", ".", "rocksdb_create_snapshot", "(", "db", ".", "c", ")", "\n", "return", "NewNativeSnapshot", "(", "cSnap", ")", "\n", "}" ]
// NewSnapshot creates a new snapshot of the database.
[ "NewSnapshot", "creates", "a", "new", "snapshot", "of", "the", "database", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L475-L478
train
tecbot/gorocksdb
db.go
GetProperty
func (db *DB) GetProperty(propName string) string { cprop := C.CString(propName) defer C.free(unsafe.Pointer(cprop)) cValue := C.rocksdb_property_value(db.c, cprop) defer C.free(unsafe.Pointer(cValue)) return C.GoString(cValue) }
go
func (db *DB) GetProperty(propName string) string { cprop := C.CString(propName) defer C.free(unsafe.Pointer(cprop)) cValue := C.rocksdb_property_value(db.c, cprop) defer C.free(unsafe.Pointer(cValue)) return C.GoString(cValue) }
[ "func", "(", "db", "*", "DB", ")", "GetProperty", "(", "propName", "string", ")", "string", "{", "cprop", ":=", "C", ".", "CString", "(", "propName", ")", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "cprop", ")", ")", "\n",...
// GetProperty returns the value of a database property.
[ "GetProperty", "returns", "the", "value", "of", "a", "database", "property", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L487-L493
train
tecbot/gorocksdb
db.go
GetPropertyCF
func (db *DB) GetPropertyCF(propName string, cf *ColumnFamilyHandle) string { cProp := C.CString(propName) defer C.free(unsafe.Pointer(cProp)) cValue := C.rocksdb_property_value_cf(db.c, cf.c, cProp) defer C.free(unsafe.Pointer(cValue)) return C.GoString(cValue) }
go
func (db *DB) GetPropertyCF(propName string, cf *ColumnFamilyHandle) string { cProp := C.CString(propName) defer C.free(unsafe.Pointer(cProp)) cValue := C.rocksdb_property_value_cf(db.c, cf.c, cProp) defer C.free(unsafe.Pointer(cValue)) return C.GoString(cValue) }
[ "func", "(", "db", "*", "DB", ")", "GetPropertyCF", "(", "propName", "string", ",", "cf", "*", "ColumnFamilyHandle", ")", "string", "{", "cProp", ":=", "C", ".", "CString", "(", "propName", ")", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "P...
// GetPropertyCF returns the value of a database property.
[ "GetPropertyCF", "returns", "the", "value", "of", "a", "database", "property", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L496-L502
train
tecbot/gorocksdb
db.go
CreateColumnFamily
func (db *DB) CreateColumnFamily(opts *Options, name string) (*ColumnFamilyHandle, error) { var ( cErr *C.char cName = C.CString(name) ) defer C.free(unsafe.Pointer(cName)) cHandle := C.rocksdb_create_column_family(db.c, opts.c, cName, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } return NewNativeColumnFamilyHandle(cHandle), nil }
go
func (db *DB) CreateColumnFamily(opts *Options, name string) (*ColumnFamilyHandle, error) { var ( cErr *C.char cName = C.CString(name) ) defer C.free(unsafe.Pointer(cName)) cHandle := C.rocksdb_create_column_family(db.c, opts.c, cName, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } return NewNativeColumnFamilyHandle(cHandle), nil }
[ "func", "(", "db", "*", "DB", ")", "CreateColumnFamily", "(", "opts", "*", "Options", ",", "name", "string", ")", "(", "*", "ColumnFamilyHandle", ",", "error", ")", "{", "var", "(", "cErr", "*", "C", ".", "char", "\n", "cName", "=", "C", ".", "CStr...
// CreateColumnFamily create a new column family.
[ "CreateColumnFamily", "create", "a", "new", "column", "family", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L505-L517
train
tecbot/gorocksdb
db.go
DropColumnFamily
func (db *DB) DropColumnFamily(c *ColumnFamilyHandle) error { var cErr *C.char C.rocksdb_drop_column_family(db.c, c.c, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
go
func (db *DB) DropColumnFamily(c *ColumnFamilyHandle) error { var cErr *C.char C.rocksdb_drop_column_family(db.c, c.c, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
[ "func", "(", "db", "*", "DB", ")", "DropColumnFamily", "(", "c", "*", "ColumnFamilyHandle", ")", "error", "{", "var", "cErr", "*", "C", ".", "char", "\n", "C", ".", "rocksdb_drop_column_family", "(", "db", ".", "c", ",", "c", ".", "c", ",", "&", "c...
// DropColumnFamily drops a column family.
[ "DropColumnFamily", "drops", "a", "column", "family", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L520-L528
train
tecbot/gorocksdb
db.go
GetApproximateSizesCF
func (db *DB) GetApproximateSizesCF(cf *ColumnFamilyHandle, ranges []Range) []uint64 { sizes := make([]uint64, len(ranges)) if len(ranges) == 0 { return sizes } cStarts := make([]*C.char, len(ranges)) cLimits := make([]*C.char, len(ranges)) cStartLens := make([]C.size_t, len(ranges)) cLimitLens := make([]C.size_t, len(ranges)) for i, r := range ranges { cStarts[i] = byteToChar(r.Start) cStartLens[i] = C.size_t(len(r.Start)) cLimits[i] = byteToChar(r.Limit) cLimitLens[i] = C.size_t(len(r.Limit)) } C.rocksdb_approximate_sizes_cf( db.c, cf.c, C.int(len(ranges)), &cStarts[0], &cStartLens[0], &cLimits[0], &cLimitLens[0], (*C.uint64_t)(&sizes[0])) return sizes }
go
func (db *DB) GetApproximateSizesCF(cf *ColumnFamilyHandle, ranges []Range) []uint64 { sizes := make([]uint64, len(ranges)) if len(ranges) == 0 { return sizes } cStarts := make([]*C.char, len(ranges)) cLimits := make([]*C.char, len(ranges)) cStartLens := make([]C.size_t, len(ranges)) cLimitLens := make([]C.size_t, len(ranges)) for i, r := range ranges { cStarts[i] = byteToChar(r.Start) cStartLens[i] = C.size_t(len(r.Start)) cLimits[i] = byteToChar(r.Limit) cLimitLens[i] = C.size_t(len(r.Limit)) } C.rocksdb_approximate_sizes_cf( db.c, cf.c, C.int(len(ranges)), &cStarts[0], &cStartLens[0], &cLimits[0], &cLimitLens[0], (*C.uint64_t)(&sizes[0])) return sizes }
[ "func", "(", "db", "*", "DB", ")", "GetApproximateSizesCF", "(", "cf", "*", "ColumnFamilyHandle", ",", "ranges", "[", "]", "Range", ")", "[", "]", "uint64", "{", "sizes", ":=", "make", "(", "[", "]", "uint64", ",", "len", "(", "ranges", ")", ")", "...
// GetApproximateSizesCF returns the approximate number of bytes of file system // space used by one or more key ranges in the column family. // // The keys counted will begin at Range.Start and end on the key before // Range.Limit.
[ "GetApproximateSizesCF", "returns", "the", "approximate", "number", "of", "bytes", "of", "file", "system", "space", "used", "by", "one", "or", "more", "key", "ranges", "in", "the", "column", "family", ".", "The", "keys", "counted", "will", "begin", "at", "Ra...
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L569-L597
train
tecbot/gorocksdb
db.go
GetLiveFilesMetaData
func (db *DB) GetLiveFilesMetaData() []LiveFileMetadata { lf := C.rocksdb_livefiles(db.c) defer C.rocksdb_livefiles_destroy(lf) count := C.rocksdb_livefiles_count(lf) liveFiles := make([]LiveFileMetadata, int(count)) for i := C.int(0); i < count; i++ { var liveFile LiveFileMetadata liveFile.Name = C.GoString(C.rocksdb_livefiles_name(lf, i)) liveFile.Level = int(C.rocksdb_livefiles_level(lf, i)) liveFile.Size = int64(C.rocksdb_livefiles_size(lf, i)) var cSize C.size_t key := C.rocksdb_livefiles_smallestkey(lf, i, &cSize) liveFile.SmallestKey = C.GoBytes(unsafe.Pointer(key), C.int(cSize)) key = C.rocksdb_livefiles_largestkey(lf, i, &cSize) liveFile.LargestKey = C.GoBytes(unsafe.Pointer(key), C.int(cSize)) liveFiles[int(i)] = liveFile } return liveFiles }
go
func (db *DB) GetLiveFilesMetaData() []LiveFileMetadata { lf := C.rocksdb_livefiles(db.c) defer C.rocksdb_livefiles_destroy(lf) count := C.rocksdb_livefiles_count(lf) liveFiles := make([]LiveFileMetadata, int(count)) for i := C.int(0); i < count; i++ { var liveFile LiveFileMetadata liveFile.Name = C.GoString(C.rocksdb_livefiles_name(lf, i)) liveFile.Level = int(C.rocksdb_livefiles_level(lf, i)) liveFile.Size = int64(C.rocksdb_livefiles_size(lf, i)) var cSize C.size_t key := C.rocksdb_livefiles_smallestkey(lf, i, &cSize) liveFile.SmallestKey = C.GoBytes(unsafe.Pointer(key), C.int(cSize)) key = C.rocksdb_livefiles_largestkey(lf, i, &cSize) liveFile.LargestKey = C.GoBytes(unsafe.Pointer(key), C.int(cSize)) liveFiles[int(i)] = liveFile } return liveFiles }
[ "func", "(", "db", "*", "DB", ")", "GetLiveFilesMetaData", "(", ")", "[", "]", "LiveFileMetadata", "{", "lf", ":=", "C", ".", "rocksdb_livefiles", "(", "db", ".", "c", ")", "\n", "defer", "C", ".", "rocksdb_livefiles_destroy", "(", "lf", ")", "\n\n", "...
// GetLiveFilesMetaData returns a list of all table files with their // level, start key and end key.
[ "GetLiveFilesMetaData", "returns", "a", "list", "of", "all", "table", "files", "with", "their", "level", "start", "key", "and", "end", "key", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L610-L631
train
tecbot/gorocksdb
db.go
CompactRangeCF
func (db *DB) CompactRangeCF(cf *ColumnFamilyHandle, r Range) { cStart := byteToChar(r.Start) cLimit := byteToChar(r.Limit) C.rocksdb_compact_range_cf(db.c, cf.c, cStart, C.size_t(len(r.Start)), cLimit, C.size_t(len(r.Limit))) }
go
func (db *DB) CompactRangeCF(cf *ColumnFamilyHandle, r Range) { cStart := byteToChar(r.Start) cLimit := byteToChar(r.Limit) C.rocksdb_compact_range_cf(db.c, cf.c, cStart, C.size_t(len(r.Start)), cLimit, C.size_t(len(r.Limit))) }
[ "func", "(", "db", "*", "DB", ")", "CompactRangeCF", "(", "cf", "*", "ColumnFamilyHandle", ",", "r", "Range", ")", "{", "cStart", ":=", "byteToChar", "(", "r", ".", "Start", ")", "\n", "cLimit", ":=", "byteToChar", "(", "r", ".", "Limit", ")", "\n", ...
// CompactRangeCF runs a manual compaction on the Range of keys given on the // given column family. This is not likely to be needed for typical usage.
[ "CompactRangeCF", "runs", "a", "manual", "compaction", "on", "the", "Range", "of", "keys", "given", "on", "the", "given", "column", "family", ".", "This", "is", "not", "likely", "to", "be", "needed", "for", "typical", "usage", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L643-L647
train
tecbot/gorocksdb
db.go
Flush
func (db *DB) Flush(opts *FlushOptions) error { var cErr *C.char C.rocksdb_flush(db.c, opts.c, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
go
func (db *DB) Flush(opts *FlushOptions) error { var cErr *C.char C.rocksdb_flush(db.c, opts.c, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
[ "func", "(", "db", "*", "DB", ")", "Flush", "(", "opts", "*", "FlushOptions", ")", "error", "{", "var", "cErr", "*", "C", ".", "char", "\n", "C", ".", "rocksdb_flush", "(", "db", ".", "c", ",", "opts", ".", "c", ",", "&", "cErr", ")", "\n", "...
// Flush triggers a manuel flush for the database.
[ "Flush", "triggers", "a", "manuel", "flush", "for", "the", "database", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L650-L658
train
tecbot/gorocksdb
db.go
DisableFileDeletions
func (db *DB) DisableFileDeletions() error { var cErr *C.char C.rocksdb_disable_file_deletions(db.c, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
go
func (db *DB) DisableFileDeletions() error { var cErr *C.char C.rocksdb_disable_file_deletions(db.c, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
[ "func", "(", "db", "*", "DB", ")", "DisableFileDeletions", "(", ")", "error", "{", "var", "cErr", "*", "C", ".", "char", "\n", "C", ".", "rocksdb_disable_file_deletions", "(", "db", ".", "c", ",", "&", "cErr", ")", "\n", "if", "cErr", "!=", "nil", ...
// DisableFileDeletions disables file deletions and should be used when backup the database.
[ "DisableFileDeletions", "disables", "file", "deletions", "and", "should", "be", "used", "when", "backup", "the", "database", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L661-L669
train
tecbot/gorocksdb
db.go
EnableFileDeletions
func (db *DB) EnableFileDeletions(force bool) error { var cErr *C.char C.rocksdb_enable_file_deletions(db.c, boolToChar(force), &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
go
func (db *DB) EnableFileDeletions(force bool) error { var cErr *C.char C.rocksdb_enable_file_deletions(db.c, boolToChar(force), &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
[ "func", "(", "db", "*", "DB", ")", "EnableFileDeletions", "(", "force", "bool", ")", "error", "{", "var", "cErr", "*", "C", ".", "char", "\n", "C", ".", "rocksdb_enable_file_deletions", "(", "db", ".", "c", ",", "boolToChar", "(", "force", ")", ",", ...
// EnableFileDeletions enables file deletions for the database.
[ "EnableFileDeletions", "enables", "file", "deletions", "for", "the", "database", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L672-L680
train
tecbot/gorocksdb
db.go
IngestExternalFile
func (db *DB) IngestExternalFile(filePaths []string, opts *IngestExternalFileOptions) error { cFilePaths := make([]*C.char, len(filePaths)) for i, s := range filePaths { cFilePaths[i] = C.CString(s) } defer func() { for _, s := range cFilePaths { C.free(unsafe.Pointer(s)) } }() var cErr *C.char C.rocksdb_ingest_external_file( db.c, &cFilePaths[0], C.size_t(len(filePaths)), opts.c, &cErr, ) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
go
func (db *DB) IngestExternalFile(filePaths []string, opts *IngestExternalFileOptions) error { cFilePaths := make([]*C.char, len(filePaths)) for i, s := range filePaths { cFilePaths[i] = C.CString(s) } defer func() { for _, s := range cFilePaths { C.free(unsafe.Pointer(s)) } }() var cErr *C.char C.rocksdb_ingest_external_file( db.c, &cFilePaths[0], C.size_t(len(filePaths)), opts.c, &cErr, ) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
[ "func", "(", "db", "*", "DB", ")", "IngestExternalFile", "(", "filePaths", "[", "]", "string", ",", "opts", "*", "IngestExternalFileOptions", ")", "error", "{", "cFilePaths", ":=", "make", "(", "[", "]", "*", "C", ".", "char", ",", "len", "(", "filePat...
// IngestExternalFile loads a list of external SST files.
[ "IngestExternalFile", "loads", "a", "list", "of", "external", "SST", "files", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L692-L718
train
tecbot/gorocksdb
db.go
DestroyDb
func DestroyDb(name string, opts *Options) error { var ( cErr *C.char cName = C.CString(name) ) defer C.free(unsafe.Pointer(cName)) C.rocksdb_destroy_db(opts.c, cName, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
go
func DestroyDb(name string, opts *Options) error { var ( cErr *C.char cName = C.CString(name) ) defer C.free(unsafe.Pointer(cName)) C.rocksdb_destroy_db(opts.c, cName, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
[ "func", "DestroyDb", "(", "name", "string", ",", "opts", "*", "Options", ")", "error", "{", "var", "(", "cErr", "*", "C", ".", "char", "\n", "cName", "=", "C", ".", "CString", "(", "name", ")", "\n", ")", "\n", "defer", "C", ".", "free", "(", "...
// DestroyDb removes a database entirely, removing everything from the // filesystem.
[ "DestroyDb", "removes", "a", "database", "entirely", "removing", "everything", "from", "the", "filesystem", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L773-L785
train
tecbot/gorocksdb
options_write.go
Destroy
func (opts *WriteOptions) Destroy() { C.rocksdb_writeoptions_destroy(opts.c) opts.c = nil }
go
func (opts *WriteOptions) Destroy() { C.rocksdb_writeoptions_destroy(opts.c) opts.c = nil }
[ "func", "(", "opts", "*", "WriteOptions", ")", "Destroy", "(", ")", "{", "C", ".", "rocksdb_writeoptions_destroy", "(", "opts", ".", "c", ")", "\n", "opts", ".", "c", "=", "nil", "\n", "}" ]
// Destroy deallocates the WriteOptions object.
[ "Destroy", "deallocates", "the", "WriteOptions", "object", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/options_write.go#L39-L42
train
tecbot/gorocksdb
options_compression.go
NewCompressionOptions
func NewCompressionOptions(windowBits, level, strategy, maxDictBytes int) *CompressionOptions { return &CompressionOptions{ WindowBits: windowBits, Level: level, Strategy: strategy, MaxDictBytes: maxDictBytes, } }
go
func NewCompressionOptions(windowBits, level, strategy, maxDictBytes int) *CompressionOptions { return &CompressionOptions{ WindowBits: windowBits, Level: level, Strategy: strategy, MaxDictBytes: maxDictBytes, } }
[ "func", "NewCompressionOptions", "(", "windowBits", ",", "level", ",", "strategy", ",", "maxDictBytes", "int", ")", "*", "CompressionOptions", "{", "return", "&", "CompressionOptions", "{", "WindowBits", ":", "windowBits", ",", "Level", ":", "level", ",", "Strat...
// NewCompressionOptions creates a CompressionOptions object.
[ "NewCompressionOptions", "creates", "a", "CompressionOptions", "object", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/options_compression.go#L17-L24
train
tecbot/gorocksdb
checkpoint.go
Destroy
func (checkpoint *Checkpoint) Destroy() { C.rocksdb_checkpoint_object_destroy(checkpoint.c) checkpoint.c = nil }
go
func (checkpoint *Checkpoint) Destroy() { C.rocksdb_checkpoint_object_destroy(checkpoint.c) checkpoint.c = nil }
[ "func", "(", "checkpoint", "*", "Checkpoint", ")", "Destroy", "(", ")", "{", "C", ".", "rocksdb_checkpoint_object_destroy", "(", "checkpoint", ".", "c", ")", "\n", "checkpoint", ".", "c", "=", "nil", "\n", "}" ]
// Destroy deallocates the Checkpoint object.
[ "Destroy", "deallocates", "the", "Checkpoint", "object", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/checkpoint.go#L53-L56
train
tecbot/gorocksdb
options_flush.go
Destroy
func (opts *FlushOptions) Destroy() { C.rocksdb_flushoptions_destroy(opts.c) opts.c = nil }
go
func (opts *FlushOptions) Destroy() { C.rocksdb_flushoptions_destroy(opts.c) opts.c = nil }
[ "func", "(", "opts", "*", "FlushOptions", ")", "Destroy", "(", ")", "{", "C", ".", "rocksdb_flushoptions_destroy", "(", "opts", ".", "c", ")", "\n", "opts", ".", "c", "=", "nil", "\n", "}" ]
// Destroy deallocates the FlushOptions object.
[ "Destroy", "deallocates", "the", "FlushOptions", "object", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/options_flush.go#L29-L32
train
tecbot/gorocksdb
memory_usage.go
GetApproximateMemoryUsageByType
func GetApproximateMemoryUsageByType(dbs []*DB, caches []*Cache) (*MemoryUsage, error) { // register memory consumers consumers := C.rocksdb_memory_consumers_create() defer C.rocksdb_memory_consumers_destroy(consumers) for _, db := range dbs { if db != nil { C.rocksdb_memory_consumers_add_db(consumers, db.c) } } for _, cache := range caches { if cache != nil { C.rocksdb_memory_consumers_add_cache(consumers, cache.c) } } // obtain memory usage stats var cErr *C.char memoryUsage := C.rocksdb_approximate_memory_usage_create(consumers, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } defer C.rocksdb_approximate_memory_usage_destroy(memoryUsage) result := &MemoryUsage{ MemTableTotal: uint64(C.rocksdb_approximate_memory_usage_get_mem_table_total(memoryUsage)), MemTableUnflushed: uint64(C.rocksdb_approximate_memory_usage_get_mem_table_unflushed(memoryUsage)), MemTableReadersTotal: uint64(C.rocksdb_approximate_memory_usage_get_mem_table_readers_total(memoryUsage)), CacheTotal: uint64(C.rocksdb_approximate_memory_usage_get_cache_total(memoryUsage)), } return result, nil }
go
func GetApproximateMemoryUsageByType(dbs []*DB, caches []*Cache) (*MemoryUsage, error) { // register memory consumers consumers := C.rocksdb_memory_consumers_create() defer C.rocksdb_memory_consumers_destroy(consumers) for _, db := range dbs { if db != nil { C.rocksdb_memory_consumers_add_db(consumers, db.c) } } for _, cache := range caches { if cache != nil { C.rocksdb_memory_consumers_add_cache(consumers, cache.c) } } // obtain memory usage stats var cErr *C.char memoryUsage := C.rocksdb_approximate_memory_usage_create(consumers, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } defer C.rocksdb_approximate_memory_usage_destroy(memoryUsage) result := &MemoryUsage{ MemTableTotal: uint64(C.rocksdb_approximate_memory_usage_get_mem_table_total(memoryUsage)), MemTableUnflushed: uint64(C.rocksdb_approximate_memory_usage_get_mem_table_unflushed(memoryUsage)), MemTableReadersTotal: uint64(C.rocksdb_approximate_memory_usage_get_mem_table_readers_total(memoryUsage)), CacheTotal: uint64(C.rocksdb_approximate_memory_usage_get_cache_total(memoryUsage)), } return result, nil }
[ "func", "GetApproximateMemoryUsageByType", "(", "dbs", "[", "]", "*", "DB", ",", "caches", "[", "]", "*", "Cache", ")", "(", "*", "MemoryUsage", ",", "error", ")", "{", "// register memory consumers", "consumers", ":=", "C", ".", "rocksdb_memory_consumers_create...
// GetApproximateMemoryUsageByType returns summary // memory usage stats for given databases and caches.
[ "GetApproximateMemoryUsageByType", "returns", "summary", "memory", "usage", "stats", "for", "given", "databases", "and", "caches", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/memory_usage.go#L25-L58
train
tecbot/gorocksdb
transactiondb.go
OpenTransactionDb
func OpenTransactionDb( opts *Options, transactionDBOpts *TransactionDBOptions, name string, ) (*TransactionDB, error) { var ( cErr *C.char cName = C.CString(name) ) defer C.free(unsafe.Pointer(cName)) db := C.rocksdb_transactiondb_open( opts.c, transactionDBOpts.c, cName, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } return &TransactionDB{ name: name, c: db, opts: opts, transactionDBOpts: transactionDBOpts, }, nil }
go
func OpenTransactionDb( opts *Options, transactionDBOpts *TransactionDBOptions, name string, ) (*TransactionDB, error) { var ( cErr *C.char cName = C.CString(name) ) defer C.free(unsafe.Pointer(cName)) db := C.rocksdb_transactiondb_open( opts.c, transactionDBOpts.c, cName, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } return &TransactionDB{ name: name, c: db, opts: opts, transactionDBOpts: transactionDBOpts, }, nil }
[ "func", "OpenTransactionDb", "(", "opts", "*", "Options", ",", "transactionDBOpts", "*", "TransactionDBOptions", ",", "name", "string", ",", ")", "(", "*", "TransactionDB", ",", "error", ")", "{", "var", "(", "cErr", "*", "C", ".", "char", "\n", "cName", ...
// OpenTransactionDb opens a database with the specified options.
[ "OpenTransactionDb", "opens", "a", "database", "with", "the", "specified", "options", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/transactiondb.go#L20-L42
train
tecbot/gorocksdb
transactiondb.go
TransactionBegin
func (db *TransactionDB) TransactionBegin( opts *WriteOptions, transactionOpts *TransactionOptions, oldTransaction *Transaction, ) *Transaction { if oldTransaction != nil { return NewNativeTransaction(C.rocksdb_transaction_begin( db.c, opts.c, transactionOpts.c, oldTransaction.c, )) } return NewNativeTransaction(C.rocksdb_transaction_begin( db.c, opts.c, transactionOpts.c, nil)) }
go
func (db *TransactionDB) TransactionBegin( opts *WriteOptions, transactionOpts *TransactionOptions, oldTransaction *Transaction, ) *Transaction { if oldTransaction != nil { return NewNativeTransaction(C.rocksdb_transaction_begin( db.c, opts.c, transactionOpts.c, oldTransaction.c, )) } return NewNativeTransaction(C.rocksdb_transaction_begin( db.c, opts.c, transactionOpts.c, nil)) }
[ "func", "(", "db", "*", "TransactionDB", ")", "TransactionBegin", "(", "opts", "*", "WriteOptions", ",", "transactionOpts", "*", "TransactionOptions", ",", "oldTransaction", "*", "Transaction", ",", ")", "*", "Transaction", "{", "if", "oldTransaction", "!=", "ni...
// TransactionBegin begins a new transaction // with the WriteOptions and TransactionOptions given.
[ "TransactionBegin", "begins", "a", "new", "transaction", "with", "the", "WriteOptions", "and", "TransactionOptions", "given", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/transactiondb.go#L57-L73
train
tecbot/gorocksdb
transactiondb.go
NewCheckpoint
func (db *TransactionDB) NewCheckpoint() (*Checkpoint, error) { var ( cErr *C.char ) cCheckpoint := C.rocksdb_transactiondb_checkpoint_object_create( db.c, &cErr, ) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } return NewNativeCheckpoint(cCheckpoint), nil }
go
func (db *TransactionDB) NewCheckpoint() (*Checkpoint, error) { var ( cErr *C.char ) cCheckpoint := C.rocksdb_transactiondb_checkpoint_object_create( db.c, &cErr, ) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } return NewNativeCheckpoint(cCheckpoint), nil }
[ "func", "(", "db", "*", "TransactionDB", ")", "NewCheckpoint", "(", ")", "(", "*", "Checkpoint", ",", "error", ")", "{", "var", "(", "cErr", "*", "C", ".", "char", "\n", ")", "\n", "cCheckpoint", ":=", "C", ".", "rocksdb_transactiondb_checkpoint_object_cre...
// NewCheckpoint creates a new Checkpoint for this db.
[ "NewCheckpoint", "creates", "a", "new", "Checkpoint", "for", "this", "db", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/transactiondb.go#L124-L137
train
tecbot/gorocksdb
transactiondb.go
Close
func (transactionDB *TransactionDB) Close() { C.rocksdb_transactiondb_close(transactionDB.c) transactionDB.c = nil }
go
func (transactionDB *TransactionDB) Close() { C.rocksdb_transactiondb_close(transactionDB.c) transactionDB.c = nil }
[ "func", "(", "transactionDB", "*", "TransactionDB", ")", "Close", "(", ")", "{", "C", ".", "rocksdb_transactiondb_close", "(", "transactionDB", ".", "c", ")", "\n", "transactionDB", ".", "c", "=", "nil", "\n", "}" ]
// Close closes the database.
[ "Close", "closes", "the", "database", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/transactiondb.go#L140-L143
train
tecbot/gorocksdb
options_transaction.go
SetExpiration
func (opts *TransactionOptions) SetExpiration(expiration int64) { C.rocksdb_transaction_options_set_expiration(opts.c, C.int64_t(expiration)) }
go
func (opts *TransactionOptions) SetExpiration(expiration int64) { C.rocksdb_transaction_options_set_expiration(opts.c, C.int64_t(expiration)) }
[ "func", "(", "opts", "*", "TransactionOptions", ")", "SetExpiration", "(", "expiration", "int64", ")", "{", "C", ".", "rocksdb_transaction_options_set_expiration", "(", "opts", ".", "c", ",", "C", ".", "int64_t", "(", "expiration", ")", ")", "\n", "}" ]
// SetExpiration sets the Expiration duration in milliseconds. // If non-negative, transactions that last longer than this many milliseconds will fail to commit. // If not set, a forgotten transaction that is never committed, rolled back, or deleted // will never relinquish any locks it holds. This could prevent keys from // being written by other writers.
[ "SetExpiration", "sets", "the", "Expiration", "duration", "in", "milliseconds", ".", "If", "non", "-", "negative", "transactions", "that", "last", "longer", "than", "this", "many", "milliseconds", "will", "fail", "to", "commit", ".", "If", "not", "set", "a", ...
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/options_transaction.go#L48-L50
train
tecbot/gorocksdb
options_transaction.go
SetDeadlockDetectDepth
func (opts *TransactionOptions) SetDeadlockDetectDepth(depth int64) { C.rocksdb_transaction_options_set_deadlock_detect_depth(opts.c, C.int64_t(depth)) }
go
func (opts *TransactionOptions) SetDeadlockDetectDepth(depth int64) { C.rocksdb_transaction_options_set_deadlock_detect_depth(opts.c, C.int64_t(depth)) }
[ "func", "(", "opts", "*", "TransactionOptions", ")", "SetDeadlockDetectDepth", "(", "depth", "int64", ")", "{", "C", ".", "rocksdb_transaction_options_set_deadlock_detect_depth", "(", "opts", ".", "c", ",", "C", ".", "int64_t", "(", "depth", ")", ")", "\n", "}...
// SetDeadlockDetectDepth sets the number of traversals to make during deadlock detection.
[ "SetDeadlockDetectDepth", "sets", "the", "number", "of", "traversals", "to", "make", "during", "deadlock", "detection", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/options_transaction.go#L53-L55
train
tecbot/gorocksdb
options_transaction.go
SetMaxWriteBatchSize
func (opts *TransactionOptions) SetMaxWriteBatchSize(size uint64) { C.rocksdb_transaction_options_set_max_write_batch_size(opts.c, C.size_t(size)) }
go
func (opts *TransactionOptions) SetMaxWriteBatchSize(size uint64) { C.rocksdb_transaction_options_set_max_write_batch_size(opts.c, C.size_t(size)) }
[ "func", "(", "opts", "*", "TransactionOptions", ")", "SetMaxWriteBatchSize", "(", "size", "uint64", ")", "{", "C", ".", "rocksdb_transaction_options_set_max_write_batch_size", "(", "opts", ".", "c", ",", "C", ".", "size_t", "(", "size", ")", ")", "\n", "}" ]
// SetMaxWriteBatchSize sets the maximum number of bytes used for the write batch. 0 means no limit.
[ "SetMaxWriteBatchSize", "sets", "the", "maximum", "number", "of", "bytes", "used", "for", "the", "write", "batch", ".", "0", "means", "no", "limit", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/options_transaction.go#L58-L60
train
tecbot/gorocksdb
options_transaction.go
Destroy
func (opts *TransactionOptions) Destroy() { C.rocksdb_transaction_options_destroy(opts.c) opts.c = nil }
go
func (opts *TransactionOptions) Destroy() { C.rocksdb_transaction_options_destroy(opts.c) opts.c = nil }
[ "func", "(", "opts", "*", "TransactionOptions", ")", "Destroy", "(", ")", "{", "C", ".", "rocksdb_transaction_options_destroy", "(", "opts", ".", "c", ")", "\n", "opts", ".", "c", "=", "nil", "\n", "}" ]
// Destroy deallocates the TransactionOptions object.
[ "Destroy", "deallocates", "the", "TransactionOptions", "object", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/options_transaction.go#L63-L66
train
prometheus/procfs
proc.go
Self
func (fs FS) Self() (Proc, error) { p, err := os.Readlink(fs.Path("self")) if err != nil { return Proc{}, err } pid, err := strconv.Atoi(strings.Replace(p, string(fs), "", -1)) if err != nil { return Proc{}, err } return fs.NewProc(pid) }
go
func (fs FS) Self() (Proc, error) { p, err := os.Readlink(fs.Path("self")) if err != nil { return Proc{}, err } pid, err := strconv.Atoi(strings.Replace(p, string(fs), "", -1)) if err != nil { return Proc{}, err } return fs.NewProc(pid) }
[ "func", "(", "fs", "FS", ")", "Self", "(", ")", "(", "Proc", ",", "error", ")", "{", "p", ",", "err", ":=", "os", ".", "Readlink", "(", "fs", ".", "Path", "(", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Proc", "{"...
// Self returns a process for the current process.
[ "Self", "returns", "a", "process", "for", "the", "current", "process", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/proc.go#L68-L78
train
prometheus/procfs
proc.go
NewProc
func (fs FS) NewProc(pid int) (Proc, error) { if _, err := os.Stat(fs.Path(strconv.Itoa(pid))); err != nil { return Proc{}, err } return Proc{PID: pid, fs: fs}, nil }
go
func (fs FS) NewProc(pid int) (Proc, error) { if _, err := os.Stat(fs.Path(strconv.Itoa(pid))); err != nil { return Proc{}, err } return Proc{PID: pid, fs: fs}, nil }
[ "func", "(", "fs", "FS", ")", "NewProc", "(", "pid", "int", ")", "(", "Proc", ",", "error", ")", "{", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "fs", ".", "Path", "(", "strconv", ".", "Itoa", "(", "pid", ")", ")", ")", ";", "err"...
// NewProc returns a process for the given pid.
[ "NewProc", "returns", "a", "process", "for", "the", "given", "pid", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/proc.go#L81-L86
train
prometheus/procfs
proc.go
AllProcs
func (fs FS) AllProcs() (Procs, error) { d, err := os.Open(fs.Path()) if err != nil { return Procs{}, err } defer d.Close() names, err := d.Readdirnames(-1) if err != nil { return Procs{}, fmt.Errorf("could not read %s: %s", d.Name(), err) } p := Procs{} for _, n := range names { pid, err := strconv.ParseInt(n, 10, 64) if err != nil { continue } p = append(p, Proc{PID: int(pid), fs: fs}) } return p, nil }
go
func (fs FS) AllProcs() (Procs, error) { d, err := os.Open(fs.Path()) if err != nil { return Procs{}, err } defer d.Close() names, err := d.Readdirnames(-1) if err != nil { return Procs{}, fmt.Errorf("could not read %s: %s", d.Name(), err) } p := Procs{} for _, n := range names { pid, err := strconv.ParseInt(n, 10, 64) if err != nil { continue } p = append(p, Proc{PID: int(pid), fs: fs}) } return p, nil }
[ "func", "(", "fs", "FS", ")", "AllProcs", "(", ")", "(", "Procs", ",", "error", ")", "{", "d", ",", "err", ":=", "os", ".", "Open", "(", "fs", ".", "Path", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Procs", "{", "}", ","...
// AllProcs returns a list of all currently available processes.
[ "AllProcs", "returns", "a", "list", "of", "all", "currently", "available", "processes", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/proc.go#L89-L111
train
prometheus/procfs
proc.go
CmdLine
func (p Proc) CmdLine() ([]string, error) { f, err := os.Open(p.path("cmdline")) if err != nil { return nil, err } defer f.Close() data, err := ioutil.ReadAll(f) if err != nil { return nil, err } if len(data) < 1 { return []string{}, nil } return strings.Split(string(bytes.TrimRight(data, string("\x00"))), string(byte(0))), nil }
go
func (p Proc) CmdLine() ([]string, error) { f, err := os.Open(p.path("cmdline")) if err != nil { return nil, err } defer f.Close() data, err := ioutil.ReadAll(f) if err != nil { return nil, err } if len(data) < 1 { return []string{}, nil } return strings.Split(string(bytes.TrimRight(data, string("\x00"))), string(byte(0))), nil }
[ "func", "(", "p", "Proc", ")", "CmdLine", "(", ")", "(", "[", "]", "string", ",", "error", ")", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "p", ".", "path", "(", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", ...
// CmdLine returns the command line of a process.
[ "CmdLine", "returns", "the", "command", "line", "of", "a", "process", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/proc.go#L114-L131
train
prometheus/procfs
proc.go
Comm
func (p Proc) Comm() (string, error) { f, err := os.Open(p.path("comm")) if err != nil { return "", err } defer f.Close() data, err := ioutil.ReadAll(f) if err != nil { return "", err } return strings.TrimSpace(string(data)), nil }
go
func (p Proc) Comm() (string, error) { f, err := os.Open(p.path("comm")) if err != nil { return "", err } defer f.Close() data, err := ioutil.ReadAll(f) if err != nil { return "", err } return strings.TrimSpace(string(data)), nil }
[ "func", "(", "p", "Proc", ")", "Comm", "(", ")", "(", "string", ",", "error", ")", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "p", ".", "path", "(", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ...
// Comm returns the command name of a process.
[ "Comm", "returns", "the", "command", "name", "of", "a", "process", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/proc.go#L134-L147
train
prometheus/procfs
proc.go
Executable
func (p Proc) Executable() (string, error) { exe, err := os.Readlink(p.path("exe")) if os.IsNotExist(err) { return "", nil } return exe, err }
go
func (p Proc) Executable() (string, error) { exe, err := os.Readlink(p.path("exe")) if os.IsNotExist(err) { return "", nil } return exe, err }
[ "func", "(", "p", "Proc", ")", "Executable", "(", ")", "(", "string", ",", "error", ")", "{", "exe", ",", "err", ":=", "os", ".", "Readlink", "(", "p", ".", "path", "(", "\"", "\"", ")", ")", "\n", "if", "os", ".", "IsNotExist", "(", "err", "...
// Executable returns the absolute path of the executable command of a process.
[ "Executable", "returns", "the", "absolute", "path", "of", "the", "executable", "command", "of", "a", "process", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/proc.go#L150-L157
train
prometheus/procfs
proc.go
Cwd
func (p Proc) Cwd() (string, error) { wd, err := os.Readlink(p.path("cwd")) if os.IsNotExist(err) { return "", nil } return wd, err }
go
func (p Proc) Cwd() (string, error) { wd, err := os.Readlink(p.path("cwd")) if os.IsNotExist(err) { return "", nil } return wd, err }
[ "func", "(", "p", "Proc", ")", "Cwd", "(", ")", "(", "string", ",", "error", ")", "{", "wd", ",", "err", ":=", "os", ".", "Readlink", "(", "p", ".", "path", "(", "\"", "\"", ")", ")", "\n", "if", "os", ".", "IsNotExist", "(", "err", ")", "{...
// Cwd returns the absolute path to the current working directory of the process.
[ "Cwd", "returns", "the", "absolute", "path", "to", "the", "current", "working", "directory", "of", "the", "process", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/proc.go#L160-L167
train
prometheus/procfs
proc.go
FileDescriptors
func (p Proc) FileDescriptors() ([]uintptr, error) { names, err := p.fileDescriptors() if err != nil { return nil, err } fds := make([]uintptr, len(names)) for i, n := range names { fd, err := strconv.ParseInt(n, 10, 32) if err != nil { return nil, fmt.Errorf("could not parse fd %s: %s", n, err) } fds[i] = uintptr(fd) } return fds, nil }
go
func (p Proc) FileDescriptors() ([]uintptr, error) { names, err := p.fileDescriptors() if err != nil { return nil, err } fds := make([]uintptr, len(names)) for i, n := range names { fd, err := strconv.ParseInt(n, 10, 32) if err != nil { return nil, fmt.Errorf("could not parse fd %s: %s", n, err) } fds[i] = uintptr(fd) } return fds, nil }
[ "func", "(", "p", "Proc", ")", "FileDescriptors", "(", ")", "(", "[", "]", "uintptr", ",", "error", ")", "{", "names", ",", "err", ":=", "p", ".", "fileDescriptors", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n"...
// FileDescriptors returns the currently open file descriptors of a process.
[ "FileDescriptors", "returns", "the", "currently", "open", "file", "descriptors", "of", "a", "process", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/proc.go#L180-L196
train
prometheus/procfs
proc.go
FileDescriptorsLen
func (p Proc) FileDescriptorsLen() (int, error) { fds, err := p.fileDescriptors() if err != nil { return 0, err } return len(fds), nil }
go
func (p Proc) FileDescriptorsLen() (int, error) { fds, err := p.fileDescriptors() if err != nil { return 0, err } return len(fds), nil }
[ "func", "(", "p", "Proc", ")", "FileDescriptorsLen", "(", ")", "(", "int", ",", "error", ")", "{", "fds", ",", "err", ":=", "p", ".", "fileDescriptors", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", ...
// FileDescriptorsLen returns the number of currently open file descriptors of // a process.
[ "FileDescriptorsLen", "returns", "the", "number", "of", "currently", "open", "file", "descriptors", "of", "a", "process", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/proc.go#L220-L227
train
prometheus/procfs
proc.go
MountStats
func (p Proc) MountStats() ([]*Mount, error) { f, err := os.Open(p.path("mountstats")) if err != nil { return nil, err } defer f.Close() return parseMountStats(f) }
go
func (p Proc) MountStats() ([]*Mount, error) { f, err := os.Open(p.path("mountstats")) if err != nil { return nil, err } defer f.Close() return parseMountStats(f) }
[ "func", "(", "p", "Proc", ")", "MountStats", "(", ")", "(", "[", "]", "*", "Mount", ",", "error", ")", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "p", ".", "path", "(", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "...
// MountStats retrieves statistics and configuration for mount points in a // process's namespace.
[ "MountStats", "retrieves", "statistics", "and", "configuration", "for", "mount", "points", "in", "a", "process", "s", "namespace", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/proc.go#L231-L239
train
prometheus/procfs
proc_limits.go
NewLimits
func (p Proc) NewLimits() (ProcLimits, error) { f, err := os.Open(p.path("limits")) if err != nil { return ProcLimits{}, err } defer f.Close() var ( l = ProcLimits{} s = bufio.NewScanner(f) ) for s.Scan() { fields := limitsDelimiter.Split(s.Text(), limitsFields) if len(fields) != limitsFields { return ProcLimits{}, fmt.Errorf( "couldn't parse %s line %s", f.Name(), s.Text()) } switch fields[0] { case "Max cpu time": l.CPUTime, err = parseInt(fields[1]) case "Max file size": l.FileSize, err = parseInt(fields[1]) case "Max data size": l.DataSize, err = parseInt(fields[1]) case "Max stack size": l.StackSize, err = parseInt(fields[1]) case "Max core file size": l.CoreFileSize, err = parseInt(fields[1]) case "Max resident set": l.ResidentSet, err = parseInt(fields[1]) case "Max processes": l.Processes, err = parseInt(fields[1]) case "Max open files": l.OpenFiles, err = parseInt(fields[1]) case "Max locked memory": l.LockedMemory, err = parseInt(fields[1]) case "Max address space": l.AddressSpace, err = parseInt(fields[1]) case "Max file locks": l.FileLocks, err = parseInt(fields[1]) case "Max pending signals": l.PendingSignals, err = parseInt(fields[1]) case "Max msgqueue size": l.MsqqueueSize, err = parseInt(fields[1]) case "Max nice priority": l.NicePriority, err = parseInt(fields[1]) case "Max realtime priority": l.RealtimePriority, err = parseInt(fields[1]) case "Max realtime timeout": l.RealtimeTimeout, err = parseInt(fields[1]) } if err != nil { return ProcLimits{}, err } } return l, s.Err() }
go
func (p Proc) NewLimits() (ProcLimits, error) { f, err := os.Open(p.path("limits")) if err != nil { return ProcLimits{}, err } defer f.Close() var ( l = ProcLimits{} s = bufio.NewScanner(f) ) for s.Scan() { fields := limitsDelimiter.Split(s.Text(), limitsFields) if len(fields) != limitsFields { return ProcLimits{}, fmt.Errorf( "couldn't parse %s line %s", f.Name(), s.Text()) } switch fields[0] { case "Max cpu time": l.CPUTime, err = parseInt(fields[1]) case "Max file size": l.FileSize, err = parseInt(fields[1]) case "Max data size": l.DataSize, err = parseInt(fields[1]) case "Max stack size": l.StackSize, err = parseInt(fields[1]) case "Max core file size": l.CoreFileSize, err = parseInt(fields[1]) case "Max resident set": l.ResidentSet, err = parseInt(fields[1]) case "Max processes": l.Processes, err = parseInt(fields[1]) case "Max open files": l.OpenFiles, err = parseInt(fields[1]) case "Max locked memory": l.LockedMemory, err = parseInt(fields[1]) case "Max address space": l.AddressSpace, err = parseInt(fields[1]) case "Max file locks": l.FileLocks, err = parseInt(fields[1]) case "Max pending signals": l.PendingSignals, err = parseInt(fields[1]) case "Max msgqueue size": l.MsqqueueSize, err = parseInt(fields[1]) case "Max nice priority": l.NicePriority, err = parseInt(fields[1]) case "Max realtime priority": l.RealtimePriority, err = parseInt(fields[1]) case "Max realtime timeout": l.RealtimeTimeout, err = parseInt(fields[1]) } if err != nil { return ProcLimits{}, err } } return l, s.Err() }
[ "func", "(", "p", "Proc", ")", "NewLimits", "(", ")", "(", "ProcLimits", ",", "error", ")", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "p", ".", "path", "(", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ProcL...
// NewLimits returns the current soft limits of the process.
[ "NewLimits", "returns", "the", "current", "soft", "limits", "of", "the", "process", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/proc_limits.go#L81-L139
train
prometheus/procfs
mountstats.go
parseMountStatsNFS
func parseMountStatsNFS(s *bufio.Scanner, statVersion string) (*MountStatsNFS, error) { // Field indicators for parsing specific types of data const ( fieldOpts = "opts:" fieldAge = "age:" fieldBytes = "bytes:" fieldEvents = "events:" fieldPerOpStats = "per-op" fieldTransport = "xprt:" ) stats := &MountStatsNFS{ StatVersion: statVersion, } for s.Scan() { ss := strings.Fields(string(s.Bytes())) if len(ss) == 0 { break } if len(ss) < 2 { return nil, fmt.Errorf("not enough information for NFS stats: %v", ss) } switch ss[0] { case fieldOpts: for _, opt := range strings.Split(ss[1], ",") { split := strings.Split(opt, "=") if len(split) == 2 && split[0] == "mountaddr" { stats.MountAddress = split[1] } } case fieldAge: // Age integer is in seconds d, err := time.ParseDuration(ss[1] + "s") if err != nil { return nil, err } stats.Age = d case fieldBytes: bstats, err := parseNFSBytesStats(ss[1:]) if err != nil { return nil, err } stats.Bytes = *bstats case fieldEvents: estats, err := parseNFSEventsStats(ss[1:]) if err != nil { return nil, err } stats.Events = *estats case fieldTransport: if len(ss) < 3 { return nil, fmt.Errorf("not enough information for NFS transport stats: %v", ss) } tstats, err := parseNFSTransportStats(ss[1:], statVersion) if err != nil { return nil, err } stats.Transport = *tstats } // When encountering "per-operation statistics", we must break this // loop and parse them separately to ensure we can terminate parsing // before reaching another device entry; hence why this 'if' statement // is not just another switch case if ss[0] == fieldPerOpStats { break } } if err := s.Err(); err != nil { return nil, err } // NFS per-operation stats appear last before the next device entry perOpStats, err := parseNFSOperationStats(s) if err != nil { return nil, err } stats.Operations = perOpStats return stats, nil }
go
func parseMountStatsNFS(s *bufio.Scanner, statVersion string) (*MountStatsNFS, error) { // Field indicators for parsing specific types of data const ( fieldOpts = "opts:" fieldAge = "age:" fieldBytes = "bytes:" fieldEvents = "events:" fieldPerOpStats = "per-op" fieldTransport = "xprt:" ) stats := &MountStatsNFS{ StatVersion: statVersion, } for s.Scan() { ss := strings.Fields(string(s.Bytes())) if len(ss) == 0 { break } if len(ss) < 2 { return nil, fmt.Errorf("not enough information for NFS stats: %v", ss) } switch ss[0] { case fieldOpts: for _, opt := range strings.Split(ss[1], ",") { split := strings.Split(opt, "=") if len(split) == 2 && split[0] == "mountaddr" { stats.MountAddress = split[1] } } case fieldAge: // Age integer is in seconds d, err := time.ParseDuration(ss[1] + "s") if err != nil { return nil, err } stats.Age = d case fieldBytes: bstats, err := parseNFSBytesStats(ss[1:]) if err != nil { return nil, err } stats.Bytes = *bstats case fieldEvents: estats, err := parseNFSEventsStats(ss[1:]) if err != nil { return nil, err } stats.Events = *estats case fieldTransport: if len(ss) < 3 { return nil, fmt.Errorf("not enough information for NFS transport stats: %v", ss) } tstats, err := parseNFSTransportStats(ss[1:], statVersion) if err != nil { return nil, err } stats.Transport = *tstats } // When encountering "per-operation statistics", we must break this // loop and parse them separately to ensure we can terminate parsing // before reaching another device entry; hence why this 'if' statement // is not just another switch case if ss[0] == fieldPerOpStats { break } } if err := s.Err(); err != nil { return nil, err } // NFS per-operation stats appear last before the next device entry perOpStats, err := parseNFSOperationStats(s) if err != nil { return nil, err } stats.Operations = perOpStats return stats, nil }
[ "func", "parseMountStatsNFS", "(", "s", "*", "bufio", ".", "Scanner", ",", "statVersion", "string", ")", "(", "*", "MountStatsNFS", ",", "error", ")", "{", "// Field indicators for parsing specific types of data", "const", "(", "fieldOpts", "=", "\"", "\"", "\n", ...
// parseMountStatsNFS parses a MountStatsNFS by scanning additional information // related to NFS statistics.
[ "parseMountStatsNFS", "parses", "a", "MountStatsNFS", "by", "scanning", "additional", "information", "related", "to", "NFS", "statistics", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/mountstats.go#L319-L408
train
prometheus/procfs
mountstats.go
parseNFSBytesStats
func parseNFSBytesStats(ss []string) (*NFSBytesStats, error) { if len(ss) != fieldBytesLen { return nil, fmt.Errorf("invalid NFS bytes stats: %v", ss) } ns := make([]uint64, 0, fieldBytesLen) for _, s := range ss { n, err := strconv.ParseUint(s, 10, 64) if err != nil { return nil, err } ns = append(ns, n) } return &NFSBytesStats{ Read: ns[0], Write: ns[1], DirectRead: ns[2], DirectWrite: ns[3], ReadTotal: ns[4], WriteTotal: ns[5], ReadPages: ns[6], WritePages: ns[7], }, nil }
go
func parseNFSBytesStats(ss []string) (*NFSBytesStats, error) { if len(ss) != fieldBytesLen { return nil, fmt.Errorf("invalid NFS bytes stats: %v", ss) } ns := make([]uint64, 0, fieldBytesLen) for _, s := range ss { n, err := strconv.ParseUint(s, 10, 64) if err != nil { return nil, err } ns = append(ns, n) } return &NFSBytesStats{ Read: ns[0], Write: ns[1], DirectRead: ns[2], DirectWrite: ns[3], ReadTotal: ns[4], WriteTotal: ns[5], ReadPages: ns[6], WritePages: ns[7], }, nil }
[ "func", "parseNFSBytesStats", "(", "ss", "[", "]", "string", ")", "(", "*", "NFSBytesStats", ",", "error", ")", "{", "if", "len", "(", "ss", ")", "!=", "fieldBytesLen", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ss", ")...
// parseNFSBytesStats parses a NFSBytesStats line using an input set of // integer fields.
[ "parseNFSBytesStats", "parses", "a", "NFSBytesStats", "line", "using", "an", "input", "set", "of", "integer", "fields", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/mountstats.go#L412-L437
train
prometheus/procfs
mountstats.go
parseNFSEventsStats
func parseNFSEventsStats(ss []string) (*NFSEventsStats, error) { if len(ss) != fieldEventsLen { return nil, fmt.Errorf("invalid NFS events stats: %v", ss) } ns := make([]uint64, 0, fieldEventsLen) for _, s := range ss { n, err := strconv.ParseUint(s, 10, 64) if err != nil { return nil, err } ns = append(ns, n) } return &NFSEventsStats{ InodeRevalidate: ns[0], DnodeRevalidate: ns[1], DataInvalidate: ns[2], AttributeInvalidate: ns[3], VFSOpen: ns[4], VFSLookup: ns[5], VFSAccess: ns[6], VFSUpdatePage: ns[7], VFSReadPage: ns[8], VFSReadPages: ns[9], VFSWritePage: ns[10], VFSWritePages: ns[11], VFSGetdents: ns[12], VFSSetattr: ns[13], VFSFlush: ns[14], VFSFsync: ns[15], VFSLock: ns[16], VFSFileRelease: ns[17], CongestionWait: ns[18], Truncation: ns[19], WriteExtension: ns[20], SillyRename: ns[21], ShortRead: ns[22], ShortWrite: ns[23], JukeboxDelay: ns[24], PNFSRead: ns[25], PNFSWrite: ns[26], }, nil }
go
func parseNFSEventsStats(ss []string) (*NFSEventsStats, error) { if len(ss) != fieldEventsLen { return nil, fmt.Errorf("invalid NFS events stats: %v", ss) } ns := make([]uint64, 0, fieldEventsLen) for _, s := range ss { n, err := strconv.ParseUint(s, 10, 64) if err != nil { return nil, err } ns = append(ns, n) } return &NFSEventsStats{ InodeRevalidate: ns[0], DnodeRevalidate: ns[1], DataInvalidate: ns[2], AttributeInvalidate: ns[3], VFSOpen: ns[4], VFSLookup: ns[5], VFSAccess: ns[6], VFSUpdatePage: ns[7], VFSReadPage: ns[8], VFSReadPages: ns[9], VFSWritePage: ns[10], VFSWritePages: ns[11], VFSGetdents: ns[12], VFSSetattr: ns[13], VFSFlush: ns[14], VFSFsync: ns[15], VFSLock: ns[16], VFSFileRelease: ns[17], CongestionWait: ns[18], Truncation: ns[19], WriteExtension: ns[20], SillyRename: ns[21], ShortRead: ns[22], ShortWrite: ns[23], JukeboxDelay: ns[24], PNFSRead: ns[25], PNFSWrite: ns[26], }, nil }
[ "func", "parseNFSEventsStats", "(", "ss", "[", "]", "string", ")", "(", "*", "NFSEventsStats", ",", "error", ")", "{", "if", "len", "(", "ss", ")", "!=", "fieldEventsLen", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ss", ...
// parseNFSEventsStats parses a NFSEventsStats line using an input set of // integer fields.
[ "parseNFSEventsStats", "parses", "a", "NFSEventsStats", "line", "using", "an", "input", "set", "of", "integer", "fields", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/mountstats.go#L441-L485
train
prometheus/procfs
mountstats.go
parseNFSOperationStats
func parseNFSOperationStats(s *bufio.Scanner) ([]NFSOperationStats, error) { const ( // Number of expected fields in each per-operation statistics set numFields = 9 ) var ops []NFSOperationStats for s.Scan() { ss := strings.Fields(string(s.Bytes())) if len(ss) == 0 { // Must break when reading a blank line after per-operation stats to // enable top-level function to parse the next device entry break } if len(ss) != numFields { return nil, fmt.Errorf("invalid NFS per-operations stats: %v", ss) } // Skip string operation name for integers ns := make([]uint64, 0, numFields-1) for _, st := range ss[1:] { n, err := strconv.ParseUint(st, 10, 64) if err != nil { return nil, err } ns = append(ns, n) } ops = append(ops, NFSOperationStats{ Operation: strings.TrimSuffix(ss[0], ":"), Requests: ns[0], Transmissions: ns[1], MajorTimeouts: ns[2], BytesSent: ns[3], BytesReceived: ns[4], CumulativeQueueTime: time.Duration(ns[5]) * time.Millisecond, CumulativeTotalResponseTime: time.Duration(ns[6]) * time.Millisecond, CumulativeTotalRequestTime: time.Duration(ns[7]) * time.Millisecond, }) } return ops, s.Err() }
go
func parseNFSOperationStats(s *bufio.Scanner) ([]NFSOperationStats, error) { const ( // Number of expected fields in each per-operation statistics set numFields = 9 ) var ops []NFSOperationStats for s.Scan() { ss := strings.Fields(string(s.Bytes())) if len(ss) == 0 { // Must break when reading a blank line after per-operation stats to // enable top-level function to parse the next device entry break } if len(ss) != numFields { return nil, fmt.Errorf("invalid NFS per-operations stats: %v", ss) } // Skip string operation name for integers ns := make([]uint64, 0, numFields-1) for _, st := range ss[1:] { n, err := strconv.ParseUint(st, 10, 64) if err != nil { return nil, err } ns = append(ns, n) } ops = append(ops, NFSOperationStats{ Operation: strings.TrimSuffix(ss[0], ":"), Requests: ns[0], Transmissions: ns[1], MajorTimeouts: ns[2], BytesSent: ns[3], BytesReceived: ns[4], CumulativeQueueTime: time.Duration(ns[5]) * time.Millisecond, CumulativeTotalResponseTime: time.Duration(ns[6]) * time.Millisecond, CumulativeTotalRequestTime: time.Duration(ns[7]) * time.Millisecond, }) } return ops, s.Err() }
[ "func", "parseNFSOperationStats", "(", "s", "*", "bufio", ".", "Scanner", ")", "(", "[", "]", "NFSOperationStats", ",", "error", ")", "{", "const", "(", "// Number of expected fields in each per-operation statistics set", "numFields", "=", "9", "\n", ")", "\n\n", ...
// parseNFSOperationStats parses a slice of NFSOperationStats by scanning // additional information about per-operation statistics until an empty // line is reached.
[ "parseNFSOperationStats", "parses", "a", "slice", "of", "NFSOperationStats", "by", "scanning", "additional", "information", "about", "per", "-", "operation", "statistics", "until", "an", "empty", "line", "is", "reached", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/mountstats.go#L490-L535
train
prometheus/procfs
mountstats.go
parseNFSTransportStats
func parseNFSTransportStats(ss []string, statVersion string) (*NFSTransportStats, error) { // Extract the protocol field. It is the only string value in the line protocol := ss[0] ss = ss[1:] switch statVersion { case statVersion10: var expectedLength int if protocol == "tcp" { expectedLength = fieldTransport10TCPLen } else if protocol == "udp" { expectedLength = fieldTransport10UDPLen } else { return nil, fmt.Errorf("invalid NFS protocol \"%s\" in stats 1.0 statement: %v", protocol, ss) } if len(ss) != expectedLength { return nil, fmt.Errorf("invalid NFS transport stats 1.0 statement: %v", ss) } case statVersion11: var expectedLength int if protocol == "tcp" { expectedLength = fieldTransport11TCPLen } else if protocol == "udp" { expectedLength = fieldTransport11UDPLen } else { return nil, fmt.Errorf("invalid NFS protocol \"%s\" in stats 1.1 statement: %v", protocol, ss) } if len(ss) != expectedLength { return nil, fmt.Errorf("invalid NFS transport stats 1.1 statement: %v", ss) } default: return nil, fmt.Errorf("unrecognized NFS transport stats version: %q", statVersion) } // Allocate enough for v1.1 stats since zero value for v1.1 stats will be okay // in a v1.0 response. Since the stat length is bigger for TCP stats, we use // the TCP length here. // // Note: slice length must be set to length of v1.1 stats to avoid a panic when // only v1.0 stats are present. // See: https://github.com/prometheus/node_exporter/issues/571. ns := make([]uint64, fieldTransport11TCPLen) for i, s := range ss { n, err := strconv.ParseUint(s, 10, 64) if err != nil { return nil, err } ns[i] = n } // The fields differ depending on the transport protocol (TCP or UDP) // From https://utcc.utoronto.ca/%7Ecks/space/blog/linux/NFSMountstatsXprt // // For the udp RPC transport there is no connection count, connect idle time, // or idle time (fields #3, #4, and #5); all other fields are the same. So // we set them to 0 here. if protocol == "udp" { ns = append(ns[:2], append(make([]uint64, 3), ns[2:]...)...) } return &NFSTransportStats{ Protocol: protocol, Port: ns[0], Bind: ns[1], Connect: ns[2], ConnectIdleTime: ns[3], IdleTime: time.Duration(ns[4]) * time.Second, Sends: ns[5], Receives: ns[6], BadTransactionIDs: ns[7], CumulativeActiveRequests: ns[8], CumulativeBacklog: ns[9], MaximumRPCSlotsUsed: ns[10], CumulativeSendingQueue: ns[11], CumulativePendingQueue: ns[12], }, nil }
go
func parseNFSTransportStats(ss []string, statVersion string) (*NFSTransportStats, error) { // Extract the protocol field. It is the only string value in the line protocol := ss[0] ss = ss[1:] switch statVersion { case statVersion10: var expectedLength int if protocol == "tcp" { expectedLength = fieldTransport10TCPLen } else if protocol == "udp" { expectedLength = fieldTransport10UDPLen } else { return nil, fmt.Errorf("invalid NFS protocol \"%s\" in stats 1.0 statement: %v", protocol, ss) } if len(ss) != expectedLength { return nil, fmt.Errorf("invalid NFS transport stats 1.0 statement: %v", ss) } case statVersion11: var expectedLength int if protocol == "tcp" { expectedLength = fieldTransport11TCPLen } else if protocol == "udp" { expectedLength = fieldTransport11UDPLen } else { return nil, fmt.Errorf("invalid NFS protocol \"%s\" in stats 1.1 statement: %v", protocol, ss) } if len(ss) != expectedLength { return nil, fmt.Errorf("invalid NFS transport stats 1.1 statement: %v", ss) } default: return nil, fmt.Errorf("unrecognized NFS transport stats version: %q", statVersion) } // Allocate enough for v1.1 stats since zero value for v1.1 stats will be okay // in a v1.0 response. Since the stat length is bigger for TCP stats, we use // the TCP length here. // // Note: slice length must be set to length of v1.1 stats to avoid a panic when // only v1.0 stats are present. // See: https://github.com/prometheus/node_exporter/issues/571. ns := make([]uint64, fieldTransport11TCPLen) for i, s := range ss { n, err := strconv.ParseUint(s, 10, 64) if err != nil { return nil, err } ns[i] = n } // The fields differ depending on the transport protocol (TCP or UDP) // From https://utcc.utoronto.ca/%7Ecks/space/blog/linux/NFSMountstatsXprt // // For the udp RPC transport there is no connection count, connect idle time, // or idle time (fields #3, #4, and #5); all other fields are the same. So // we set them to 0 here. if protocol == "udp" { ns = append(ns[:2], append(make([]uint64, 3), ns[2:]...)...) } return &NFSTransportStats{ Protocol: protocol, Port: ns[0], Bind: ns[1], Connect: ns[2], ConnectIdleTime: ns[3], IdleTime: time.Duration(ns[4]) * time.Second, Sends: ns[5], Receives: ns[6], BadTransactionIDs: ns[7], CumulativeActiveRequests: ns[8], CumulativeBacklog: ns[9], MaximumRPCSlotsUsed: ns[10], CumulativeSendingQueue: ns[11], CumulativePendingQueue: ns[12], }, nil }
[ "func", "parseNFSTransportStats", "(", "ss", "[", "]", "string", ",", "statVersion", "string", ")", "(", "*", "NFSTransportStats", ",", "error", ")", "{", "// Extract the protocol field. It is the only string value in the line", "protocol", ":=", "ss", "[", "0", "]", ...
// parseNFSTransportStats parses a NFSTransportStats line using an input set of // integer fields matched to a specific stats version.
[ "parseNFSTransportStats", "parses", "a", "NFSTransportStats", "line", "using", "an", "input", "set", "of", "integer", "fields", "matched", "to", "a", "specific", "stats", "version", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/mountstats.go#L539-L616
train
prometheus/procfs
xfrm.go
NewXfrmStat
func NewXfrmStat() (XfrmStat, error) { fs, err := NewFS(DefaultMountPoint) if err != nil { return XfrmStat{}, err } return fs.NewXfrmStat() }
go
func NewXfrmStat() (XfrmStat, error) { fs, err := NewFS(DefaultMountPoint) if err != nil { return XfrmStat{}, err } return fs.NewXfrmStat() }
[ "func", "NewXfrmStat", "(", ")", "(", "XfrmStat", ",", "error", ")", "{", "fs", ",", "err", ":=", "NewFS", "(", "DefaultMountPoint", ")", "\n", "if", "err", "!=", "nil", "{", "return", "XfrmStat", "{", "}", ",", "err", "\n", "}", "\n\n", "return", ...
// NewXfrmStat reads the xfrm_stat statistics.
[ "NewXfrmStat", "reads", "the", "xfrm_stat", "statistics", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/xfrm.go#L89-L96
train
prometheus/procfs
xfrm.go
NewXfrmStat
func (fs FS) NewXfrmStat() (XfrmStat, error) { file, err := os.Open(fs.Path("net/xfrm_stat")) if err != nil { return XfrmStat{}, err } defer file.Close() var ( x = XfrmStat{} s = bufio.NewScanner(file) ) for s.Scan() { fields := strings.Fields(s.Text()) if len(fields) != 2 { return XfrmStat{}, fmt.Errorf( "couldn't parse %s line %s", file.Name(), s.Text()) } name := fields[0] value, err := strconv.Atoi(fields[1]) if err != nil { return XfrmStat{}, err } switch name { case "XfrmInError": x.XfrmInError = value case "XfrmInBufferError": x.XfrmInBufferError = value case "XfrmInHdrError": x.XfrmInHdrError = value case "XfrmInNoStates": x.XfrmInNoStates = value case "XfrmInStateProtoError": x.XfrmInStateProtoError = value case "XfrmInStateModeError": x.XfrmInStateModeError = value case "XfrmInStateSeqError": x.XfrmInStateSeqError = value case "XfrmInStateExpired": x.XfrmInStateExpired = value case "XfrmInStateInvalid": x.XfrmInStateInvalid = value case "XfrmInTmplMismatch": x.XfrmInTmplMismatch = value case "XfrmInNoPols": x.XfrmInNoPols = value case "XfrmInPolBlock": x.XfrmInPolBlock = value case "XfrmInPolError": x.XfrmInPolError = value case "XfrmOutError": x.XfrmOutError = value case "XfrmInStateMismatch": x.XfrmInStateMismatch = value case "XfrmOutBundleGenError": x.XfrmOutBundleGenError = value case "XfrmOutBundleCheckError": x.XfrmOutBundleCheckError = value case "XfrmOutNoStates": x.XfrmOutNoStates = value case "XfrmOutStateProtoError": x.XfrmOutStateProtoError = value case "XfrmOutStateModeError": x.XfrmOutStateModeError = value case "XfrmOutStateSeqError": x.XfrmOutStateSeqError = value case "XfrmOutStateExpired": x.XfrmOutStateExpired = value case "XfrmOutPolBlock": x.XfrmOutPolBlock = value case "XfrmOutPolDead": x.XfrmOutPolDead = value case "XfrmOutPolError": x.XfrmOutPolError = value case "XfrmFwdHdrError": x.XfrmFwdHdrError = value case "XfrmOutStateInvalid": x.XfrmOutStateInvalid = value case "XfrmAcquireError": x.XfrmAcquireError = value } } return x, s.Err() }
go
func (fs FS) NewXfrmStat() (XfrmStat, error) { file, err := os.Open(fs.Path("net/xfrm_stat")) if err != nil { return XfrmStat{}, err } defer file.Close() var ( x = XfrmStat{} s = bufio.NewScanner(file) ) for s.Scan() { fields := strings.Fields(s.Text()) if len(fields) != 2 { return XfrmStat{}, fmt.Errorf( "couldn't parse %s line %s", file.Name(), s.Text()) } name := fields[0] value, err := strconv.Atoi(fields[1]) if err != nil { return XfrmStat{}, err } switch name { case "XfrmInError": x.XfrmInError = value case "XfrmInBufferError": x.XfrmInBufferError = value case "XfrmInHdrError": x.XfrmInHdrError = value case "XfrmInNoStates": x.XfrmInNoStates = value case "XfrmInStateProtoError": x.XfrmInStateProtoError = value case "XfrmInStateModeError": x.XfrmInStateModeError = value case "XfrmInStateSeqError": x.XfrmInStateSeqError = value case "XfrmInStateExpired": x.XfrmInStateExpired = value case "XfrmInStateInvalid": x.XfrmInStateInvalid = value case "XfrmInTmplMismatch": x.XfrmInTmplMismatch = value case "XfrmInNoPols": x.XfrmInNoPols = value case "XfrmInPolBlock": x.XfrmInPolBlock = value case "XfrmInPolError": x.XfrmInPolError = value case "XfrmOutError": x.XfrmOutError = value case "XfrmInStateMismatch": x.XfrmInStateMismatch = value case "XfrmOutBundleGenError": x.XfrmOutBundleGenError = value case "XfrmOutBundleCheckError": x.XfrmOutBundleCheckError = value case "XfrmOutNoStates": x.XfrmOutNoStates = value case "XfrmOutStateProtoError": x.XfrmOutStateProtoError = value case "XfrmOutStateModeError": x.XfrmOutStateModeError = value case "XfrmOutStateSeqError": x.XfrmOutStateSeqError = value case "XfrmOutStateExpired": x.XfrmOutStateExpired = value case "XfrmOutPolBlock": x.XfrmOutPolBlock = value case "XfrmOutPolDead": x.XfrmOutPolDead = value case "XfrmOutPolError": x.XfrmOutPolError = value case "XfrmFwdHdrError": x.XfrmFwdHdrError = value case "XfrmOutStateInvalid": x.XfrmOutStateInvalid = value case "XfrmAcquireError": x.XfrmAcquireError = value } } return x, s.Err() }
[ "func", "(", "fs", "FS", ")", "NewXfrmStat", "(", ")", "(", "XfrmStat", ",", "error", ")", "{", "file", ",", "err", ":=", "os", ".", "Open", "(", "fs", ".", "Path", "(", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Xf...
// NewXfrmStat reads the xfrm_stat statistics from the 'proc' filesystem.
[ "NewXfrmStat", "reads", "the", "xfrm_stat", "statistics", "from", "the", "proc", "filesystem", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/xfrm.go#L99-L187
train
prometheus/procfs
internal/util/parse.go
ParseUint32s
func ParseUint32s(ss []string) ([]uint32, error) { us := make([]uint32, 0, len(ss)) for _, s := range ss { u, err := strconv.ParseUint(s, 10, 32) if err != nil { return nil, err } us = append(us, uint32(u)) } return us, nil }
go
func ParseUint32s(ss []string) ([]uint32, error) { us := make([]uint32, 0, len(ss)) for _, s := range ss { u, err := strconv.ParseUint(s, 10, 32) if err != nil { return nil, err } us = append(us, uint32(u)) } return us, nil }
[ "func", "ParseUint32s", "(", "ss", "[", "]", "string", ")", "(", "[", "]", "uint32", ",", "error", ")", "{", "us", ":=", "make", "(", "[", "]", "uint32", ",", "0", ",", "len", "(", "ss", ")", ")", "\n", "for", "_", ",", "s", ":=", "range", ...
// ParseUint32s parses a slice of strings into a slice of uint32s.
[ "ParseUint32s", "parses", "a", "slice", "of", "strings", "into", "a", "slice", "of", "uint32s", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/internal/util/parse.go#L23-L35
train
prometheus/procfs
internal/util/parse.go
ParseUint64s
func ParseUint64s(ss []string) ([]uint64, error) { us := make([]uint64, 0, len(ss)) for _, s := range ss { u, err := strconv.ParseUint(s, 10, 64) if err != nil { return nil, err } us = append(us, u) } return us, nil }
go
func ParseUint64s(ss []string) ([]uint64, error) { us := make([]uint64, 0, len(ss)) for _, s := range ss { u, err := strconv.ParseUint(s, 10, 64) if err != nil { return nil, err } us = append(us, u) } return us, nil }
[ "func", "ParseUint64s", "(", "ss", "[", "]", "string", ")", "(", "[", "]", "uint64", ",", "error", ")", "{", "us", ":=", "make", "(", "[", "]", "uint64", ",", "0", ",", "len", "(", "ss", ")", ")", "\n", "for", "_", ",", "s", ":=", "range", ...
// ParseUint64s parses a slice of strings into a slice of uint64s.
[ "ParseUint64s", "parses", "a", "slice", "of", "strings", "into", "a", "slice", "of", "uint64s", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/internal/util/parse.go#L38-L50
train
prometheus/procfs
internal/util/parse.go
ReadUintFromFile
func ReadUintFromFile(path string) (uint64, error) { data, err := ioutil.ReadFile(path) if err != nil { return 0, err } return strconv.ParseUint(strings.TrimSpace(string(data)), 10, 64) }
go
func ReadUintFromFile(path string) (uint64, error) { data, err := ioutil.ReadFile(path) if err != nil { return 0, err } return strconv.ParseUint(strings.TrimSpace(string(data)), 10, 64) }
[ "func", "ReadUintFromFile", "(", "path", "string", ")", "(", "uint64", ",", "error", ")", "{", "data", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", ...
// ReadUintFromFile reads a file and attempts to parse a uint64 from it.
[ "ReadUintFromFile", "reads", "a", "file", "and", "attempts", "to", "parse", "a", "uint64", "from", "it", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/internal/util/parse.go#L53-L59
train
prometheus/procfs
internal/util/parse.go
ParseBool
func ParseBool(b string) *bool { var truth bool switch b { case "enabled": truth = true case "disabled": truth = false default: return nil } return &truth }
go
func ParseBool(b string) *bool { var truth bool switch b { case "enabled": truth = true case "disabled": truth = false default: return nil } return &truth }
[ "func", "ParseBool", "(", "b", "string", ")", "*", "bool", "{", "var", "truth", "bool", "\n", "switch", "b", "{", "case", "\"", "\"", ":", "truth", "=", "true", "\n", "case", "\"", "\"", ":", "truth", "=", "false", "\n", "default", ":", "return", ...
// ParseBool parses a string into a boolean pointer.
[ "ParseBool", "parses", "a", "string", "into", "a", "boolean", "pointer", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/internal/util/parse.go#L62-L73
train
prometheus/procfs
sysfs/fs.go
Path
func (fs FS) Path(p ...string) string { return filepath.Join(append([]string{string(fs)}, p...)...) }
go
func (fs FS) Path(p ...string) string { return filepath.Join(append([]string{string(fs)}, p...)...) }
[ "func", "(", "fs", "FS", ")", "Path", "(", "p", "...", "string", ")", "string", "{", "return", "filepath", ".", "Join", "(", "append", "(", "[", "]", "string", "{", "string", "(", "fs", ")", "}", ",", "p", "...", ")", "...", ")", "\n", "}" ]
// Path returns the path of the given subsystem relative to the sys root.
[ "Path", "returns", "the", "path", "of", "the", "given", "subsystem", "relative", "to", "the", "sys", "root", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/sysfs/fs.go#L44-L46
train
prometheus/procfs
bcache/get.go
ReadStats
func ReadStats(sysfs string) ([]*Stats, error) { matches, err := filepath.Glob(path.Join(sysfs, "fs/bcache/*-*")) if err != nil { return nil, err } stats := make([]*Stats, 0, len(matches)) for _, uuidPath := range matches { // "*-*" in glob above indicates the name of the bcache. name := filepath.Base(uuidPath) // stats s, err := GetStats(uuidPath) if err != nil { return nil, err } s.Name = name stats = append(stats, s) } return stats, nil }
go
func ReadStats(sysfs string) ([]*Stats, error) { matches, err := filepath.Glob(path.Join(sysfs, "fs/bcache/*-*")) if err != nil { return nil, err } stats := make([]*Stats, 0, len(matches)) for _, uuidPath := range matches { // "*-*" in glob above indicates the name of the bcache. name := filepath.Base(uuidPath) // stats s, err := GetStats(uuidPath) if err != nil { return nil, err } s.Name = name stats = append(stats, s) } return stats, nil }
[ "func", "ReadStats", "(", "sysfs", "string", ")", "(", "[", "]", "*", "Stats", ",", "error", ")", "{", "matches", ",", "err", ":=", "filepath", ".", "Glob", "(", "path", ".", "Join", "(", "sysfs", ",", "\"", "\"", ")", ")", "\n", "if", "err", "...
// ReadStats retrieves bcache runtime statistics for each bcache.
[ "ReadStats", "retrieves", "bcache", "runtime", "statistics", "for", "each", "bcache", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/bcache/get.go#L28-L50
train
prometheus/procfs
bcache/get.go
parsePseudoFloat
func parsePseudoFloat(str string) (float64, error) { ss := strings.Split(str, ".") intPart, err := strconv.ParseFloat(ss[0], 64) if err != nil { return 0, err } if len(ss) == 1 { // Pure integers are fine. return intPart, nil } fracPart, err := strconv.ParseFloat(ss[1], 64) if err != nil { return 0, err } // fracPart is a number between 0 and 1023 divided by 100; it is off // by a small amount. Unexpected bumps in time lines may occur because // for bch_hprint .1 != .10 and .10 > .9 (at least up to Linux // v4.12-rc3). // Restore the proper order: fracPart = fracPart / 10.24 return intPart + fracPart, nil }
go
func parsePseudoFloat(str string) (float64, error) { ss := strings.Split(str, ".") intPart, err := strconv.ParseFloat(ss[0], 64) if err != nil { return 0, err } if len(ss) == 1 { // Pure integers are fine. return intPart, nil } fracPart, err := strconv.ParseFloat(ss[1], 64) if err != nil { return 0, err } // fracPart is a number between 0 and 1023 divided by 100; it is off // by a small amount. Unexpected bumps in time lines may occur because // for bch_hprint .1 != .10 and .10 > .9 (at least up to Linux // v4.12-rc3). // Restore the proper order: fracPart = fracPart / 10.24 return intPart + fracPart, nil }
[ "func", "parsePseudoFloat", "(", "str", "string", ")", "(", "float64", ",", "error", ")", "{", "ss", ":=", "strings", ".", "Split", "(", "str", ",", "\"", "\"", ")", "\n\n", "intPart", ",", "err", ":=", "strconv", ".", "ParseFloat", "(", "ss", "[", ...
// ParsePseudoFloat parses the peculiar format produced by bcache's bch_hprint.
[ "ParsePseudoFloat", "parses", "the", "peculiar", "format", "produced", "by", "bcache", "s", "bch_hprint", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/bcache/get.go#L53-L77
train
prometheus/procfs
bcache/get.go
dehumanize
func dehumanize(hbytes []byte) (uint64, error) { ll := len(hbytes) if ll == 0 { return 0, fmt.Errorf("zero-length reply") } lastByte := hbytes[ll-1] mul := float64(1) var ( mant float64 err error ) // If lastByte is beyond the range of ASCII digits, it must be a // multiplier. if lastByte > 57 { // Remove multiplier from slice. hbytes = hbytes[:len(hbytes)-1] const ( _ = 1 << (10 * iota) KiB MiB GiB TiB PiB EiB ZiB YiB ) multipliers := map[rune]float64{ // Source for conversion rules: // linux-kernel/drivers/md/bcache/util.c:bch_hprint() 'k': KiB, 'M': MiB, 'G': GiB, 'T': TiB, 'P': PiB, 'E': EiB, 'Z': ZiB, 'Y': YiB, } mul = multipliers[rune(lastByte)] mant, err = parsePseudoFloat(string(hbytes)) if err != nil { return 0, err } } else { // Not humanized by bch_hprint mant, err = strconv.ParseFloat(string(hbytes), 64) if err != nil { return 0, err } } res := uint64(mant * mul) return res, nil }
go
func dehumanize(hbytes []byte) (uint64, error) { ll := len(hbytes) if ll == 0 { return 0, fmt.Errorf("zero-length reply") } lastByte := hbytes[ll-1] mul := float64(1) var ( mant float64 err error ) // If lastByte is beyond the range of ASCII digits, it must be a // multiplier. if lastByte > 57 { // Remove multiplier from slice. hbytes = hbytes[:len(hbytes)-1] const ( _ = 1 << (10 * iota) KiB MiB GiB TiB PiB EiB ZiB YiB ) multipliers := map[rune]float64{ // Source for conversion rules: // linux-kernel/drivers/md/bcache/util.c:bch_hprint() 'k': KiB, 'M': MiB, 'G': GiB, 'T': TiB, 'P': PiB, 'E': EiB, 'Z': ZiB, 'Y': YiB, } mul = multipliers[rune(lastByte)] mant, err = parsePseudoFloat(string(hbytes)) if err != nil { return 0, err } } else { // Not humanized by bch_hprint mant, err = strconv.ParseFloat(string(hbytes), 64) if err != nil { return 0, err } } res := uint64(mant * mul) return res, nil }
[ "func", "dehumanize", "(", "hbytes", "[", "]", "byte", ")", "(", "uint64", ",", "error", ")", "{", "ll", ":=", "len", "(", "hbytes", ")", "\n", "if", "ll", "==", "0", "{", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", ...
// Dehumanize converts a human-readable byte slice into a uint64.
[ "Dehumanize", "converts", "a", "human", "-", "readable", "byte", "slice", "into", "a", "uint64", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/bcache/get.go#L80-L135
train
prometheus/procfs
bcache/get.go
parsePriorityStats
func parsePriorityStats(line string, ps *PriorityStats) error { var ( value uint64 err error ) switch { case strings.HasPrefix(line, "Unused:"): fields := strings.Fields(line) rawValue := fields[len(fields)-1] valueStr := strings.TrimSuffix(rawValue, "%") value, err = strconv.ParseUint(valueStr, 10, 64) if err != nil { return err } ps.UnusedPercent = value case strings.HasPrefix(line, "Metadata:"): fields := strings.Fields(line) rawValue := fields[len(fields)-1] valueStr := strings.TrimSuffix(rawValue, "%") value, err = strconv.ParseUint(valueStr, 10, 64) if err != nil { return err } ps.MetadataPercent = value } return nil }
go
func parsePriorityStats(line string, ps *PriorityStats) error { var ( value uint64 err error ) switch { case strings.HasPrefix(line, "Unused:"): fields := strings.Fields(line) rawValue := fields[len(fields)-1] valueStr := strings.TrimSuffix(rawValue, "%") value, err = strconv.ParseUint(valueStr, 10, 64) if err != nil { return err } ps.UnusedPercent = value case strings.HasPrefix(line, "Metadata:"): fields := strings.Fields(line) rawValue := fields[len(fields)-1] valueStr := strings.TrimSuffix(rawValue, "%") value, err = strconv.ParseUint(valueStr, 10, 64) if err != nil { return err } ps.MetadataPercent = value } return nil }
[ "func", "parsePriorityStats", "(", "line", "string", ",", "ps", "*", "PriorityStats", ")", "error", "{", "var", "(", "value", "uint64", "\n", "err", "error", "\n", ")", "\n", "switch", "{", "case", "strings", ".", "HasPrefix", "(", "line", ",", "\"", "...
// ParsePriorityStats parses lines from the priority_stats file.
[ "ParsePriorityStats", "parses", "lines", "from", "the", "priority_stats", "file", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/bcache/get.go#L167-L193
train
prometheus/procfs
sysfs/system_cpu.go
NewSystemCpufreq
func (fs FS) NewSystemCpufreq() ([]SystemCPUCpufreqStats, error) { var g errgroup.Group cpus, err := filepath.Glob(fs.Path("devices/system/cpu/cpu[0-9]*")) if err != nil { return nil, err } systemCpufreq := make([]SystemCPUCpufreqStats, len(cpus)) for i, cpu := range cpus { cpuName := strings.TrimPrefix(filepath.Base(cpu), "cpu") cpuCpufreqPath := filepath.Join(cpu, "cpufreq") _, err = os.Stat(cpuCpufreqPath) if os.IsNotExist(err) { continue } else if err != nil { return nil, err } // Execute the parsing of each CPU in parallel. // This is done because the kernel intentionally delays access to each CPU by // 50 milliseconds to avoid DDoSing possibly expensive functions. i := i // https://golang.org/doc/faq#closures_and_goroutines g.Go(func() error { cpufreq, err := parseCpufreqCpuinfo(cpuCpufreqPath) if err == nil { cpufreq.Name = cpuName systemCpufreq[i] = *cpufreq } return err }) } if err = g.Wait(); err != nil { return nil, err } return systemCpufreq, nil }
go
func (fs FS) NewSystemCpufreq() ([]SystemCPUCpufreqStats, error) { var g errgroup.Group cpus, err := filepath.Glob(fs.Path("devices/system/cpu/cpu[0-9]*")) if err != nil { return nil, err } systemCpufreq := make([]SystemCPUCpufreqStats, len(cpus)) for i, cpu := range cpus { cpuName := strings.TrimPrefix(filepath.Base(cpu), "cpu") cpuCpufreqPath := filepath.Join(cpu, "cpufreq") _, err = os.Stat(cpuCpufreqPath) if os.IsNotExist(err) { continue } else if err != nil { return nil, err } // Execute the parsing of each CPU in parallel. // This is done because the kernel intentionally delays access to each CPU by // 50 milliseconds to avoid DDoSing possibly expensive functions. i := i // https://golang.org/doc/faq#closures_and_goroutines g.Go(func() error { cpufreq, err := parseCpufreqCpuinfo(cpuCpufreqPath) if err == nil { cpufreq.Name = cpuName systemCpufreq[i] = *cpufreq } return err }) } if err = g.Wait(); err != nil { return nil, err } return systemCpufreq, nil }
[ "func", "(", "fs", "FS", ")", "NewSystemCpufreq", "(", ")", "(", "[", "]", "SystemCPUCpufreqStats", ",", "error", ")", "{", "var", "g", "errgroup", ".", "Group", "\n\n", "cpus", ",", "err", ":=", "filepath", ".", "Glob", "(", "fs", ".", "Path", "(", ...
// NewSystemCpufreq returns CPU frequency metrics for all CPUs.
[ "NewSystemCpufreq", "returns", "CPU", "frequency", "metrics", "for", "all", "CPUs", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/sysfs/system_cpu.go#L60-L99
train
prometheus/procfs
xfs/parse.go
extentAllocationStats
func extentAllocationStats(us []uint32) (ExtentAllocationStats, error) { if l := len(us); l != 4 { return ExtentAllocationStats{}, fmt.Errorf("incorrect number of values for XFS extent allocation stats: %d", l) } return ExtentAllocationStats{ ExtentsAllocated: us[0], BlocksAllocated: us[1], ExtentsFreed: us[2], BlocksFreed: us[3], }, nil }
go
func extentAllocationStats(us []uint32) (ExtentAllocationStats, error) { if l := len(us); l != 4 { return ExtentAllocationStats{}, fmt.Errorf("incorrect number of values for XFS extent allocation stats: %d", l) } return ExtentAllocationStats{ ExtentsAllocated: us[0], BlocksAllocated: us[1], ExtentsFreed: us[2], BlocksFreed: us[3], }, nil }
[ "func", "extentAllocationStats", "(", "us", "[", "]", "uint32", ")", "(", "ExtentAllocationStats", ",", "error", ")", "{", "if", "l", ":=", "len", "(", "us", ")", ";", "l", "!=", "4", "{", "return", "ExtentAllocationStats", "{", "}", ",", "fmt", ".", ...
// extentAllocationStats builds an ExtentAllocationStats from a slice of uint32s.
[ "extentAllocationStats", "builds", "an", "ExtentAllocationStats", "from", "a", "slice", "of", "uint32s", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/xfs/parse.go#L128-L139
train
prometheus/procfs
xfs/parse.go
btreeStats
func btreeStats(us []uint32) (BTreeStats, error) { if l := len(us); l != 4 { return BTreeStats{}, fmt.Errorf("incorrect number of values for XFS btree stats: %d", l) } return BTreeStats{ Lookups: us[0], Compares: us[1], RecordsInserted: us[2], RecordsDeleted: us[3], }, nil }
go
func btreeStats(us []uint32) (BTreeStats, error) { if l := len(us); l != 4 { return BTreeStats{}, fmt.Errorf("incorrect number of values for XFS btree stats: %d", l) } return BTreeStats{ Lookups: us[0], Compares: us[1], RecordsInserted: us[2], RecordsDeleted: us[3], }, nil }
[ "func", "btreeStats", "(", "us", "[", "]", "uint32", ")", "(", "BTreeStats", ",", "error", ")", "{", "if", "l", ":=", "len", "(", "us", ")", ";", "l", "!=", "4", "{", "return", "BTreeStats", "{", "}", ",", "fmt", ".", "Errorf", "(", "\"", "\"",...
// btreeStats builds a BTreeStats from a slice of uint32s.
[ "btreeStats", "builds", "a", "BTreeStats", "from", "a", "slice", "of", "uint32s", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/xfs/parse.go#L142-L153
train
prometheus/procfs
xfs/parse.go
blockMappingStats
func blockMappingStats(us []uint32) (BlockMappingStats, error) { if l := len(us); l != 7 { return BlockMappingStats{}, fmt.Errorf("incorrect number of values for XFS block mapping stats: %d", l) } return BlockMappingStats{ Reads: us[0], Writes: us[1], Unmaps: us[2], ExtentListInsertions: us[3], ExtentListDeletions: us[4], ExtentListLookups: us[5], ExtentListCompares: us[6], }, nil }
go
func blockMappingStats(us []uint32) (BlockMappingStats, error) { if l := len(us); l != 7 { return BlockMappingStats{}, fmt.Errorf("incorrect number of values for XFS block mapping stats: %d", l) } return BlockMappingStats{ Reads: us[0], Writes: us[1], Unmaps: us[2], ExtentListInsertions: us[3], ExtentListDeletions: us[4], ExtentListLookups: us[5], ExtentListCompares: us[6], }, nil }
[ "func", "blockMappingStats", "(", "us", "[", "]", "uint32", ")", "(", "BlockMappingStats", ",", "error", ")", "{", "if", "l", ":=", "len", "(", "us", ")", ";", "l", "!=", "7", "{", "return", "BlockMappingStats", "{", "}", ",", "fmt", ".", "Errorf", ...
// BlockMappingStat builds a BlockMappingStats from a slice of uint32s.
[ "BlockMappingStat", "builds", "a", "BlockMappingStats", "from", "a", "slice", "of", "uint32s", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/xfs/parse.go#L156-L170
train
prometheus/procfs
xfs/parse.go
directoryOperationStats
func directoryOperationStats(us []uint32) (DirectoryOperationStats, error) { if l := len(us); l != 4 { return DirectoryOperationStats{}, fmt.Errorf("incorrect number of values for XFS directory operation stats: %d", l) } return DirectoryOperationStats{ Lookups: us[0], Creates: us[1], Removes: us[2], Getdents: us[3], }, nil }
go
func directoryOperationStats(us []uint32) (DirectoryOperationStats, error) { if l := len(us); l != 4 { return DirectoryOperationStats{}, fmt.Errorf("incorrect number of values for XFS directory operation stats: %d", l) } return DirectoryOperationStats{ Lookups: us[0], Creates: us[1], Removes: us[2], Getdents: us[3], }, nil }
[ "func", "directoryOperationStats", "(", "us", "[", "]", "uint32", ")", "(", "DirectoryOperationStats", ",", "error", ")", "{", "if", "l", ":=", "len", "(", "us", ")", ";", "l", "!=", "4", "{", "return", "DirectoryOperationStats", "{", "}", ",", "fmt", ...
// DirectoryOperationStats builds a DirectoryOperationStats from a slice of uint32s.
[ "DirectoryOperationStats", "builds", "a", "DirectoryOperationStats", "from", "a", "slice", "of", "uint32s", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/xfs/parse.go#L173-L184
train
prometheus/procfs
xfs/parse.go
transactionStats
func transactionStats(us []uint32) (TransactionStats, error) { if l := len(us); l != 3 { return TransactionStats{}, fmt.Errorf("incorrect number of values for XFS transaction stats: %d", l) } return TransactionStats{ Sync: us[0], Async: us[1], Empty: us[2], }, nil }
go
func transactionStats(us []uint32) (TransactionStats, error) { if l := len(us); l != 3 { return TransactionStats{}, fmt.Errorf("incorrect number of values for XFS transaction stats: %d", l) } return TransactionStats{ Sync: us[0], Async: us[1], Empty: us[2], }, nil }
[ "func", "transactionStats", "(", "us", "[", "]", "uint32", ")", "(", "TransactionStats", ",", "error", ")", "{", "if", "l", ":=", "len", "(", "us", ")", ";", "l", "!=", "3", "{", "return", "TransactionStats", "{", "}", ",", "fmt", ".", "Errorf", "(...
// TransactionStats builds a TransactionStats from a slice of uint32s.
[ "TransactionStats", "builds", "a", "TransactionStats", "from", "a", "slice", "of", "uint32s", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/xfs/parse.go#L187-L197
train
prometheus/procfs
xfs/parse.go
inodeOperationStats
func inodeOperationStats(us []uint32) (InodeOperationStats, error) { if l := len(us); l != 7 { return InodeOperationStats{}, fmt.Errorf("incorrect number of values for XFS inode operation stats: %d", l) } return InodeOperationStats{ Attempts: us[0], Found: us[1], Recycle: us[2], Missed: us[3], Duplicate: us[4], Reclaims: us[5], AttributeChange: us[6], }, nil }
go
func inodeOperationStats(us []uint32) (InodeOperationStats, error) { if l := len(us); l != 7 { return InodeOperationStats{}, fmt.Errorf("incorrect number of values for XFS inode operation stats: %d", l) } return InodeOperationStats{ Attempts: us[0], Found: us[1], Recycle: us[2], Missed: us[3], Duplicate: us[4], Reclaims: us[5], AttributeChange: us[6], }, nil }
[ "func", "inodeOperationStats", "(", "us", "[", "]", "uint32", ")", "(", "InodeOperationStats", ",", "error", ")", "{", "if", "l", ":=", "len", "(", "us", ")", ";", "l", "!=", "7", "{", "return", "InodeOperationStats", "{", "}", ",", "fmt", ".", "Erro...
// InodeOperationStats builds an InodeOperationStats from a slice of uint32s.
[ "InodeOperationStats", "builds", "an", "InodeOperationStats", "from", "a", "slice", "of", "uint32s", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/xfs/parse.go#L200-L214
train
prometheus/procfs
xfs/parse.go
logOperationStats
func logOperationStats(us []uint32) (LogOperationStats, error) { if l := len(us); l != 5 { return LogOperationStats{}, fmt.Errorf("incorrect number of values for XFS log operation stats: %d", l) } return LogOperationStats{ Writes: us[0], Blocks: us[1], NoInternalBuffers: us[2], Force: us[3], ForceSleep: us[4], }, nil }
go
func logOperationStats(us []uint32) (LogOperationStats, error) { if l := len(us); l != 5 { return LogOperationStats{}, fmt.Errorf("incorrect number of values for XFS log operation stats: %d", l) } return LogOperationStats{ Writes: us[0], Blocks: us[1], NoInternalBuffers: us[2], Force: us[3], ForceSleep: us[4], }, nil }
[ "func", "logOperationStats", "(", "us", "[", "]", "uint32", ")", "(", "LogOperationStats", ",", "error", ")", "{", "if", "l", ":=", "len", "(", "us", ")", ";", "l", "!=", "5", "{", "return", "LogOperationStats", "{", "}", ",", "fmt", ".", "Errorf", ...
// LogOperationStats builds a LogOperationStats from a slice of uint32s.
[ "LogOperationStats", "builds", "a", "LogOperationStats", "from", "a", "slice", "of", "uint32s", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/xfs/parse.go#L217-L229
train
prometheus/procfs
xfs/parse.go
readWriteStats
func readWriteStats(us []uint32) (ReadWriteStats, error) { if l := len(us); l != 2 { return ReadWriteStats{}, fmt.Errorf("incorrect number of values for XFS read write stats: %d", l) } return ReadWriteStats{ Read: us[0], Write: us[1], }, nil }
go
func readWriteStats(us []uint32) (ReadWriteStats, error) { if l := len(us); l != 2 { return ReadWriteStats{}, fmt.Errorf("incorrect number of values for XFS read write stats: %d", l) } return ReadWriteStats{ Read: us[0], Write: us[1], }, nil }
[ "func", "readWriteStats", "(", "us", "[", "]", "uint32", ")", "(", "ReadWriteStats", ",", "error", ")", "{", "if", "l", ":=", "len", "(", "us", ")", ";", "l", "!=", "2", "{", "return", "ReadWriteStats", "{", "}", ",", "fmt", ".", "Errorf", "(", "...
// ReadWriteStats builds a ReadWriteStats from a slice of uint32s.
[ "ReadWriteStats", "builds", "a", "ReadWriteStats", "from", "a", "slice", "of", "uint32s", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/xfs/parse.go#L232-L241
train
prometheus/procfs
xfs/parse.go
attributeOperationStats
func attributeOperationStats(us []uint32) (AttributeOperationStats, error) { if l := len(us); l != 4 { return AttributeOperationStats{}, fmt.Errorf("incorrect number of values for XFS attribute operation stats: %d", l) } return AttributeOperationStats{ Get: us[0], Set: us[1], Remove: us[2], List: us[3], }, nil }
go
func attributeOperationStats(us []uint32) (AttributeOperationStats, error) { if l := len(us); l != 4 { return AttributeOperationStats{}, fmt.Errorf("incorrect number of values for XFS attribute operation stats: %d", l) } return AttributeOperationStats{ Get: us[0], Set: us[1], Remove: us[2], List: us[3], }, nil }
[ "func", "attributeOperationStats", "(", "us", "[", "]", "uint32", ")", "(", "AttributeOperationStats", ",", "error", ")", "{", "if", "l", ":=", "len", "(", "us", ")", ";", "l", "!=", "4", "{", "return", "AttributeOperationStats", "{", "}", ",", "fmt", ...
// AttributeOperationStats builds an AttributeOperationStats from a slice of uint32s.
[ "AttributeOperationStats", "builds", "an", "AttributeOperationStats", "from", "a", "slice", "of", "uint32s", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/xfs/parse.go#L244-L255
train
prometheus/procfs
xfs/parse.go
inodeClusteringStats
func inodeClusteringStats(us []uint32) (InodeClusteringStats, error) { if l := len(us); l != 3 { return InodeClusteringStats{}, fmt.Errorf("incorrect number of values for XFS inode clustering stats: %d", l) } return InodeClusteringStats{ Iflush: us[0], Flush: us[1], FlushInode: us[2], }, nil }
go
func inodeClusteringStats(us []uint32) (InodeClusteringStats, error) { if l := len(us); l != 3 { return InodeClusteringStats{}, fmt.Errorf("incorrect number of values for XFS inode clustering stats: %d", l) } return InodeClusteringStats{ Iflush: us[0], Flush: us[1], FlushInode: us[2], }, nil }
[ "func", "inodeClusteringStats", "(", "us", "[", "]", "uint32", ")", "(", "InodeClusteringStats", ",", "error", ")", "{", "if", "l", ":=", "len", "(", "us", ")", ";", "l", "!=", "3", "{", "return", "InodeClusteringStats", "{", "}", ",", "fmt", ".", "E...
// InodeClusteringStats builds an InodeClusteringStats from a slice of uint32s.
[ "InodeClusteringStats", "builds", "an", "InodeClusteringStats", "from", "a", "slice", "of", "uint32s", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/xfs/parse.go#L258-L268
train
prometheus/procfs
xfs/parse.go
vnodeStats
func vnodeStats(us []uint32) (VnodeStats, error) { // The attribute "Free" appears to not be available on older XFS // stats versions. Therefore, 7 or 8 elements may appear in // this slice. l := len(us) if l != 7 && l != 8 { return VnodeStats{}, fmt.Errorf("incorrect number of values for XFS vnode stats: %d", l) } s := VnodeStats{ Active: us[0], Allocate: us[1], Get: us[2], Hold: us[3], Release: us[4], Reclaim: us[5], Remove: us[6], } // Skip adding free, unless it is present. The zero value will // be used in place of an actual count. if l == 7 { return s, nil } s.Free = us[7] return s, nil }
go
func vnodeStats(us []uint32) (VnodeStats, error) { // The attribute "Free" appears to not be available on older XFS // stats versions. Therefore, 7 or 8 elements may appear in // this slice. l := len(us) if l != 7 && l != 8 { return VnodeStats{}, fmt.Errorf("incorrect number of values for XFS vnode stats: %d", l) } s := VnodeStats{ Active: us[0], Allocate: us[1], Get: us[2], Hold: us[3], Release: us[4], Reclaim: us[5], Remove: us[6], } // Skip adding free, unless it is present. The zero value will // be used in place of an actual count. if l == 7 { return s, nil } s.Free = us[7] return s, nil }
[ "func", "vnodeStats", "(", "us", "[", "]", "uint32", ")", "(", "VnodeStats", ",", "error", ")", "{", "// The attribute \"Free\" appears to not be available on older XFS", "// stats versions. Therefore, 7 or 8 elements may appear in", "// this slice.", "l", ":=", "len", "(", ...
// VnodeStats builds a VnodeStats from a slice of uint32s.
[ "VnodeStats", "builds", "a", "VnodeStats", "from", "a", "slice", "of", "uint32s", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/xfs/parse.go#L271-L298
train
prometheus/procfs
xfs/parse.go
bufferStats
func bufferStats(us []uint32) (BufferStats, error) { if l := len(us); l != 9 { return BufferStats{}, fmt.Errorf("incorrect number of values for XFS buffer stats: %d", l) } return BufferStats{ Get: us[0], Create: us[1], GetLocked: us[2], GetLockedWaited: us[3], BusyLocked: us[4], MissLocked: us[5], PageRetries: us[6], PageFound: us[7], GetRead: us[8], }, nil }
go
func bufferStats(us []uint32) (BufferStats, error) { if l := len(us); l != 9 { return BufferStats{}, fmt.Errorf("incorrect number of values for XFS buffer stats: %d", l) } return BufferStats{ Get: us[0], Create: us[1], GetLocked: us[2], GetLockedWaited: us[3], BusyLocked: us[4], MissLocked: us[5], PageRetries: us[6], PageFound: us[7], GetRead: us[8], }, nil }
[ "func", "bufferStats", "(", "us", "[", "]", "uint32", ")", "(", "BufferStats", ",", "error", ")", "{", "if", "l", ":=", "len", "(", "us", ")", ";", "l", "!=", "9", "{", "return", "BufferStats", "{", "}", ",", "fmt", ".", "Errorf", "(", "\"", "\...
// BufferStats builds a BufferStats from a slice of uint32s.
[ "BufferStats", "builds", "a", "BufferStats", "from", "a", "slice", "of", "uint32s", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/xfs/parse.go#L301-L317
train
prometheus/procfs
xfs/parse.go
extendedPrecisionStats
func extendedPrecisionStats(us []uint64) (ExtendedPrecisionStats, error) { if l := len(us); l != 3 { return ExtendedPrecisionStats{}, fmt.Errorf("incorrect number of values for XFS extended precision stats: %d", l) } return ExtendedPrecisionStats{ FlushBytes: us[0], WriteBytes: us[1], ReadBytes: us[2], }, nil }
go
func extendedPrecisionStats(us []uint64) (ExtendedPrecisionStats, error) { if l := len(us); l != 3 { return ExtendedPrecisionStats{}, fmt.Errorf("incorrect number of values for XFS extended precision stats: %d", l) } return ExtendedPrecisionStats{ FlushBytes: us[0], WriteBytes: us[1], ReadBytes: us[2], }, nil }
[ "func", "extendedPrecisionStats", "(", "us", "[", "]", "uint64", ")", "(", "ExtendedPrecisionStats", ",", "error", ")", "{", "if", "l", ":=", "len", "(", "us", ")", ";", "l", "!=", "3", "{", "return", "ExtendedPrecisionStats", "{", "}", ",", "fmt", "."...
// ExtendedPrecisionStats builds an ExtendedPrecisionStats from a slice of uint32s.
[ "ExtendedPrecisionStats", "builds", "an", "ExtendedPrecisionStats", "from", "a", "slice", "of", "uint32s", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/xfs/parse.go#L320-L330
train
prometheus/procfs
fs.go
Path
func (fs FS) Path(p ...string) string { return path.Join(append([]string{string(fs)}, p...)...) }
go
func (fs FS) Path(p ...string) string { return path.Join(append([]string{string(fs)}, p...)...) }
[ "func", "(", "fs", "FS", ")", "Path", "(", "p", "...", "string", ")", "string", "{", "return", "path", ".", "Join", "(", "append", "(", "[", "]", "string", "{", "string", "(", "fs", ")", "}", ",", "p", "...", ")", "...", ")", "\n", "}" ]
// Path returns the path of the given subsystem relative to the procfs root.
[ "Path", "returns", "the", "path", "of", "the", "given", "subsystem", "relative", "to", "the", "procfs", "root", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/fs.go#L44-L46
train
prometheus/procfs
sysfs/class_thermal.go
NewClassThermalZoneStats
func (fs FS) NewClassThermalZoneStats() ([]ClassThermalZoneStats, error) { zones, err := filepath.Glob(fs.Path("class/thermal/thermal_zone[0-9]*")) if err != nil { return []ClassThermalZoneStats{}, err } var zoneStats = ClassThermalZoneStats{} stats := make([]ClassThermalZoneStats, len(zones)) for i, zone := range zones { zoneName := strings.TrimPrefix(filepath.Base(zone), "thermal_zone") zoneStats, err = parseClassThermalZone(zone) if err != nil { return []ClassThermalZoneStats{}, err } zoneStats.Name = zoneName stats[i] = zoneStats } return stats, nil }
go
func (fs FS) NewClassThermalZoneStats() ([]ClassThermalZoneStats, error) { zones, err := filepath.Glob(fs.Path("class/thermal/thermal_zone[0-9]*")) if err != nil { return []ClassThermalZoneStats{}, err } var zoneStats = ClassThermalZoneStats{} stats := make([]ClassThermalZoneStats, len(zones)) for i, zone := range zones { zoneName := strings.TrimPrefix(filepath.Base(zone), "thermal_zone") zoneStats, err = parseClassThermalZone(zone) if err != nil { return []ClassThermalZoneStats{}, err } zoneStats.Name = zoneName stats[i] = zoneStats } return stats, nil }
[ "func", "(", "fs", "FS", ")", "NewClassThermalZoneStats", "(", ")", "(", "[", "]", "ClassThermalZoneStats", ",", "error", ")", "{", "zones", ",", "err", ":=", "filepath", ".", "Glob", "(", "fs", ".", "Path", "(", "\"", "\"", ")", ")", "\n", "if", "...
// NewClassThermalZoneStats returns Thermal Zone metrics for all zones.
[ "NewClassThermalZoneStats", "returns", "Thermal", "Zone", "metrics", "for", "all", "zones", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/sysfs/class_thermal.go#L39-L58
train
prometheus/procfs
mdstat.go
ParseMDStat
func (fs FS) ParseMDStat() (mdstates []MDStat, err error) { mdStatusFilePath := fs.Path("mdstat") content, err := ioutil.ReadFile(mdStatusFilePath) if err != nil { return []MDStat{}, fmt.Errorf("error parsing %s: %s", mdStatusFilePath, err) } mdStates := []MDStat{} lines := strings.Split(string(content), "\n") for i, l := range lines { if l == "" { continue } if l[0] == ' ' { continue } if strings.HasPrefix(l, "Personalities") || strings.HasPrefix(l, "unused") { continue } mainLine := strings.Split(l, " ") if len(mainLine) < 3 { return mdStates, fmt.Errorf("error parsing mdline: %s", l) } mdName := mainLine[0] activityState := mainLine[2] if len(lines) <= i+3 { return mdStates, fmt.Errorf( "error parsing %s: too few lines for md device %s", mdStatusFilePath, mdName, ) } active, total, size, err := evalStatusline(lines[i+1]) if err != nil { return mdStates, fmt.Errorf("error parsing %s: %s", mdStatusFilePath, err) } // j is the line number of the syncing-line. j := i + 2 if strings.Contains(lines[i+2], "bitmap") { // skip bitmap line j = i + 3 } // If device is syncing at the moment, get the number of currently // synced bytes, otherwise that number equals the size of the device. syncedBlocks := size if strings.Contains(lines[j], "recovery") || strings.Contains(lines[j], "resync") { syncedBlocks, err = evalBuildline(lines[j]) if err != nil { return mdStates, fmt.Errorf("error parsing %s: %s", mdStatusFilePath, err) } } mdStates = append(mdStates, MDStat{ Name: mdName, ActivityState: activityState, DisksActive: active, DisksTotal: total, BlocksTotal: size, BlocksSynced: syncedBlocks, }) } return mdStates, nil }
go
func (fs FS) ParseMDStat() (mdstates []MDStat, err error) { mdStatusFilePath := fs.Path("mdstat") content, err := ioutil.ReadFile(mdStatusFilePath) if err != nil { return []MDStat{}, fmt.Errorf("error parsing %s: %s", mdStatusFilePath, err) } mdStates := []MDStat{} lines := strings.Split(string(content), "\n") for i, l := range lines { if l == "" { continue } if l[0] == ' ' { continue } if strings.HasPrefix(l, "Personalities") || strings.HasPrefix(l, "unused") { continue } mainLine := strings.Split(l, " ") if len(mainLine) < 3 { return mdStates, fmt.Errorf("error parsing mdline: %s", l) } mdName := mainLine[0] activityState := mainLine[2] if len(lines) <= i+3 { return mdStates, fmt.Errorf( "error parsing %s: too few lines for md device %s", mdStatusFilePath, mdName, ) } active, total, size, err := evalStatusline(lines[i+1]) if err != nil { return mdStates, fmt.Errorf("error parsing %s: %s", mdStatusFilePath, err) } // j is the line number of the syncing-line. j := i + 2 if strings.Contains(lines[i+2], "bitmap") { // skip bitmap line j = i + 3 } // If device is syncing at the moment, get the number of currently // synced bytes, otherwise that number equals the size of the device. syncedBlocks := size if strings.Contains(lines[j], "recovery") || strings.Contains(lines[j], "resync") { syncedBlocks, err = evalBuildline(lines[j]) if err != nil { return mdStates, fmt.Errorf("error parsing %s: %s", mdStatusFilePath, err) } } mdStates = append(mdStates, MDStat{ Name: mdName, ActivityState: activityState, DisksActive: active, DisksTotal: total, BlocksTotal: size, BlocksSynced: syncedBlocks, }) } return mdStates, nil }
[ "func", "(", "fs", "FS", ")", "ParseMDStat", "(", ")", "(", "mdstates", "[", "]", "MDStat", ",", "err", "error", ")", "{", "mdStatusFilePath", ":=", "fs", ".", "Path", "(", "\"", "\"", ")", "\n", "content", ",", "err", ":=", "ioutil", ".", "ReadFil...
// ParseMDStat parses an mdstat-file and returns a struct with the relevant infos.
[ "ParseMDStat", "parses", "an", "mdstat", "-", "file", "and", "returns", "a", "struct", "with", "the", "relevant", "infos", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/mdstat.go#L46-L113
train
prometheus/procfs
stat.go
parseSoftIRQStat
func parseSoftIRQStat(line string) (SoftIRQStat, uint64, error) { softIRQStat := SoftIRQStat{} var total uint64 var prefix string _, err := fmt.Sscanf(line, "%s %d %d %d %d %d %d %d %d %d %d %d", &prefix, &total, &softIRQStat.Hi, &softIRQStat.Timer, &softIRQStat.NetTx, &softIRQStat.NetRx, &softIRQStat.Block, &softIRQStat.BlockIoPoll, &softIRQStat.Tasklet, &softIRQStat.Sched, &softIRQStat.Hrtimer, &softIRQStat.Rcu) if err != nil { return SoftIRQStat{}, 0, fmt.Errorf("couldn't parse %s (softirq): %s", line, err) } return softIRQStat, total, nil }
go
func parseSoftIRQStat(line string) (SoftIRQStat, uint64, error) { softIRQStat := SoftIRQStat{} var total uint64 var prefix string _, err := fmt.Sscanf(line, "%s %d %d %d %d %d %d %d %d %d %d %d", &prefix, &total, &softIRQStat.Hi, &softIRQStat.Timer, &softIRQStat.NetTx, &softIRQStat.NetRx, &softIRQStat.Block, &softIRQStat.BlockIoPoll, &softIRQStat.Tasklet, &softIRQStat.Sched, &softIRQStat.Hrtimer, &softIRQStat.Rcu) if err != nil { return SoftIRQStat{}, 0, fmt.Errorf("couldn't parse %s (softirq): %s", line, err) } return softIRQStat, total, nil }
[ "func", "parseSoftIRQStat", "(", "line", "string", ")", "(", "SoftIRQStat", ",", "uint64", ",", "error", ")", "{", "softIRQStat", ":=", "SoftIRQStat", "{", "}", "\n", "var", "total", "uint64", "\n", "var", "prefix", "string", "\n\n", "_", ",", "err", ":=...
// Parse a softirq line.
[ "Parse", "a", "softirq", "line", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/stat.go#L133-L150
train
prometheus/procfs
ipvs.go
NewIPVSStats
func NewIPVSStats() (IPVSStats, error) { fs, err := NewFS(DefaultMountPoint) if err != nil { return IPVSStats{}, err } return fs.NewIPVSStats() }
go
func NewIPVSStats() (IPVSStats, error) { fs, err := NewFS(DefaultMountPoint) if err != nil { return IPVSStats{}, err } return fs.NewIPVSStats() }
[ "func", "NewIPVSStats", "(", ")", "(", "IPVSStats", ",", "error", ")", "{", "fs", ",", "err", ":=", "NewFS", "(", "DefaultMountPoint", ")", "\n", "if", "err", "!=", "nil", "{", "return", "IPVSStats", "{", "}", ",", "err", "\n", "}", "\n\n", "return",...
// NewIPVSStats reads the IPVS statistics.
[ "NewIPVSStats", "reads", "the", "IPVS", "statistics", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/ipvs.go#L66-L73
train
prometheus/procfs
ipvs.go
NewIPVSStats
func (fs FS) NewIPVSStats() (IPVSStats, error) { file, err := os.Open(fs.Path("net/ip_vs_stats")) if err != nil { return IPVSStats{}, err } defer file.Close() return parseIPVSStats(file) }
go
func (fs FS) NewIPVSStats() (IPVSStats, error) { file, err := os.Open(fs.Path("net/ip_vs_stats")) if err != nil { return IPVSStats{}, err } defer file.Close() return parseIPVSStats(file) }
[ "func", "(", "fs", "FS", ")", "NewIPVSStats", "(", ")", "(", "IPVSStats", ",", "error", ")", "{", "file", ",", "err", ":=", "os", ".", "Open", "(", "fs", ".", "Path", "(", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "...
// NewIPVSStats reads the IPVS statistics from the specified `proc` filesystem.
[ "NewIPVSStats", "reads", "the", "IPVS", "statistics", "from", "the", "specified", "proc", "filesystem", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/ipvs.go#L76-L84
train
prometheus/procfs
ipvs.go
parseIPVSStats
func parseIPVSStats(file io.Reader) (IPVSStats, error) { var ( statContent []byte statLines []string statFields []string stats IPVSStats ) statContent, err := ioutil.ReadAll(file) if err != nil { return IPVSStats{}, err } statLines = strings.SplitN(string(statContent), "\n", 4) if len(statLines) != 4 { return IPVSStats{}, errors.New("ip_vs_stats corrupt: too short") } statFields = strings.Fields(statLines[2]) if len(statFields) != 5 { return IPVSStats{}, errors.New("ip_vs_stats corrupt: unexpected number of fields") } stats.Connections, err = strconv.ParseUint(statFields[0], 16, 64) if err != nil { return IPVSStats{}, err } stats.IncomingPackets, err = strconv.ParseUint(statFields[1], 16, 64) if err != nil { return IPVSStats{}, err } stats.OutgoingPackets, err = strconv.ParseUint(statFields[2], 16, 64) if err != nil { return IPVSStats{}, err } stats.IncomingBytes, err = strconv.ParseUint(statFields[3], 16, 64) if err != nil { return IPVSStats{}, err } stats.OutgoingBytes, err = strconv.ParseUint(statFields[4], 16, 64) if err != nil { return IPVSStats{}, err } return stats, nil }
go
func parseIPVSStats(file io.Reader) (IPVSStats, error) { var ( statContent []byte statLines []string statFields []string stats IPVSStats ) statContent, err := ioutil.ReadAll(file) if err != nil { return IPVSStats{}, err } statLines = strings.SplitN(string(statContent), "\n", 4) if len(statLines) != 4 { return IPVSStats{}, errors.New("ip_vs_stats corrupt: too short") } statFields = strings.Fields(statLines[2]) if len(statFields) != 5 { return IPVSStats{}, errors.New("ip_vs_stats corrupt: unexpected number of fields") } stats.Connections, err = strconv.ParseUint(statFields[0], 16, 64) if err != nil { return IPVSStats{}, err } stats.IncomingPackets, err = strconv.ParseUint(statFields[1], 16, 64) if err != nil { return IPVSStats{}, err } stats.OutgoingPackets, err = strconv.ParseUint(statFields[2], 16, 64) if err != nil { return IPVSStats{}, err } stats.IncomingBytes, err = strconv.ParseUint(statFields[3], 16, 64) if err != nil { return IPVSStats{}, err } stats.OutgoingBytes, err = strconv.ParseUint(statFields[4], 16, 64) if err != nil { return IPVSStats{}, err } return stats, nil }
[ "func", "parseIPVSStats", "(", "file", "io", ".", "Reader", ")", "(", "IPVSStats", ",", "error", ")", "{", "var", "(", "statContent", "[", "]", "byte", "\n", "statLines", "[", "]", "string", "\n", "statFields", "[", "]", "string", "\n", "stats", "IPVSS...
// parseIPVSStats performs the actual parsing of `ip_vs_stats`.
[ "parseIPVSStats", "performs", "the", "actual", "parsing", "of", "ip_vs_stats", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/ipvs.go#L87-L132
train
prometheus/procfs
net_dev.go
newNetDev
func newNetDev(file string) (NetDev, error) { f, err := os.Open(file) if err != nil { return NetDev{}, err } defer f.Close() nd := NetDev{} s := bufio.NewScanner(f) for n := 0; s.Scan(); n++ { // Skip the 2 header lines. if n < 2 { continue } line, err := nd.parseLine(s.Text()) if err != nil { return nd, err } nd[line.Name] = *line } return nd, s.Err() }
go
func newNetDev(file string) (NetDev, error) { f, err := os.Open(file) if err != nil { return NetDev{}, err } defer f.Close() nd := NetDev{} s := bufio.NewScanner(f) for n := 0; s.Scan(); n++ { // Skip the 2 header lines. if n < 2 { continue } line, err := nd.parseLine(s.Text()) if err != nil { return nd, err } nd[line.Name] = *line } return nd, s.Err() }
[ "func", "newNetDev", "(", "file", "string", ")", "(", "NetDev", ",", "error", ")", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "file", ")", "\n", "if", "err", "!=", "nil", "{", "return", "NetDev", "{", "}", ",", "err", "\n", "}", "\n", ...
// newNetDev creates a new NetDev from the contents of the given file.
[ "newNetDev", "creates", "a", "new", "NetDev", "from", "the", "contents", "of", "the", "given", "file", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/net_dev.go#L71-L95
train
prometheus/procfs
net_dev.go
Total
func (nd NetDev) Total() NetDevLine { total := NetDevLine{} names := make([]string, 0, len(nd)) for _, ifc := range nd { names = append(names, ifc.Name) total.RxBytes += ifc.RxBytes total.RxPackets += ifc.RxPackets total.RxPackets += ifc.RxPackets total.RxErrors += ifc.RxErrors total.RxDropped += ifc.RxDropped total.RxFIFO += ifc.RxFIFO total.RxFrame += ifc.RxFrame total.RxCompressed += ifc.RxCompressed total.RxMulticast += ifc.RxMulticast total.TxBytes += ifc.TxBytes total.TxPackets += ifc.TxPackets total.TxErrors += ifc.TxErrors total.TxDropped += ifc.TxDropped total.TxFIFO += ifc.TxFIFO total.TxCollisions += ifc.TxCollisions total.TxCarrier += ifc.TxCarrier total.TxCompressed += ifc.TxCompressed } sort.Strings(names) total.Name = strings.Join(names, ", ") return total }
go
func (nd NetDev) Total() NetDevLine { total := NetDevLine{} names := make([]string, 0, len(nd)) for _, ifc := range nd { names = append(names, ifc.Name) total.RxBytes += ifc.RxBytes total.RxPackets += ifc.RxPackets total.RxPackets += ifc.RxPackets total.RxErrors += ifc.RxErrors total.RxDropped += ifc.RxDropped total.RxFIFO += ifc.RxFIFO total.RxFrame += ifc.RxFrame total.RxCompressed += ifc.RxCompressed total.RxMulticast += ifc.RxMulticast total.TxBytes += ifc.TxBytes total.TxPackets += ifc.TxPackets total.TxErrors += ifc.TxErrors total.TxDropped += ifc.TxDropped total.TxFIFO += ifc.TxFIFO total.TxCollisions += ifc.TxCollisions total.TxCarrier += ifc.TxCarrier total.TxCompressed += ifc.TxCompressed } sort.Strings(names) total.Name = strings.Join(names, ", ") return total }
[ "func", "(", "nd", "NetDev", ")", "Total", "(", ")", "NetDevLine", "{", "total", ":=", "NetDevLine", "{", "}", "\n\n", "names", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "nd", ")", ")", "\n", "for", "_", ",", "ifc", ":="...
// Total aggregates the values across interfaces and returns a new NetDevLine. // The Name field will be a sorted comma separated list of interface names.
[ "Total", "aggregates", "the", "values", "across", "interfaces", "and", "returns", "a", "new", "NetDevLine", ".", "The", "Name", "field", "will", "be", "a", "sorted", "comma", "separated", "list", "of", "interface", "names", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/net_dev.go#L188-L216
train
prometheus/procfs
proc_psi.go
NewPSIStatsForResource
func NewPSIStatsForResource(resource string) (PSIStats, error) { fs, err := NewFS(DefaultMountPoint) if err != nil { return PSIStats{}, err } return fs.NewPSIStatsForResource(resource) }
go
func NewPSIStatsForResource(resource string) (PSIStats, error) { fs, err := NewFS(DefaultMountPoint) if err != nil { return PSIStats{}, err } return fs.NewPSIStatsForResource(resource) }
[ "func", "NewPSIStatsForResource", "(", "resource", "string", ")", "(", "PSIStats", ",", "error", ")", "{", "fs", ",", "err", ":=", "NewFS", "(", "DefaultMountPoint", ")", "\n", "if", "err", "!=", "nil", "{", "return", "PSIStats", "{", "}", ",", "err", ...
// NewPSIStatsForResource reads pressure stall information for the specified // resource. At time of writing this can be either "cpu", "memory" or "io".
[ "NewPSIStatsForResource", "reads", "pressure", "stall", "information", "for", "the", "specified", "resource", ".", "At", "time", "of", "writing", "this", "can", "be", "either", "cpu", "memory", "or", "io", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/proc_psi.go#L56-L63
train
prometheus/procfs
proc_psi.go
parsePSIStats
func parsePSIStats(resource string, file io.Reader) (PSIStats, error) { psiStats := PSIStats{} stats, err := ioutil.ReadAll(file) if err != nil { return psiStats, fmt.Errorf("psi_stats: unable to read data for %s", resource) } for _, l := range strings.Split(string(stats), "\n") { prefix := strings.Split(l, " ")[0] switch prefix { case "some": psi := PSILine{} _, err := fmt.Sscanf(l, fmt.Sprintf("some %s", lineFormat), &psi.Avg10, &psi.Avg60, &psi.Avg300, &psi.Total) if err != nil { return PSIStats{}, err } psiStats.Some = &psi case "full": psi := PSILine{} _, err := fmt.Sscanf(l, fmt.Sprintf("full %s", lineFormat), &psi.Avg10, &psi.Avg60, &psi.Avg300, &psi.Total) if err != nil { return PSIStats{}, err } psiStats.Full = &psi default: // If we encounter a line with an unknown prefix, ignore it and move on // Should new measurement types be added in the future we'll simply ignore them instead // of erroring on retrieval continue } } return psiStats, nil }
go
func parsePSIStats(resource string, file io.Reader) (PSIStats, error) { psiStats := PSIStats{} stats, err := ioutil.ReadAll(file) if err != nil { return psiStats, fmt.Errorf("psi_stats: unable to read data for %s", resource) } for _, l := range strings.Split(string(stats), "\n") { prefix := strings.Split(l, " ")[0] switch prefix { case "some": psi := PSILine{} _, err := fmt.Sscanf(l, fmt.Sprintf("some %s", lineFormat), &psi.Avg10, &psi.Avg60, &psi.Avg300, &psi.Total) if err != nil { return PSIStats{}, err } psiStats.Some = &psi case "full": psi := PSILine{} _, err := fmt.Sscanf(l, fmt.Sprintf("full %s", lineFormat), &psi.Avg10, &psi.Avg60, &psi.Avg300, &psi.Total) if err != nil { return PSIStats{}, err } psiStats.Full = &psi default: // If we encounter a line with an unknown prefix, ignore it and move on // Should new measurement types be added in the future we'll simply ignore them instead // of erroring on retrieval continue } } return psiStats, nil }
[ "func", "parsePSIStats", "(", "resource", "string", ",", "file", "io", ".", "Reader", ")", "(", "PSIStats", ",", "error", ")", "{", "psiStats", ":=", "PSIStats", "{", "}", "\n", "stats", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "file", ")", "...
// parsePSIStats parses the specified file for pressure stall information
[ "parsePSIStats", "parses", "the", "specified", "file", "for", "pressure", "stall", "information" ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/proc_psi.go#L77-L110
train
prometheus/procfs
buddyinfo.go
NewBuddyInfo
func NewBuddyInfo() ([]BuddyInfo, error) { fs, err := NewFS(DefaultMountPoint) if err != nil { return nil, err } return fs.NewBuddyInfo() }
go
func NewBuddyInfo() ([]BuddyInfo, error) { fs, err := NewFS(DefaultMountPoint) if err != nil { return nil, err } return fs.NewBuddyInfo() }
[ "func", "NewBuddyInfo", "(", ")", "(", "[", "]", "BuddyInfo", ",", "error", ")", "{", "fs", ",", "err", ":=", "NewFS", "(", "DefaultMountPoint", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "fs...
// NewBuddyInfo reads the buddyinfo statistics.
[ "NewBuddyInfo", "reads", "the", "buddyinfo", "statistics", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/buddyinfo.go#L35-L42
train
prometheus/procfs
buddyinfo.go
NewBuddyInfo
func (fs FS) NewBuddyInfo() ([]BuddyInfo, error) { file, err := os.Open(fs.Path("buddyinfo")) if err != nil { return nil, err } defer file.Close() return parseBuddyInfo(file) }
go
func (fs FS) NewBuddyInfo() ([]BuddyInfo, error) { file, err := os.Open(fs.Path("buddyinfo")) if err != nil { return nil, err } defer file.Close() return parseBuddyInfo(file) }
[ "func", "(", "fs", "FS", ")", "NewBuddyInfo", "(", ")", "(", "[", "]", "BuddyInfo", ",", "error", ")", "{", "file", ",", "err", ":=", "os", ".", "Open", "(", "fs", ".", "Path", "(", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", ...
// NewBuddyInfo reads the buddyinfo statistics from the specified `proc` filesystem.
[ "NewBuddyInfo", "reads", "the", "buddyinfo", "statistics", "from", "the", "specified", "proc", "filesystem", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/buddyinfo.go#L45-L53
train
prometheus/procfs
proc_stat.go
NewStat
func (p Proc) NewStat() (ProcStat, error) { f, err := os.Open(p.path("stat")) if err != nil { return ProcStat{}, err } defer f.Close() data, err := ioutil.ReadAll(f) if err != nil { return ProcStat{}, err } var ( ignore int s = ProcStat{PID: p.PID, fs: p.fs} l = bytes.Index(data, []byte("(")) r = bytes.LastIndex(data, []byte(")")) ) if l < 0 || r < 0 { return ProcStat{}, fmt.Errorf( "unexpected format, couldn't extract comm: %s", data, ) } s.Comm = string(data[l+1 : r]) _, err = fmt.Fscan( bytes.NewBuffer(data[r+2:]), &s.State, &s.PPID, &s.PGRP, &s.Session, &s.TTY, &s.TPGID, &s.Flags, &s.MinFlt, &s.CMinFlt, &s.MajFlt, &s.CMajFlt, &s.UTime, &s.STime, &s.CUTime, &s.CSTime, &s.Priority, &s.Nice, &s.NumThreads, &ignore, &s.Starttime, &s.VSize, &s.RSS, ) if err != nil { return ProcStat{}, err } return s, nil }
go
func (p Proc) NewStat() (ProcStat, error) { f, err := os.Open(p.path("stat")) if err != nil { return ProcStat{}, err } defer f.Close() data, err := ioutil.ReadAll(f) if err != nil { return ProcStat{}, err } var ( ignore int s = ProcStat{PID: p.PID, fs: p.fs} l = bytes.Index(data, []byte("(")) r = bytes.LastIndex(data, []byte(")")) ) if l < 0 || r < 0 { return ProcStat{}, fmt.Errorf( "unexpected format, couldn't extract comm: %s", data, ) } s.Comm = string(data[l+1 : r]) _, err = fmt.Fscan( bytes.NewBuffer(data[r+2:]), &s.State, &s.PPID, &s.PGRP, &s.Session, &s.TTY, &s.TPGID, &s.Flags, &s.MinFlt, &s.CMinFlt, &s.MajFlt, &s.CMajFlt, &s.UTime, &s.STime, &s.CUTime, &s.CSTime, &s.Priority, &s.Nice, &s.NumThreads, &ignore, &s.Starttime, &s.VSize, &s.RSS, ) if err != nil { return ProcStat{}, err } return s, nil }
[ "func", "(", "p", "Proc", ")", "NewStat", "(", ")", "(", "ProcStat", ",", "error", ")", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "p", ".", "path", "(", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ProcStat"...
// NewStat returns the current status information of the process.
[ "NewStat", "returns", "the", "current", "status", "information", "of", "the", "process", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/proc_stat.go#L106-L164
train
prometheus/procfs
proc_stat.go
StartTime
func (s ProcStat) StartTime() (float64, error) { stat, err := s.fs.NewStat() if err != nil { return 0, err } return float64(stat.BootTime) + (float64(s.Starttime) / userHZ), nil }
go
func (s ProcStat) StartTime() (float64, error) { stat, err := s.fs.NewStat() if err != nil { return 0, err } return float64(stat.BootTime) + (float64(s.Starttime) / userHZ), nil }
[ "func", "(", "s", "ProcStat", ")", "StartTime", "(", ")", "(", "float64", ",", "error", ")", "{", "stat", ",", "err", ":=", "s", ".", "fs", ".", "NewStat", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "...
// StartTime returns the unix timestamp of the process in seconds.
[ "StartTime", "returns", "the", "unix", "timestamp", "of", "the", "process", "in", "seconds", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/proc_stat.go#L177-L183
train
prometheus/procfs
proc_stat.go
CPUTime
func (s ProcStat) CPUTime() float64 { return float64(s.UTime+s.STime) / userHZ }
go
func (s ProcStat) CPUTime() float64 { return float64(s.UTime+s.STime) / userHZ }
[ "func", "(", "s", "ProcStat", ")", "CPUTime", "(", ")", "float64", "{", "return", "float64", "(", "s", ".", "UTime", "+", "s", ".", "STime", ")", "/", "userHZ", "\n", "}" ]
// CPUTime returns the total CPU user and system time in seconds.
[ "CPUTime", "returns", "the", "total", "CPU", "user", "and", "system", "time", "in", "seconds", "." ]
87a4384529e0652f5035fb5cc8095faf73ea9b0b
https://github.com/prometheus/procfs/blob/87a4384529e0652f5035fb5cc8095faf73ea9b0b/proc_stat.go#L186-L188
train
nats-io/go-nats-streaming
stan.go
ConnectWait
func ConnectWait(t time.Duration) Option { return func(o *Options) error { o.ConnectTimeout = t return nil } }
go
func ConnectWait(t time.Duration) Option { return func(o *Options) error { o.ConnectTimeout = t return nil } }
[ "func", "ConnectWait", "(", "t", "time", ".", "Duration", ")", "Option", "{", "return", "func", "(", "o", "*", "Options", ")", "error", "{", "o", ".", "ConnectTimeout", "=", "t", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// ConnectWait is an Option to set the timeout for establishing a connection.
[ "ConnectWait", "is", "an", "Option", "to", "set", "the", "timeout", "for", "establishing", "a", "connection", "." ]
3e2ff0719c7a6219b4e791e19c782de98c701f4a
https://github.com/nats-io/go-nats-streaming/blob/3e2ff0719c7a6219b4e791e19c782de98c701f4a/stan.go#L198-L203
train
nats-io/go-nats-streaming
stan.go
PubAckWait
func PubAckWait(t time.Duration) Option { return func(o *Options) error { o.AckTimeout = t return nil } }
go
func PubAckWait(t time.Duration) Option { return func(o *Options) error { o.AckTimeout = t return nil } }
[ "func", "PubAckWait", "(", "t", "time", ".", "Duration", ")", "Option", "{", "return", "func", "(", "o", "*", "Options", ")", "error", "{", "o", ".", "AckTimeout", "=", "t", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// PubAckWait is an Option to set the timeout for waiting for an ACK for a // published message.
[ "PubAckWait", "is", "an", "Option", "to", "set", "the", "timeout", "for", "waiting", "for", "an", "ACK", "for", "a", "published", "message", "." ]
3e2ff0719c7a6219b4e791e19c782de98c701f4a
https://github.com/nats-io/go-nats-streaming/blob/3e2ff0719c7a6219b4e791e19c782de98c701f4a/stan.go#L207-L212
train
nats-io/go-nats-streaming
stan.go
MaxPubAcksInflight
func MaxPubAcksInflight(max int) Option { return func(o *Options) error { o.MaxPubAcksInflight = max return nil } }
go
func MaxPubAcksInflight(max int) Option { return func(o *Options) error { o.MaxPubAcksInflight = max return nil } }
[ "func", "MaxPubAcksInflight", "(", "max", "int", ")", "Option", "{", "return", "func", "(", "o", "*", "Options", ")", "error", "{", "o", ".", "MaxPubAcksInflight", "=", "max", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// MaxPubAcksInflight is an Option to set the maximum number of published // messages without outstanding ACKs from the server.
[ "MaxPubAcksInflight", "is", "an", "Option", "to", "set", "the", "maximum", "number", "of", "published", "messages", "without", "outstanding", "ACKs", "from", "the", "server", "." ]
3e2ff0719c7a6219b4e791e19c782de98c701f4a
https://github.com/nats-io/go-nats-streaming/blob/3e2ff0719c7a6219b4e791e19c782de98c701f4a/stan.go#L216-L221
train
nats-io/go-nats-streaming
stan.go
NatsConn
func NatsConn(nc *nats.Conn) Option { return func(o *Options) error { o.NatsConn = nc return nil } }
go
func NatsConn(nc *nats.Conn) Option { return func(o *Options) error { o.NatsConn = nc return nil } }
[ "func", "NatsConn", "(", "nc", "*", "nats", ".", "Conn", ")", "Option", "{", "return", "func", "(", "o", "*", "Options", ")", "error", "{", "o", ".", "NatsConn", "=", "nc", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// NatsConn is an Option to set the underlying NATS connection to be used // by a streaming connection object. When such option is set, closing the // streaming connection does not close the provided NATS connection.
[ "NatsConn", "is", "an", "Option", "to", "set", "the", "underlying", "NATS", "connection", "to", "be", "used", "by", "a", "streaming", "connection", "object", ".", "When", "such", "option", "is", "set", "closing", "the", "streaming", "connection", "does", "no...
3e2ff0719c7a6219b4e791e19c782de98c701f4a
https://github.com/nats-io/go-nats-streaming/blob/3e2ff0719c7a6219b4e791e19c782de98c701f4a/stan.go#L226-L231
train
nats-io/go-nats-streaming
stan.go
Pings
func Pings(interval, maxOut int) Option { return func(o *Options) error { // For tests, we may pass negative value that will be interpreted // by the library as milliseconds. If this test boolean is set, // do not check values. if !testAllowMillisecInPings { if interval < 1 || maxOut <= 2 { return fmt.Errorf("invalid ping values: interval=%v (min>0) maxOut=%v (min=2)", interval, maxOut) } } o.PingIterval = interval o.PingMaxOut = maxOut return nil } }
go
func Pings(interval, maxOut int) Option { return func(o *Options) error { // For tests, we may pass negative value that will be interpreted // by the library as milliseconds. If this test boolean is set, // do not check values. if !testAllowMillisecInPings { if interval < 1 || maxOut <= 2 { return fmt.Errorf("invalid ping values: interval=%v (min>0) maxOut=%v (min=2)", interval, maxOut) } } o.PingIterval = interval o.PingMaxOut = maxOut return nil } }
[ "func", "Pings", "(", "interval", ",", "maxOut", "int", ")", "Option", "{", "return", "func", "(", "o", "*", "Options", ")", "error", "{", "// For tests, we may pass negative value that will be interpreted", "// by the library as milliseconds. If this test boolean is set,", ...
// Pings is an Option to set the ping interval and max out values. // The interval needs to be at least 1 and represents the number // of seconds. // The maxOut needs to be at least 2, since the count of sent PINGs // increase whenever a PING is sent and reset to 0 when a response // is received. Setting to 1 would cause the library to close the // connection right away.
[ "Pings", "is", "an", "Option", "to", "set", "the", "ping", "interval", "and", "max", "out", "values", ".", "The", "interval", "needs", "to", "be", "at", "least", "1", "and", "represents", "the", "number", "of", "seconds", ".", "The", "maxOut", "needs", ...
3e2ff0719c7a6219b4e791e19c782de98c701f4a
https://github.com/nats-io/go-nats-streaming/blob/3e2ff0719c7a6219b4e791e19c782de98c701f4a/stan.go#L240-L254
train
nats-io/go-nats-streaming
stan.go
failConnect
func (sc *conn) failConnect(err error) { sc.cleanupOnClose(err) if sc.nc != nil && sc.ncOwned { sc.nc.Close() } }
go
func (sc *conn) failConnect(err error) { sc.cleanupOnClose(err) if sc.nc != nil && sc.ncOwned { sc.nc.Close() } }
[ "func", "(", "sc", "*", "conn", ")", "failConnect", "(", "err", "error", ")", "{", "sc", ".", "cleanupOnClose", "(", "err", ")", "\n", "if", "sc", ".", "nc", "!=", "nil", "&&", "sc", ".", "ncOwned", "{", "sc", ".", "nc", ".", "Close", "(", ")",...
// Invoked on a failed connect. // Perform appropriate cleanup operations but do not attempt to send // a close request.
[ "Invoked", "on", "a", "failed", "connect", ".", "Perform", "appropriate", "cleanup", "operations", "but", "do", "not", "attempt", "to", "send", "a", "close", "request", "." ]
3e2ff0719c7a6219b4e791e19c782de98c701f4a
https://github.com/nats-io/go-nats-streaming/blob/3e2ff0719c7a6219b4e791e19c782de98c701f4a/stan.go#L460-L465
train
nats-io/go-nats-streaming
stan.go
closeDueToPing
func (sc *conn) closeDueToPing(err error) { sc.Lock() if sc.nc == nil { sc.Unlock() return } // Stop timer, unsubscribe, fail the pubs, etc.. sc.cleanupOnClose(err) // No need to send Close protocol, so simply close the underlying // NATS connection (if we own it, and if not already closed) if sc.ncOwned && !sc.nc.IsClosed() { sc.nc.Close() } // Mark this streaming connection as closed. Do this under pingMu lock. sc.pingMu.Lock() sc.nc = nil sc.pingMu.Unlock() // Capture callback (even though this is immutable). cb := sc.connLostCB sc.Unlock() if cb != nil { // Execute in separate go routine. go cb(sc, err) } }
go
func (sc *conn) closeDueToPing(err error) { sc.Lock() if sc.nc == nil { sc.Unlock() return } // Stop timer, unsubscribe, fail the pubs, etc.. sc.cleanupOnClose(err) // No need to send Close protocol, so simply close the underlying // NATS connection (if we own it, and if not already closed) if sc.ncOwned && !sc.nc.IsClosed() { sc.nc.Close() } // Mark this streaming connection as closed. Do this under pingMu lock. sc.pingMu.Lock() sc.nc = nil sc.pingMu.Unlock() // Capture callback (even though this is immutable). cb := sc.connLostCB sc.Unlock() if cb != nil { // Execute in separate go routine. go cb(sc, err) } }
[ "func", "(", "sc", "*", "conn", ")", "closeDueToPing", "(", "err", "error", ")", "{", "sc", ".", "Lock", "(", ")", "\n", "if", "sc", ".", "nc", "==", "nil", "{", "sc", ".", "Unlock", "(", ")", "\n", "return", "\n", "}", "\n", "// Stop timer, unsu...
// Closes a connection and invoke the connection error callback if one // was registered when the connection was created.
[ "Closes", "a", "connection", "and", "invoke", "the", "connection", "error", "callback", "if", "one", "was", "registered", "when", "the", "connection", "was", "created", "." ]
3e2ff0719c7a6219b4e791e19c782de98c701f4a
https://github.com/nats-io/go-nats-streaming/blob/3e2ff0719c7a6219b4e791e19c782de98c701f4a/stan.go#L523-L547
train