-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move (re-license) tracing package and introduce 'allowundefined' in k…
…probe struct tag (#37602) * fix: replace deprecated io/ioutil with os * fix: rename local vars so they don't collide with built-in functions * feat: introduce support for allowundefined tag * fix: remove unnecessary named return variable * feat: expose the option to set the wakeup_events for the perf channel * feat: move tracing from x-pack/auditbeat to auditbeat * legal: re-license tracing from Elastic License to Apache License Version 2.0 * fix: remove deprecated ioutil in events_test.go * fix: replace naked return(s) * fix: pre-allocate slices wherever the len is known * fix: use errors.Is to check for a specific error * fix: remove unused withTime struct field from PerfChannel * fix: properly use make(chan struct{}) * fix: use raw string with regexp.MustCompile * fix: replace missed naked return(s) * fix: replace pre-allocating len of the slices with cap * feat: modernise tracing endian.go to use binary.NativeEndian * feat: refactor copyInt and readInt to use unsafe.Slice * fix: revert pollAll in perfevent.go to named returns as these can be properly documented * fix: remove redundant endian.go and utilise directly binary.NativeEndian * fix: return explicitly the named returns in pollAll * Revert "fix: remove redundant endian.go and utilise directly binary.NativeEndian" This reverts commit 19d9c28.
- Loading branch information
1 parent
56e198b
commit 685be2f
Showing
39 changed files
with
350 additions
and
192 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
19 changes: 16 additions & 3 deletions
19
x-pack/auditbeat/tracing/cpu_test.go → auditbeat/tracing/cpu_test.go
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,22 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
// Package tracing provides a set of tools built on top of | ||
// golang.org/x/sys/unix/linux/perf that simplify working with KProbes and | ||
// UProbes, using tracing perf channels to receive events from the kernel and | ||
// decoding of this raw events into more useful types. | ||
package tracing |
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,28 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
//go:build linux | ||
|
||
package tracing | ||
|
||
import ( | ||
"encoding/binary" | ||
) | ||
|
||
// MachineEndian is either binary.BigEndian or binary.LittleEndian, depending | ||
// on the current architecture. | ||
var MachineEndian = binary.NativeEndian |
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,71 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
//go:build linux && !386 && !amd64 && !amd64p32 | ||
|
||
// Alignment-safe integer reading and writing functions. | ||
|
||
package tracing | ||
|
||
import ( | ||
"errors" | ||
"unsafe" | ||
) | ||
|
||
var errBadSize = errors.New("bad size for integer") | ||
|
||
func copyInt(dst unsafe.Pointer, src unsafe.Pointer, len uint8) error { | ||
copy(unsafe.Slice((*byte)(dst), len), unsafe.Slice((*byte)(src), len)) | ||
return nil | ||
} | ||
|
||
func readInt(ptr unsafe.Pointer, len uint8, signed bool) (any, error) { | ||
var value any | ||
asSlice := unsafe.Slice((*byte)(ptr), len) | ||
switch len { | ||
case 1: | ||
if signed { | ||
value = int8(asSlice[0]) | ||
} else { | ||
value = asSlice[0] | ||
} | ||
case 2: | ||
if signed { | ||
value = int16(MachineEndian.Uint16(asSlice)) | ||
} else { | ||
value = MachineEndian.Uint16(asSlice) | ||
} | ||
|
||
case 4: | ||
if signed { | ||
value = int32(MachineEndian.Uint32(asSlice)) | ||
} else { | ||
value = MachineEndian.Uint32(asSlice) | ||
} | ||
|
||
case 8: | ||
if signed { | ||
value = int64(MachineEndian.Uint64(asSlice)) | ||
} else { | ||
value = MachineEndian.Uint64(asSlice) | ||
} | ||
|
||
default: | ||
return nil, errBadSize | ||
} | ||
return value, nil | ||
} |
Oops, something went wrong.