sheeps

package module
v0.0.0-...-cd714d9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2023 License: MIT Imports: 4 Imported by: 0

README

gsupersheeps

介绍

supersheeps服务器压力测试工具使用的golang插件,支持linux和windows,可以使用golang作为项目开发语言。linux下使用cgo,编译需要gcc环境,windows下使用syscall。

安装

go get gitee.com/lutianming/gsupersheeps

代码示例
//main.go
package main

import (
	sheeps "gitee.com/lutianming/gsupersheeps"
)

type User struct {
	sheeps.BaseUser
	tcpsock uintptr
}

func (U *User) EventStart(taskcfg *sheeps.TaskConfig, user_number int) {
	U.Log(2, "EventStart")
}

func (U *User) EventConnectOpen(ip string, port int, protocol int) {
	U.Log(2, "EventConnectOpen")
	U.tcpsock = U.SocketConnect(ip, port, protocol)
	U.PlayPause()
}

func (U *User) EventConnectMade(hsock uintptr) {
	U.Log(2, "EventConnectMade")
	U.PlayNoraml()
}

func (U *User) EventConnectFailed(hsock uintptr, errno int) {
}

func (U *User) EventConnectSend(ip string, port int, data []byte, protocol int) {
	U.Log(2, "EventConnectSend:"+string(data))
	U.SocketSend(U.tcpsock, data, len(data))
	U.PlayPause()
}

func (U *User) EventConnectRecved(hsock uintptr, data []byte) {
	U.Log(2, "EventConnectRecved:"+string(data))
	U.PlayNoraml()
}

func (U *User) EventConnectClose(ip string, port int, protocol int) {
}

func (U *User) EventConnectClosed(hsock uintptr, errno int) {
}

func (U *User) EventTimeOut() {
}

func (U *User) EventStop(err string) {
	U.Log(2, "EventStop:"+err)
}

func create_user(user_handle uintptr) sheeps.BaseUserCall {
	user := new(User)
	return user
}

func main() {
	sheeps.LoadEngin(0, 0, true, "", create_user)
}
使用

1.安装golang环境 2.创建项目文件夹,如project
3.在project下创建main.go,拷贝示例代码
4.下载supersheeps最新版本,解压动态库Sheeps.dll/libsheeps.so和sheeps.ini到project目录
5.依次执行命令

	go mod init test  
	go get gitee.com/lutianming/gsupersheeps  
	go mod vendor  
	go build

6.启动可执行程序 test

Q&A

1.vscode调试golang代码时,调试控制台看不到日志输出 答:在launch.json添加配置 "console": "integratedTerminal"

