Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
majora-go
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
majora
majora-go
Commits
ec243b8b
Commit
ec243b8b
authored
Dec 23, 2021
by
Tsaiilin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
trace 日志采样
parent
06bd0e54
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
3 deletions
+26
-3
trace.go
trace/trace.go
+26
-3
No files found.
trace/trace.go
View file @
ec243b8b
package
trace
package
trace
import
(
import
(
"sync/atomic"
"time"
"github.com/adamweixuan/getty"
"github.com/adamweixuan/getty"
"go.uber.org/zap"
"go.uber.org/zap"
"time"
"virjar.com/majora-go/log"
"virjar.com/majora-go/log"
)
)
...
@@ -117,10 +120,30 @@ func (r *RecorderImpl) Enable() bool {
...
@@ -117,10 +120,30 @@ func (r *RecorderImpl) Enable() bool {
var
defaultNopRecorder
=
NopRecorder
{}
var
defaultNopRecorder
=
NopRecorder
{}
var
slots
=
make
([]
int64
,
30
)
func
AcquireRecorder
(
sessionId
string
)
Recorder
{
func
AcquireRecorder
(
sessionId
string
)
Recorder
{
return
&
RecorderImpl
{
sessionId
:
sessionId
,
now
:=
time
.
Now
()
slotIndex
:=
now
.
Minute
()
/
2
timeMinute
:=
now
.
Unix
()
/
60
slot
:=
&
slots
[
slotIndex
]
slotTime
:=
atomic
.
LoadInt64
(
slot
)
if
slotTime
==
timeMinute
{
return
&
defaultNopRecorder
}
if
atomic
.
CompareAndSwapInt64
(
slot
,
slotTime
,
timeMinute
)
{
return
&
RecorderImpl
{
sessionId
:
sessionId
}
}
}
return
&
defaultNopRecorder
}
type
slot
struct
{
time
int64
recorder
Recorder
}
}
type
Session
struct
{
type
Session
struct
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment