diff --git a/.gitignore b/.gitignore index 80b2c3e..1bf69f5 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ example/example example/example.test example/nohup.out +example/recorder/recorder example/replayer/replayer example/replayer/replayer.test example/replayer/example.test diff --git a/plugins/recorder.go b/plugins/recorder.go index 747ecc0..b9e2187 100644 --- a/plugins/recorder.go +++ b/plugins/recorder.go @@ -3,7 +3,7 @@ package plugins import ( "context" - "github.com/didi/sharingan/recorder/recording" + "github.com/didi/sharingan/recorder/koala/recording" ) var recorders []recording.Recorder diff --git a/plugins/recorder_default.go b/plugins/recorder_default.go index 300e7f3..5b90b0d 100644 --- a/plugins/recorder_default.go +++ b/plugins/recorder_default.go @@ -12,7 +12,7 @@ import ( "time" "github.com/didi/sharingan/recorder" - "github.com/didi/sharingan/recorder/recording" + "github.com/didi/sharingan/recorder/koala/recording" "github.com/didi/sharingan/recorder/utils" "github.com/v2pro/plz/countlog" diff --git a/recorder/hook/hook.go b/recorder/koala/hook/hook.go similarity index 80% rename from recorder/hook/hook.go rename to recorder/koala/hook/hook.go index 77dd563..754ad05 100644 --- a/recorder/hook/hook.go +++ b/recorder/koala/hook/hook.go @@ -4,8 +4,7 @@ import ( "net" "syscall" - "github.com/didi/sharingan/recorder/internal" - "github.com/didi/sharingan/recorder/sut" + "github.com/didi/sharingan/recorder/koala/sut" "github.com/v2pro/plz/countlog" ) @@ -23,8 +22,8 @@ func Start() { } func setupAcceptHook() { - internal.RegisterOnAccept(func(serverSocketFD int, clientSocketFD int, sa syscall.Sockaddr) { - gid := sut.ThreadID(internal.GetCurrentGoRoutineID()) + RegisterOnAccept(func(serverSocketFD int, clientSocketFD int, sa syscall.Sockaddr) { + gid := sut.ThreadID(GetCurrentGoRoutineID()) origAddr := sockaddrToTCP(sa) @@ -43,8 +42,8 @@ func setupAcceptHook() { } func setupConnectHook() { - internal.RegisterOnConnect(func(fd int, sa syscall.Sockaddr) { - gid := sut.ThreadID(internal.GetCurrentGoRoutineID()) + RegisterOnConnect(func(fd int, sa syscall.Sockaddr) { + gid := sut.ThreadID(GetCurrentGoRoutineID()) ipv4Addr, _ := sa.(*syscall.SockaddrInet4) if ipv4Addr == nil { @@ -73,8 +72,8 @@ func setupConnectHook() { } func setupSendHook() { - internal.RegisterOnSend(func(fd int, network string, raddr net.Addr, span []byte) { - gid := sut.ThreadID(internal.GetCurrentGoRoutineID()) + RegisterOnSend(func(fd int, network string, raddr net.Addr, span []byte) { + gid := sut.ThreadID(GetCurrentGoRoutineID()) if gid == ignoreThreadID { return } @@ -94,8 +93,8 @@ func setupSendHook() { } func setupRecvHook() { - internal.RegisterOnRecv(func(fd int, network string, raddr net.Addr, span []byte) { - gid := sut.ThreadID(internal.GetCurrentGoRoutineID()) + RegisterOnRecv(func(fd int, network string, raddr net.Addr, span []byte) { + gid := sut.ThreadID(GetCurrentGoRoutineID()) if gid == ignoreThreadID { return } @@ -111,7 +110,7 @@ func setupRecvHook() { } func setupCloseHook() { - internal.RegisterOnClose(func(fd int) { + RegisterOnClose(func(fd int) { countlog.Debug("event!sut.close", "socketFD", fd) sut.RemoveGlobalSock(sut.SocketFD(fd)) }) @@ -119,7 +118,7 @@ func setupCloseHook() { func setupGoRoutineExitHook() { // true goroutineID - internal.RegisterOnGoRoutineExit(func(gid int64) { + RegisterOnGoRoutineExit(func(gid int64) { countlog.Debug("event!sut.goroutine_exit", "threadID", gid) sut.OperateThreadOnRecordingSession(sut.ThreadID(gid), func(thread *sut.Thread) { thread.OnShutdown() diff --git a/recorder/hook/hook_test.go b/recorder/koala/hook/hook_test.go similarity index 100% rename from recorder/hook/hook_test.go rename to recorder/koala/hook/hook_test.go diff --git a/recorder/internal/tag_with_recorder.go b/recorder/koala/hook/tag_with_recorder.go similarity index 98% rename from recorder/internal/tag_with_recorder.go rename to recorder/koala/hook/tag_with_recorder.go index b2bd728..3e06a29 100644 --- a/recorder/internal/tag_with_recorder.go +++ b/recorder/koala/hook/tag_with_recorder.go @@ -1,6 +1,6 @@ // +build recorder -package internal +package hook import ( "net" diff --git a/recorder/internal/tag_without_recorder.go b/recorder/koala/hook/tag_without_recorder.go similarity index 98% rename from recorder/internal/tag_without_recorder.go rename to recorder/koala/hook/tag_without_recorder.go index 3a983f7..19f205c 100644 --- a/recorder/internal/tag_without_recorder.go +++ b/recorder/koala/hook/tag_without_recorder.go @@ -1,6 +1,6 @@ // +build !recorder -package internal +package hook import ( "net" diff --git a/recorder/logger/logger.go b/recorder/koala/logger/logger.go similarity index 100% rename from recorder/logger/logger.go rename to recorder/koala/logger/logger.go diff --git a/recorder/recording/action.go b/recorder/koala/recording/action.go similarity index 100% rename from recorder/recording/action.go rename to recorder/koala/recording/action.go diff --git a/recorder/recording/action_test.go b/recorder/koala/recording/action_test.go similarity index 100% rename from recorder/recording/action_test.go rename to recorder/koala/recording/action_test.go diff --git a/recorder/recording/async.go b/recorder/koala/recording/async.go similarity index 100% rename from recorder/recording/async.go rename to recorder/koala/recording/async.go diff --git a/recorder/recording/recorder.go b/recorder/koala/recording/recorder.go similarity index 100% rename from recorder/recording/recorder.go rename to recorder/koala/recording/recorder.go diff --git a/recorder/recording/session.go b/recorder/koala/recording/session.go similarity index 100% rename from recorder/recording/session.go rename to recorder/koala/recording/session.go diff --git a/recorder/recording/session_test.go b/recorder/koala/recording/session_test.go similarity index 100% rename from recorder/recording/session_test.go rename to recorder/koala/recording/session_test.go diff --git a/recorder/sut/gc.go b/recorder/koala/sut/gc.go similarity index 100% rename from recorder/sut/gc.go rename to recorder/koala/sut/gc.go diff --git a/recorder/sut/socket.go b/recorder/koala/sut/socket.go similarity index 100% rename from recorder/sut/socket.go rename to recorder/koala/sut/socket.go diff --git a/recorder/sut/thread.go b/recorder/koala/sut/thread.go similarity index 99% rename from recorder/sut/thread.go rename to recorder/koala/sut/thread.go index e491e15..fa685a8 100644 --- a/recorder/sut/thread.go +++ b/recorder/koala/sut/thread.go @@ -8,7 +8,7 @@ import ( "time" "unsafe" - "github.com/didi/sharingan/recorder/recording" + "github.com/didi/sharingan/recorder/koala/recording" "github.com/v2pro/plz/countlog" ) diff --git a/recorder/sut/thread_test.go b/recorder/koala/sut/thread_test.go similarity index 100% rename from recorder/sut/thread_test.go rename to recorder/koala/sut/thread_test.go diff --git a/recorder/recorder.go b/recorder/recorder.go index d43ffb7..00ff743 100644 --- a/recorder/recorder.go +++ b/recorder/recorder.go @@ -1,15 +1,15 @@ package recorder import ( - "github.com/didi/sharingan/recorder/internal" + "github.com/didi/sharingan/recorder/koala/hook" ) // GetCurrentGoRoutineID get current goRoutineID incase with delegatedID func GetCurrentGoRoutineID() int64 { - return internal.GetCurrentGoRoutineID() + return hook.GetCurrentGoRoutineID() } // SetDelegatedFromGoRoutineID set goRoutine delegatedID func SetDelegatedFromGoRoutineID(gID int64) { - internal.SetDelegatedFromGoRoutineID(gID) + hook.SetDelegatedFromGoRoutineID(gID) } diff --git a/tag_with_recorder.go b/tag_with_recorder.go index 9d00217..7f02957 100644 --- a/tag_with_recorder.go +++ b/tag_with_recorder.go @@ -8,9 +8,9 @@ import ( "github.com/didi/sharingan/plugins" "github.com/didi/sharingan/recorder" - "github.com/didi/sharingan/recorder/hook" - "github.com/didi/sharingan/recorder/logger" - "github.com/didi/sharingan/recorder/sut" + "github.com/didi/sharingan/recorder/koala/hook" + "github.com/didi/sharingan/recorder/koala/logger" + "github.com/didi/sharingan/recorder/koala/sut" ) // GetCurrentGoRoutineID get current goroutineID incase SetDelegatedFromGoRoutineID