forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement telegraf's own full metric type
main reasons behind this: - make adding/removing tags cheap - make adding/removing fields cheap - make parsing cheaper - make parse -> decorate -> write out bytes metric flow much faster Refactor serializer to use byte buffer
- Loading branch information
Showing
40 changed files
with
1,375 additions
and
397 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package metric | ||
|
||
import ( | ||
"reflect" | ||
"strconv" | ||
"unsafe" | ||
) | ||
|
||
// parseIntBytes is a zero-alloc wrapper around strconv.ParseInt. | ||
func parseIntBytes(b []byte, base int, bitSize int) (i int64, err error) { | ||
s := unsafeBytesToString(b) | ||
return strconv.ParseInt(s, base, bitSize) | ||
} | ||
|
||
// parseFloatBytes is a zero-alloc wrapper around strconv.ParseFloat. | ||
func parseFloatBytes(b []byte, bitSize int) (float64, error) { | ||
s := unsafeBytesToString(b) | ||
return strconv.ParseFloat(s, bitSize) | ||
} | ||
|
||
// parseBoolBytes is a zero-alloc wrapper around strconv.ParseBool. | ||
func parseBoolBytes(b []byte) (bool, error) { | ||
return strconv.ParseBool(unsafeBytesToString(b)) | ||
} | ||
|
||
// unsafeBytesToString converts a []byte to a string without a heap allocation. | ||
// | ||
// It is unsafe, and is intended to prepare input to short-lived functions | ||
// that require strings. | ||
func unsafeBytesToString(in []byte) string { | ||
src := *(*reflect.SliceHeader)(unsafe.Pointer(&in)) | ||
dst := reflect.StringHeader{ | ||
Data: src.Data, | ||
Len: src.Len, | ||
} | ||
s := *(*string)(unsafe.Pointer(&dst)) | ||
return s | ||
} |
Oops, something went wrong.