{
    "version": "0.2.0",
    "configurations": [
    
        {
            "name": "debug go",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${fileDirname}",
            "console": "integratedTerminal"
        }
    ]
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadEngin

func LoadEngin(project_id int, group_id int, local_server bool, config_file string, create_user func(uintptr) BaseUserCall)

func Task_start_callback

func Task_start_callback(task_id int, project_id int, machine_id int, run_number int, parms *C.char)

func Task_stop_callback

func Task_stop_callback(task_id C.int)

func Task_user_create_callback

func Task_user_create_callback(user_handle uintptr, ud *unsafe.Pointer, task_id int)

Types

type BaseUser

type BaseUser struct {
	// contains filtered or unexported fields
}

func (*BaseUser) ConfigGetBool

func (B *BaseUser) ConfigGetBool(section string, key string, def bool) bool

func (*BaseUser) ConfigGetNumber

func (B *BaseUser) ConfigGetNumber(section string, key string, def int) int

func (*BaseUser) ConfigGetString

func (B *BaseUser) ConfigGetString(section string, key string, def string) string

func (*BaseUser) GetHostByName

func (B *BaseUser) GetHostByName(name string)

func (*BaseUser) KcpCreate

func (B *BaseUser) KcpCreate(hsock uintptr, conv int, stream int)

func (*BaseUser) KcpDebug

func (B *BaseUser) KcpDebug(hsock uintptr) string

func (*BaseUser) KcpNodelay

func (B *BaseUser) KcpNodelay(hsock uintptr, nodelay int, interval int, resend int, nc int)

func (*BaseUser) KcpWndsize

func (B *BaseUser) KcpWndsize(hsock uintptr, snwd int, rcwn int)

func (*BaseUser) Log

func (B *BaseUser) Log(log_level int, msg string)

func (*BaseUser) Microsecond

func (B *BaseUser) Microsecond() int64

func (*BaseUser) PlayAction

func (B *BaseUser) PlayAction(action int)

func (*BaseUser) PlayBack

func (B *BaseUser) PlayBack(step int)

func (*BaseUser) PlayFast

func (B *BaseUser) PlayFast(fast bool)

func (*BaseUser) PlayNoStop

func (B *BaseUser) PlayNoStop()

func (*BaseUser) PlayNoraml

func (B *BaseUser) PlayNoraml()

func (*BaseUser) PlayOver

func (B *BaseUser) PlayOver()

func (*BaseUser) PlayPause

func (B *BaseUser) PlayPause()

func (*BaseUser) PlayStep

func (B *BaseUser) PlayStep() int

func (*BaseUser) PlayStepNote

func (B *BaseUser) PlayStepNote() string

func (*BaseUser) PlayStepSession

func (B *BaseUser) PlayStepSession() int

func (*BaseUser) PlayStop

func (B *BaseUser) PlayStop(err string)

func (*BaseUser) ReportAPIRecv

func (B *BaseUser) ReportAPIRecv(api string, flow int, count int)

func (*BaseUser) ReportAPIResponse

func (B *BaseUser) ReportAPIResponse(api string, response_time int)

func (*BaseUser) ReportAPISend

func (B *BaseUser) ReportAPISend(api string, flow int, count int)

func (*BaseUser) ReportCounter

func (B *BaseUser) ReportCounter(key string, value int, report_type int, space_time int)

func (*BaseUser) ReportOffline

func (B *BaseUser) ReportOffline()

func (*BaseUser) ReportOnline

func (B *BaseUser) ReportOnline()

func (*BaseUser) ReportOverMessage

func (B *BaseUser) ReportOverMessage(message string)

func (*BaseUser) SocketClose

func (B *BaseUser) SocketClose(hsock uintptr)

func (*BaseUser) SocketConnect

func (B *BaseUser) SocketConnect(ip string, port int, protocol int) uintptr

func (*BaseUser) SocketLocalAddrGet

func (B *BaseUser) SocketLocalAddrGet(hsock uintptr) (string, int)

func (*BaseUser) SocketPeerAddrGet

func (B *BaseUser) SocketPeerAddrGet(hsock uintptr) (string, int)

func (*BaseUser) SocketPeerAddrSet

func (B *BaseUser) SocketPeerAddrSet(hsock uintptr, ip string, port int)

func (*BaseUser) SocketSend

func (B *BaseUser) SocketSend(hsock uintptr, data []byte, len int) int8

type BaseUserCall

type BaseUserCall interface {
	EventStart(taskcfg *TaskConfig, user_number int)
	EventConnectOpen(ip string, port int, protocol int)
	EventConnectMade(hsock uintptr)
	EventConnectFailed(hsock uintptr, errno int)
	EventConnectSend(ip string, port int, data []byte, protocol int)
	EventConnectRecved(hsock uintptr, data []byte)
	EventConnectClose(ip string, port int, protocol int)
	EventConnectClosed(hsock uintptr, errno int)
	EventTimeOut()
	EventStop(errmsg string)
	// contains filtered or unexported methods
}

type TaskConfig

type TaskConfig struct {
	Task_id    int
	Project_id int
	Machine_id int
	Run_number int
	Parms      string
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL