1 Star 0 Fork 0

似是故人来/v8go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
cpuprofile_test.go 1.59 KB
一键复制 编辑 原始数据 按行查看 历史
似是故人来 提交于 2024-10-09 00:04 . 整理测试文件
// Copyright 2021 the v8go contributors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package v8go_test
import (
"testing"
v8 "gitee.com/hasika/v8go"
)
func TestCPUProfile(t *testing.T) {
t.Parallel()
ctx := v8.NewContextWithOptions(nil)
iso := ctx.Isolate()
defer iso.Dispose()
defer ctx.Close()
cpuProfiler := v8.NewCPUProfiler(iso)
defer cpuProfiler.Dispose()
title := "cpuprofiletest"
cpuProfiler.StartProfiling(title)
_, err := ctx.RunScript(profileScript, "script.js")
fatalIf(t, err)
val, err := ctx.Global().Get("start")
fatalIf(t, err)
fn, err := val.AsFunction()
fatalIf(t, err)
_, err = fn.Call(ctx.Global().Value)
fatalIf(t, err)
cpuProfile := cpuProfiler.StopProfiling(title)
defer cpuProfile.Delete()
if cpuProfile.GetTitle() != title {
t.Fatalf("expected title %s, but got %s", title, cpuProfile.GetTitle())
}
root := cpuProfile.GetTopDownRoot()
if root == nil {
t.Fatal("expected root not to be nil")
}
if root.GetFunctionName() != "(root)" {
t.Errorf("expected (root), but got %v", root.GetFunctionName())
}
if cpuProfile.GetDuration() <= 0 {
t.Fatalf("expected positive profile duration (%s)", cpuProfile.GetDuration())
}
}
func TestCPUProfile_Delete(t *testing.T) {
t.Parallel()
iso := v8.NewIsolate()
defer iso.Dispose()
cpuProfiler := v8.NewCPUProfiler(iso)
defer cpuProfiler.Dispose()
cpuProfiler.StartProfiling("cpuprofiletest")
cpuProfile := cpuProfiler.StopProfiling("cpuprofiletest")
cpuProfile.Delete()
// noop when called multiple times
cpuProfile.Delete()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/hasika/v8go.git
git@gitee.com:hasika/v8go.git
hasika
v8go
v8go
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385