main.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. package main
  2. import (
  3. _ "context"
  4. "encoding/base64"
  5. "fmt"
  6. _ "github.com/olivere/elastic/v7"
  7. _ "github.com/olivere/elastic/v7/config"
  8. "io/ioutil"
  9. "log"
  10. "os"
  11. "rocommon/service"
  12. _ "rocommon/socket"
  13. _ "rocommon/socket/http"
  14. _ "rocommon/socket/tcp"
  15. _ "rocommon/socket/websocket"
  16. "rocommon/util"
  17. "roserver/baseserver/model"
  18. "roserver/baseserver/set"
  19. testModel "roserver/test/model"
  20. "runtime"
  21. "strings"
  22. )
  23. type IBase interface {
  24. SetVal()
  25. GetBase() *abase
  26. }
  27. type abase struct {
  28. aabase int
  29. }
  30. type a1 struct {
  31. abase
  32. aaa int
  33. }
  34. func (this *a1) SetVal() {
  35. this.aabase = 1
  36. }
  37. func (this *a1) GetBase() *abase {
  38. return &this.abase
  39. }
  40. type noCopy struct{}
  41. func (this *noCopy) Lock() {}
  42. func (this *noCopy) Unlock() {}
  43. type copyCool struct {
  44. Val int32
  45. noCopy noCopy
  46. }
  47. func main() {
  48. testCool := copyCool{Val: 10}
  49. t2 := testCool
  50. t2.Val = 20
  51. testCool.Val = 30
  52. fmt.Println(t2, testCool)
  53. return
  54. //tmpa1 := &a1{}
  55. //tmpa1.SetVal()
  56. //var tmpa2 IBase
  57. //tmpa2 = tmpa1
  58. //tmpVal := (*abase)(unsafe.Pointer(tmpa1))
  59. //tmpa2.GetBase().aabase = 2
  60. //log.Printf("tmpval=%v tmpa2=%v", tmpVal, tmpa2.GetBase().aabase)
  61. //return
  62. //uuuuid := 3132646845219
  63. //tmpUid := uuuuid >> 32
  64. //tmpUid1 := 3132646845219 - (tmpUid << 32)
  65. //log.Printf("tmpuid=%v | %v | %v", tmpUid, tmpUid<<32, tmpUid1)
  66. //
  67. //return
  68. //testStr := "CFwQDxiQmtnLpy8g6NjagbYvKAGCAQcIgPnhw6cv"
  69. //tmpData := &serverproto.ActivitiesDetailData{}
  70. //model.GetDecodeMessage(tmpData, testStr)
  71. //
  72. //testStr = "Cg0IARAQGgcIgLH77KcvIPqizYiSLygOOgQISBABOgQIXxABOgQIYxABOgQIRxABOgQICBABOgQIBRABOgQIBBABOgQIBhABOgQIdhABOgQIaBABOgQIBxABOgQIcxABOgQIbhABOgQIbBABOgQIAhABOgQIZRABOgQIahABOgQIYhABOgQIShABOgQIARABOgQIdRABOgQIaRABOgQIbxABOgQIbRABOgQIZxABOgQIcBABOgQIAxABOgQIchABOgQIZhABOgQIaxABOgQIcRABOgQIdBABOgQISRABQg8DCTgBAgsSJBYoFylaXF0="
  73. //tmpData1 := &serverproto.RoleActivity{}
  74. //model.GetDecodeMessage(tmpData1, testStr)
  75. runtime.GOMAXPROCS(runtime.NumCPU() / 3)
  76. //
  77. err := util.InitLog(1, 0, "./log", "test", "")
  78. testModel.GetRoleFromRedis1()
  79. return
  80. //err := util.InitLog(1, 0, "./log", "test", "")
  81. //prof := profile.Start(profile.CPUProfile, profile.ProfilePath("./pprof/test.pprof"), profile.NoShutdownHook)
  82. err = service.ServerCmd.Parse(os.Args[1:])
  83. if err != nil {
  84. util.InfoF("err=%v", err)
  85. }
  86. if *service.MaxOnlineNumParam > 0 {
  87. testModel.MaxConnNum = *service.MaxOnlineNumParam
  88. }
  89. if *service.IPParam != "" {
  90. testModel.TmpIpStr = *service.IPParam
  91. }
  92. log.Printf("ip=%v", testModel.TmpIpStr)
  93. //读取机器人压测数据文件
  94. TestRobotBenchmark(&testModel.BenchmarkMsgDataList)
  95. msgList := testModel.BenchmarkMsgDataList
  96. if len(msgList) > 0 {
  97. totalTime := msgList[len(msgList)-1].MsgTime - msgList[0].MsgTime
  98. totalTime /= 1000
  99. util.InfoF("msgTotalTime=%v(s) %v(m) count=%v", totalTime, totalTime/60, len(msgList))
  100. }
  101. //t := time.Now().Unix()
  102. t := 1
  103. //log.Printf("begin:%v %v", t, *service.TempParam)
  104. //log.Println("begin:", t, *service.TempParam)
  105. testModel.TestBeginTime = util.GetTimeMilliseconds()
  106. //for i := 0; i < testModel.MaxConnNum; i++ {
  107. // go testModel.Client(int(t) + i)
  108. //}
  109. for i := 0; i < testModel.MaxConnNum; i++ {
  110. go testModel.Client(int(t) + i)
  111. }
  112. //client(int(t) + maxConnNum)
  113. service.WaitExitSignal()
  114. }
  115. func TestRobotBenchmark(msgDtaList *[]*testModel.RobotBenchmarkSt) {
  116. f, err := os.Open("./game.log")
  117. if err != nil {
  118. return
  119. }
  120. defer f.Close()
  121. fd, err := ioutil.ReadAll(f)
  122. if err != nil {
  123. return
  124. }
  125. fileStr := string(fd)
  126. uniMsgId := set.New(set.NonThreadSafe)
  127. fileStrList := strings.Split(fileStr, "\n")
  128. for idx := 0; idx < len(fileStrList); idx++ {
  129. tmpStr := fileStrList[idx]
  130. if !strings.Contains(tmpStr, "receivemsg") {
  131. continue
  132. }
  133. tmpStrList := strings.Split(tmpStr, " ")
  134. msgIdStr := getTextData(tmpStrList[5])
  135. msgId, _ := model.Str2Num(msgIdStr)
  136. msgDataStr := getTextData(tmpStrList[6])
  137. msgData, _ := base64.StdEncoding.DecodeString(msgDataStr)
  138. msgTimeStr := getTextData(tmpStrList[7])
  139. msgTime, _ := model.Str2NumU64(msgTimeStr)
  140. *msgDtaList = append(*msgDtaList, &testModel.RobotBenchmarkSt{
  141. MsgTime: msgTime,
  142. MsgId: uint32(msgId),
  143. MsgData: msgData,
  144. })
  145. uniMsgId.Add(msgId)
  146. }
  147. //for _, data := range uniMsgId.List() {
  148. // util.InfoF("receivemsg sendmsgid=%v", data.(int)+1)
  149. //}
  150. }
  151. func getTextData(str string) string {
  152. retStr := ""
  153. findIdx := strings.Index(str, "=")
  154. for idx := findIdx + 1; idx < len(str); idx++ {
  155. retStr += string(str[idx])
  156. }
  157. return retStr
  158. }