ninjalog

package
v0.0.0-...-e560ebb Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package ninjalog provides ninja_log parser

It support ninja log v5.

# ninja log v5
<start>	<end>	<restat>	<target>	<cmdhash>

where

<start> = start time since ninja starts in msec.
<end>   = end time since ninja starts in msec.
<restat> = restat time in epoch.
<target> = target (output) filename
<cmdhash> = hash of command line (?)

It assumes steps in the last build will be ascendent order of <end>.

It also supports metadata added by chromium's buildbot compile.py. metadata is added after

# end of ninja log

and written in json format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dump

func Dump(w io.Writer, steps []Step) error

Dump dumps steps as ninja log v5 format in w.

func Flow

func Flow(steps []Step, sortByEnd bool) [][]Step

Flow returns concurrent steps by time. steps in every []Step will not have time overlap. steps will be sorted by start or end time depends on |sortByEnd|.

func ToProto

func ToProto(info *NinjaLog) []*npb.NinjaTask

ToProto converts ninjalog to structs of protocol buffer.

func TotalTime

func TotalTime(steps []Step) (startupTime, endTime, cpuTime time.Duration)

TotalTime returns startup time and end time of ninja, and accumulated time of all tasks.

func WeightedTime

func WeightedTime(steps []Step) map[string]time.Duration

WeightedTime calculates weighted time, which is elapsed time with each segment divided by the number of tasks that were running in paralle. This makes it a much better approximation of how "important" a slow step was. For example, A link that is entirely or mostly serialized will have a weighted time that is the same or similar to its elapsed time. A compile that runs in parallel with 999 other compiles will have a weighted time that is tiny.

Types

type ByDuration

type ByDuration struct{ Steps }

ByDuration is used to sort by duration.

func (ByDuration) Less

func (s ByDuration) Less(i, j int) bool

Less is used to sort a list by Steps Duration.

type ByEnd

type ByEnd struct{ Steps }

ByEnd is used to sort by end time.

func (ByEnd) Less

func (s ByEnd) Less(i, j int) bool

Less is used to sort a list by Steps End time.

type ByWeightedTime

type ByWeightedTime struct {
	Weighted map[string]time.Duration
	Steps
}

ByWeightedTime is used to sort by weighted time.

func (ByWeightedTime) Less

func (s ByWeightedTime) Less(i, j int) bool

Less is used to sort a list by Weighted duration.

type Metadata

type Metadata struct {
	// BuildID is identifier of build used in buildbucket api v2 (go/buildbucket-api-v2)
	// Or some random number representing an invocation of build.
	BuildID int64 `json:"build_id"`

	// Platform is platform of buildbot.
	Platform string `json:"platform"`

	// Argv is argv of compile.py
	Argv []string `json:"argv"`

	// Cwd is current working directory of compile.py
	Cwd string `json:"cwd"`

	// Compiler is compiler used.
	Compiler string `json:"compiler"`

	// Cmdline is command line of ninja.
	Cmdline []string `json:"cmdline"`

	// Exit is exit status of ninja.
	Exit int `json:"exit"`

	// Hostname is hostname of builder.
	Hostname string `json:"hostname"`

	// StepName is stepname to distinguish multiple compile steps in a build.
	StepName string `json:"step_name"`

	// CPUCore is the number of cpu cores.
	CPUCore int32 `json:"cpu_core"`

	// BuildConfigs is content of args.gn.
	BuildConfigs map[string]string `json:"build_configs"`

	// Env is environment variables.
	Env map[string]string `json:"env"`

	// CompilerProxyInfo is a path name of associated compiler_proxy.INFO log.
	CompilerProxyInfo string `json:"compiler_proxy_info"`

	// Jobs is number of parallel process in a build.
	Jobs int `json:"jobs"`

	// Build target.
	Targets []string `json:"targets"`

	// Raw is raw string for metadata.
	Raw string
	// Error is error message of parsing metadata.
	Error string
}

Metadata is data added by compile.py or json sent from ninjalog uploader.

type NinjaLog

type NinjaLog struct {
	// Filename is a filename of ninja_log.
	Filename string

	// Start is start line of the last build in ninja_log file.
	Start int

	// Steps contains steps in the last build in ninja_log file.
	Steps []Step

	// Metadata is additional data found in ninja_log file.
	Metadata Metadata
}

NinjaLog is parsed data of ninja_log file.

func Parse

func Parse(fname string, r io.Reader) (*NinjaLog, error)

Parse parses .ninja_log file, with chromium's compile.py metadata.

type Stat

type Stat struct {
	Type     string
	Count    int
	Time     time.Duration
	Weighted time.Duration
}

Stat represents statistics for build step.

func StatsByType

func StatsByType(steps []Step, weighted map[string]time.Duration, typeOf func(Step) string) []Stat

StatsByType summarizes build step statistics with weighted and typeOf. Stats is sorted by Weighted, longer first.

type Step

type Step struct {
	Start time.Duration
	End   time.Duration
	// modification time, but not convertible to absolute real time.
	// on POSIX, time_t is used, but on Windows different type is used.
	// htts://github.com/martine/ninja/blob/master/src/timestamp.h
	Restat  int
	Out     string
	CmdHash string

	// other outs for the same CmdHash if dedup'ed.
	Outs []string
}

Step is one step in ninja_log file. time is measured from ninja start time.

func Dedup

func Dedup(steps []Step) []Step

Dedup dedupes steps. step may have the same cmd hash. Dedup only returns the first step for these steps. steps will be sorted by start time.

func (Step) Duration

func (s Step) Duration() time.Duration

Duration reports step's duration.

type Steps

type Steps []Step

Steps is a list of Step. It could be used to sort by start time.

func (Steps) Len

func (s Steps) Len() int

func (Steps) Less

func (s Steps) Less(i, j int) bool

func (Steps) Reverse

func (s Steps) Reverse()

Reverse reverses steps. It would be more efficient if steps is already sorted than using sort.Reverse.

func (Steps) Swap

func (s Steps) Swap(i, j int)

type Trace

type Trace struct {
	Name      string                 `json:"name"`
	Category  string                 `json:"cat"`
	EventType string                 `json:"ph"`
	Timestamp int                    `json:"ts"`  // microsecond
	Duration  int                    `json:"dur"` // microsecond
	ProcessID int                    `json:"pid"`
	ThreadID  int                    `json:"tid"`
	Args      map[string]interface{} `json:"args"`
}

Trace is an entry of trace format. https://code.google.com/p/trace-viewer/

func ToTraces

func ToTraces(steps [][]Step, pid int) []Trace

ToTraces converts Flow outputs into trace log.

Jump to

Keyboard shortcuts

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