Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
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
630f8262
Commit
630f8262
authored
Dec 23, 2021
by
Tsaiilin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
format
parent
ec243b8b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
25 deletions
+15
-25
trace.go
trace/trace.go
+15
-25
No files found.
trace/trace.go
View file @
630f8262
...
...
@@ -3,6 +3,7 @@ package trace
import
(
"sync/atomic"
"time"
"virjar.com/majora-go/safe"
"github.com/adamweixuan/getty"
"go.uber.org/zap"
...
...
@@ -21,7 +22,7 @@ var (
)
func
init
()
{
go
func
()
{
safe
.
SageGo
(
func
()
{
for
{
e
:=
<-
sessionEventChan
if
e
.
Err
!=
nil
{
...
...
@@ -32,7 +33,7 @@ func init() {
zap
.
Any
(
"event"
,
e
.
Event
))
}
}
}
(
)
})
}
// Event 事件
...
...
@@ -63,36 +64,30 @@ type Recorder interface {
Enable
()
bool
}
type
N
opRecorder
struct
{}
type
n
opRecorder
struct
{}
func
(
n
*
N
opRecorder
)
RecordEvent
(
eventName
string
,
message
string
)
{
func
(
n
*
n
opRecorder
)
RecordEvent
(
eventName
string
,
message
string
)
{
}
func
(
n
*
N
opRecorder
)
RecordErrorEvent
(
eventName
string
,
message
string
,
err
error
)
{
func
(
n
*
n
opRecorder
)
RecordErrorEvent
(
eventName
string
,
message
string
,
err
error
)
{
}
func
(
n
*
N
opRecorder
)
Enable
()
bool
{
func
(
n
*
n
opRecorder
)
Enable
()
bool
{
return
false
}
type
R
ecorderImpl
struct
{
type
r
ecorderImpl
struct
{
sessionId
string
}
func
NewRecorderImpl
(
sessionId
string
)
*
RecorderImpl
{
return
&
RecorderImpl
{
sessionId
:
sessionId
,
}
}
func
(
r
*
R
ecorderImpl
)
RecordEvent
(
eventName
string
,
message
string
)
{
func
(
r
*
r
ecorderImpl
)
RecordEvent
(
eventName
string
,
message
string
)
{
r
.
RecordErrorEvent
(
eventName
,
message
,
nil
)
}
func
(
r
*
R
ecorderImpl
)
RecordErrorEvent
(
eventName
string
,
message
string
,
err
error
)
{
func
(
r
*
r
ecorderImpl
)
RecordErrorEvent
(
eventName
string
,
message
string
,
err
error
)
{
event
:=
&
Event
{
Timestamp
:
time
.
Now
(),
EventName
:
eventName
,
...
...
@@ -114,15 +109,15 @@ func (r *RecorderImpl) RecordErrorEvent(eventName string, message string, err er
sessionEventChan
<-
sessionEvent
}
func
(
r
*
R
ecorderImpl
)
Enable
()
bool
{
func
(
r
*
r
ecorderImpl
)
Enable
()
bool
{
return
true
}
var
defaultNopRecorder
=
N
opRecorder
{}
var
defaultNopRecorder
=
n
opRecorder
{}
var
slots
=
make
([]
int64
,
30
)
func
A
cquireRecorder
(
sessionId
string
)
Recorder
{
func
a
cquireRecorder
(
sessionId
string
)
Recorder
{
now
:=
time
.
Now
()
slotIndex
:=
now
.
Minute
()
/
2
...
...
@@ -135,17 +130,12 @@ func AcquireRecorder(sessionId string) Recorder {
}
if
atomic
.
CompareAndSwapInt64
(
slot
,
slotTime
,
timeMinute
)
{
return
&
R
ecorderImpl
{
sessionId
:
sessionId
}
return
&
r
ecorderImpl
{
sessionId
:
sessionId
}
}
return
&
defaultNopRecorder
}
type
slot
struct
{
time
int64
recorder
Recorder
}
type
Session
struct
{
Recorder
Recorder
}
...
...
@@ -155,7 +145,7 @@ func NewSession(sessionId string) *Session {
sessionId
=
sessionIdNop
}
return
&
Session
{
Recorder
:
A
cquireRecorder
(
sessionId
),
Recorder
:
a
cquireRecorder
(
sessionId
),
}
}
...
...
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