Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional CPUProfile values #341

Merged
merged 1 commit into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions cpuprofilenode.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
package v8go

type CPUProfileNode struct {
// The id of the current node, unique within the tree.
nodeId int

// The id of the script where the function originates.
scriptId int

// The resource name for script from where the function originates.
scriptResourceName string

Expand All @@ -17,13 +23,29 @@ type CPUProfileNode struct {
// The number of the column where the function originates.
columnNumber int

// The count of samples where the function was currently executing.
hitCount int

// The bailout reason for the function if the optimization was disabled for it.
bailoutReason string

// The children node of this node.
children []*CPUProfileNode

// The parent node of this node.
parent *CPUProfileNode
}

// Returns node id.
func (c *CPUProfileNode) GetNodeId() int {
return c.nodeId
}

// Returns id for script from where the function originates.
func (c *CPUProfileNode) GetScriptId() int {
return c.scriptId
}

// Returns function name (empty string for anonymous functions.)
func (c *CPUProfileNode) GetFunctionName() string {
return c.functionName
Expand All @@ -44,6 +66,16 @@ func (c *CPUProfileNode) GetColumnNumber() int {
return c.columnNumber
}

// Returns count of samples where the function was currently executing.
func (c *CPUProfileNode) GetHitCount() int {
return c.hitCount
}

// Returns the bailout reason for the function if the optimization was disabled for it.
func (c *CPUProfileNode) GetBailoutReason() string {
return c.bailoutReason
}

// Retrieves the ancestor node, or nil if the root.
func (c *CPUProfileNode) GetParent() *CPUProfileNode {
return c.parent
Expand Down
4 changes: 4 additions & 0 deletions cpuprofiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,14 @@ func (c *CPUProfiler) StopProfiling(title string) *CPUProfile {

func newCPUProfileNode(node *C.CPUProfileNode, parent *CPUProfileNode) *CPUProfileNode {
n := &CPUProfileNode{
nodeId: int(node.nodeId),
scriptId: int(node.scriptId),
scriptResourceName: C.GoString(node.scriptResourceName),
functionName: C.GoString(node.functionName),
lineNumber: int(node.lineNumber),
columnNumber: int(node.columnNumber),
hitCount: int(node.hitCount),
bailoutReason: C.GoString(node.bailoutReason),
parent: parent,
}

Expand Down
4 changes: 4 additions & 0 deletions v8go.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,14 @@ CPUProfileNode* NewCPUProfileNode(const CpuProfileNode* ptr_) {

CPUProfileNode* root = new CPUProfileNode{
ptr_,
ptr_->GetNodeId(),
ptr_->GetScriptId(),
ptr_->GetScriptResourceNameStr(),
ptr_->GetFunctionNameStr(),
ptr_->GetLineNumber(),
ptr_->GetColumnNumber(),
ptr_->GetHitCount(),
ptr_->GetBailoutReason(),
count,
children,
};
Expand Down
4 changes: 4 additions & 0 deletions v8go.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ typedef struct {

typedef struct CPUProfileNode {
CpuProfileNodePtr ptr;
unsigned nodeId;
int scriptId;
const char* scriptResourceName;
const char* functionName;
int lineNumber;
int columnNumber;
unsigned hitCount;
const char* bailoutReason;
int childrenCount;
struct CPUProfileNode** children;
} CPUProfileNode;
Expand Down