| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- package main
- import (
- _ "context"
- "encoding/base64"
- "fmt"
- _ "github.com/olivere/elastic/v7"
- _ "github.com/olivere/elastic/v7/config"
- "io/ioutil"
- "log"
- "os"
- "rocommon/service"
- _ "rocommon/socket"
- _ "rocommon/socket/http"
- _ "rocommon/socket/tcp"
- _ "rocommon/socket/websocket"
- "rocommon/util"
- "roserver/baseserver/model"
- "roserver/baseserver/set"
- testModel "roserver/test/model"
- "runtime"
- "strings"
- )
- type IBase interface {
- SetVal()
- GetBase() *abase
- }
- type abase struct {
- aabase int
- }
- type a1 struct {
- abase
- aaa int
- }
- func (this *a1) SetVal() {
- this.aabase = 1
- }
- func (this *a1) GetBase() *abase {
- return &this.abase
- }
- type noCopy struct{}
- func (this *noCopy) Lock() {}
- func (this *noCopy) Unlock() {}
- type copyCool struct {
- Val int32
- noCopy noCopy
- }
- func main() {
- testCool := copyCool{Val: 10}
- t2 := testCool
- t2.Val = 20
- testCool.Val = 30
- fmt.Println(t2, testCool)
- return
- //tmpa1 := &a1{}
- //tmpa1.SetVal()
- //var tmpa2 IBase
- //tmpa2 = tmpa1
- //tmpVal := (*abase)(unsafe.Pointer(tmpa1))
- //tmpa2.GetBase().aabase = 2
- //log.Printf("tmpval=%v tmpa2=%v", tmpVal, tmpa2.GetBase().aabase)
- //return
- //uuuuid := 3132646845219
- //tmpUid := uuuuid >> 32
- //tmpUid1 := 3132646845219 - (tmpUid << 32)
- //log.Printf("tmpuid=%v | %v | %v", tmpUid, tmpUid<<32, tmpUid1)
- //
- //return
- //testStr := "CFwQDxiQmtnLpy8g6NjagbYvKAGCAQcIgPnhw6cv"
- //tmpData := &serverproto.ActivitiesDetailData{}
- //model.GetDecodeMessage(tmpData, testStr)
- //
- //testStr = "Cg0IARAQGgcIgLH77KcvIPqizYiSLygOOgQISBABOgQIXxABOgQIYxABOgQIRxABOgQICBABOgQIBRABOgQIBBABOgQIBhABOgQIdhABOgQIaBABOgQIBxABOgQIcxABOgQIbhABOgQIbBABOgQIAhABOgQIZRABOgQIahABOgQIYhABOgQIShABOgQIARABOgQIdRABOgQIaRABOgQIbxABOgQIbRABOgQIZxABOgQIcBABOgQIAxABOgQIchABOgQIZhABOgQIaxABOgQIcRABOgQIdBABOgQISRABQg8DCTgBAgsSJBYoFylaXF0="
- //tmpData1 := &serverproto.RoleActivity{}
- //model.GetDecodeMessage(tmpData1, testStr)
- runtime.GOMAXPROCS(runtime.NumCPU() / 3)
- //
- err := util.InitLog(1, 0, "./log", "test", "")
- testModel.GetRoleFromRedis1()
- return
- //err := util.InitLog(1, 0, "./log", "test", "")
- //prof := profile.Start(profile.CPUProfile, profile.ProfilePath("./pprof/test.pprof"), profile.NoShutdownHook)
- err = service.ServerCmd.Parse(os.Args[1:])
- if err != nil {
- util.InfoF("err=%v", err)
- }
- if *service.MaxOnlineNumParam > 0 {
- testModel.MaxConnNum = *service.MaxOnlineNumParam
- }
- if *service.IPParam != "" {
- testModel.TmpIpStr = *service.IPParam
- }
- log.Printf("ip=%v", testModel.TmpIpStr)
- //读取机器人压测数据文件
- TestRobotBenchmark(&testModel.BenchmarkMsgDataList)
- msgList := testModel.BenchmarkMsgDataList
- if len(msgList) > 0 {
- totalTime := msgList[len(msgList)-1].MsgTime - msgList[0].MsgTime
- totalTime /= 1000
- util.InfoF("msgTotalTime=%v(s) %v(m) count=%v", totalTime, totalTime/60, len(msgList))
- }
- //t := time.Now().Unix()
- t := 1
- //log.Printf("begin:%v %v", t, *service.TempParam)
- //log.Println("begin:", t, *service.TempParam)
- testModel.TestBeginTime = util.GetTimeMilliseconds()
- //for i := 0; i < testModel.MaxConnNum; i++ {
- // go testModel.Client(int(t) + i)
- //}
- for i := 0; i < testModel.MaxConnNum; i++ {
- go testModel.Client(int(t) + i)
- }
- //client(int(t) + maxConnNum)
- service.WaitExitSignal()
- }
- func TestRobotBenchmark(msgDtaList *[]*testModel.RobotBenchmarkSt) {
- f, err := os.Open("./game.log")
- if err != nil {
- return
- }
- defer f.Close()
- fd, err := ioutil.ReadAll(f)
- if err != nil {
- return
- }
- fileStr := string(fd)
- uniMsgId := set.New(set.NonThreadSafe)
- fileStrList := strings.Split(fileStr, "\n")
- for idx := 0; idx < len(fileStrList); idx++ {
- tmpStr := fileStrList[idx]
- if !strings.Contains(tmpStr, "receivemsg") {
- continue
- }
- tmpStrList := strings.Split(tmpStr, " ")
- msgIdStr := getTextData(tmpStrList[5])
- msgId, _ := model.Str2Num(msgIdStr)
- msgDataStr := getTextData(tmpStrList[6])
- msgData, _ := base64.StdEncoding.DecodeString(msgDataStr)
- msgTimeStr := getTextData(tmpStrList[7])
- msgTime, _ := model.Str2NumU64(msgTimeStr)
- *msgDtaList = append(*msgDtaList, &testModel.RobotBenchmarkSt{
- MsgTime: msgTime,
- MsgId: uint32(msgId),
- MsgData: msgData,
- })
- uniMsgId.Add(msgId)
- }
- //for _, data := range uniMsgId.List() {
- // util.InfoF("receivemsg sendmsgid=%v", data.(int)+1)
- //}
- }
- func getTextData(str string) string {
- retStr := ""
- findIdx := strings.Index(str, "=")
- for idx := findIdx + 1; idx < len(str); idx++ {
- retStr += string(str[idx])
- }
- return retStr
- }
|