Documentation ¶
Overview ¶
Package asten provides functionalities for runtime performance evaluation.
Statistics are organized in Groups. Each group contains one or more Profiles. Each Profile may be composite, i.e., a collection of sub-profiles. An example structure may be:
Group 1 ├ Profile 1.1 └ Profile 1.2 ├ Sub-Profile 1.2.1 └ Sub-Profile 1.2.2 Group 2 └ Profile 2.1 └ Sub-Profile 2.1.1 └ Sub-Profile 2.1.1.1
Statistics are presented in a tabular manner.
Index ¶
- func PrintGroups()
- func SetCoresNumber(n uint64)
- func SetDefaultConditionName(name string)
- func SetLogLevel(level slog.Level)
- func SetLogger(newlogger *slog.Logger)
- type GroupSt
- type ProfileBuilder
- func (pb *ProfileBuilder) AddComposition() *ProfileBuilder
- func (pb *ProfileBuilder) AddMemory() *ProfileBuilder
- func (pb *ProfileBuilder) AddMultiThreading() *ProfileBuilder
- func (pb ProfileBuilder) Copy() *ProfileBuilder
- func (pb *ProfileBuilder) NewProfile(pname string) *ProfileSt
- func (pb *ProfileBuilder) RemoveComposition() *ProfileBuilder
- func (pb *ProfileBuilder) RemoveMemory() *ProfileBuilder
- func (pb *ProfileBuilder) RemoveMultiThreading() *ProfileBuilder
- func (pb ProfileBuilder) String() string
- func (pb *ProfileBuilder) WithNCores(n uint64) *ProfileBuilder
- func (pb *ProfileBuilder) WithNThreads(n uint64) *ProfileBuilder
- func (pb *ProfileBuilder) WithParentGroup(g *GroupSt) *ProfileBuilder
- func (pb *ProfileBuilder) WithParentProfile(p *ProfileSt) *ProfileBuilder
- type ProfileSt
- func (p *ProfileSt) Builder() *ProfileBuilder
- func (p *ProfileSt) MakeComposite() *ProfileSt
- func (p *ProfileSt) Print()
- func (p *ProfileSt) Profile(pname string) *ProfileSt
- func (p *ProfileSt) SetBuilder(pb *ProfileBuilder)
- func (p *ProfileSt) StartTimer() *Timer
- func (p *ProfileSt) String() string
- type Timer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PrintGroups ¶
func PrintGroups()
PrintGroups generates and prints in a recursive manner tables containing info regarding all the declared groups and their profiles.
func SetCoresNumber ¶
func SetCoresNumber(n uint64)
SetCoresNumber sets the number of cores available when calculating statistics. Default value is initialized using runtime.NumCPU.
func SetDefaultConditionName ¶
func SetDefaultConditionName(name string)
SetDefaultConditionName sets the name given to groups and profiles when a name is not specified. The default value is "base".
func SetLogLevel ¶
SetLogLevel sets the level for asten messages unless SetLogger has been called. The default log level is the zero value of slog.LevelVar.
func SetLogger ¶
SetLogger set the logger used by asten. SetLogLevel will not be enforced if a custom logger is used.
Types ¶
type GroupSt ¶
type GroupSt struct { *sync.RWMutex // manages concurrent access // contains filtered or unexported fields }
GroupSt (Group Struct) ¶
Represents a group which is a collection of profiles whose statistics are to be compared. It is designed to be thread safe. Its zero value has no meaning and should not be used.
func Group ¶
Group returns the group with name: gname. If a group called gname exists then it will be returned otherwise a new group is created using a NewProfileBuilder and returned.
func (*GroupSt) Builder ¶
func (g *GroupSt) Builder() *ProfileBuilder
Builder returns a pointer to the builder used to generate new profiles for group g.
func (*GroupSt) Print ¶
func (g *GroupSt) Print()
Print generates and prints in a recursive manner tables containing info about the group g and its profiles.
func (*GroupSt) Profile ¶
Profile returns the profile named pname belonging to group g. If no such profile exists it is created using the group builder (see GroupSt.Builder).
func (*GroupSt) SetBuilder ¶
func (g *GroupSt) SetBuilder(pb *ProfileBuilder)
SetBuilder sets the builder used by group g to generate new profiles to pb.
func (*GroupSt) StartTimer ¶
StartTimer is equivalent to calling:
g.Profile(default_condition_name).StartTimer()
(see SetDefaultConditionName).
type ProfileBuilder ¶
type ProfileBuilder struct {
// contains filtered or unexported fields
}
ProfileBuilder ¶
ProfileBuilder implements a builder pattern to generate new profiles. A ProfileBuilder can have either a parent profile or a parent group (which can be set using ProfileBuilder.WithParentGroup or ProfileBuilder.WithParentProfile) that affect the behaviour of ProfileBuilder.NewProfile. Its zero value has no particular meaning and should not be used. A ProfileBuilder should always be instantiated using NewProfileBuilder.
func NewProfileBuilder ¶
func NewProfileBuilder() *ProfileBuilder
NewProfileBuilder returns a ProfileBuilder which will generate profiles that are:
- non-composite
- memoryless
- sigle-threaded
func (*ProfileBuilder) AddComposition ¶
func (pb *ProfileBuilder) AddComposition() *ProfileBuilder
AddComposition modifies and returns pb, making any new profile generated by calling ProfileBuilder.NewProfile a composite profile.
func (*ProfileBuilder) AddMemory ¶
func (pb *ProfileBuilder) AddMemory() *ProfileBuilder
AddMemory modifies and returns pb, making any new profile generated by calling ProfileBuilder.NewProfile a memory full profile.
func (*ProfileBuilder) AddMultiThreading ¶
func (pb *ProfileBuilder) AddMultiThreading() *ProfileBuilder
AddMultiThreading modifies and returns pb, making any new profile generated by calling ProfileBuilder.NewProfile a multi-threaded profile with n threads, where n is the number of cores (see SetCoresNumber).
func (ProfileBuilder) Copy ¶
func (pb ProfileBuilder) Copy() *ProfileBuilder
Copy generates and returns a deep copy of pb.
func (*ProfileBuilder) NewProfile ¶
func (pb *ProfileBuilder) NewProfile(pname string) *ProfileSt
NewProfile generates a new profile whose characteristics are based on pb's state. If pb is the builder for a profile or a group, the generated profile is automatically added to it. The generated profile will have a builder with the same characteristics as pb except it will always be non-composite.
func (*ProfileBuilder) RemoveComposition ¶
func (pb *ProfileBuilder) RemoveComposition() *ProfileBuilder
RemoveComposition modifies and returns pb, making any new profile generated by calling ProfileBuilder.NewProfile a non-composite profile.
func (*ProfileBuilder) RemoveMemory ¶
func (pb *ProfileBuilder) RemoveMemory() *ProfileBuilder
RemoveMemory modifies and returns pb, making any new profile generated by calling ProfileBuilder.NewProfile a memoryless profile.
func (*ProfileBuilder) RemoveMultiThreading ¶
func (pb *ProfileBuilder) RemoveMultiThreading() *ProfileBuilder
RemoveMultiThreading modifies and returns pb, making any new profile generated by calling ProfileBuilder.NewProfile a single-threaded profile.
func (ProfileBuilder) String ¶
func (pb ProfileBuilder) String() string
func (*ProfileBuilder) WithNCores ¶
func (pb *ProfileBuilder) WithNCores(n uint64) *ProfileBuilder
WithNThreads is equivalent to ProfileBuilder.WithNThreads but no check is done on n.
func (*ProfileBuilder) WithNThreads ¶
func (pb *ProfileBuilder) WithNThreads(n uint64) *ProfileBuilder
WithNThreads modifies and returns pb, making any new profile generated by calling ProfileBuilder.NewProfile a multi-threaded profile with n threads. If n > number of cores (see SetCoresNumber) then n is set to the number of cores.
func (*ProfileBuilder) WithParentGroup ¶
func (pb *ProfileBuilder) WithParentGroup(g *GroupSt) *ProfileBuilder
WithParentGroup modifies and returns pb, setting its parent group to g. Any profile generated calling [NewProfile] will be added to the profiles of group g. If pb had a parent profile, it will be deleted.
func (*ProfileBuilder) WithParentProfile ¶
func (pb *ProfileBuilder) WithParentProfile(p *ProfileSt) *ProfileBuilder
WithParentProfile modifies and returns pb, setting its parent profile to p. Any profile generated calling [NewProfile] will be added to the sub-profiles of profile p. If pb had a parent group, it will be deleted.
type ProfileSt ¶
ProfileSt (Profile Struct) ¶
Represents a profile which groups and elaborates info obtained using timers. A profile can be:
- non-composite
- composite: it represent a collection of subprofiles.
- single-threaded
- multi-threaded: in this case the effective runtime of the profile will simply be divided by the number of threads specified.
- memory full: it keeps memory of the start and the end of all recorded samples. This avoids updating the statistics each time a sample is recirded.
- memoryless: when recording a sample statistics are updated and the sample discarded.
Its zero value has no meaning and should not be used. A profile should always be instantiated either using Profile, GroupSt.Profile or a custom builder ProfileBuilder.
func Profile ¶
Profile is equivalent to calling GroupSt.Profile on the group with the default condition name (see SetDefaultConditionName), i.e., it is equivalent to:
Group(default_condition_name).Profile(pname)
func (*ProfileSt) Builder ¶
func (p *ProfileSt) Builder() *ProfileBuilder
Builder returns a pointer to the builder used to generate new sub-profiles for profile p.
func (*ProfileSt) MakeComposite ¶
MakeComposite transforms profile p from non-composite to composite. Any sample recorded while p was non-composite will be lost.
func (*ProfileSt) Print ¶
func (p *ProfileSt) Print()
Print generates and prints in a recursive manner tables containing info about the profile p and its sub-profiles.
func (*ProfileSt) Profile ¶
Profile returns the sub-profile named pname belonging to profile p. If no such profile exists it is created using the profile builder (see ProfileSt.Builder).
func (*ProfileSt) SetBuilder ¶
func (p *ProfileSt) SetBuilder(pb *ProfileBuilder)
SetBuilder sets the builder used by profile p to generate new profiles to pb.
func (*ProfileSt) StartTimer ¶
StartTimer starts and returns a Timer relative to profile p.
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer ¶
Represents a running timer. Its zero value has no meaning. A Timer should always be instantiated by calling either GroupSt.StartTimer or ProfileSt.StartTimer.
func (*Timer) Stop ¶
func (t *Timer) Stop()
Stop is equivalent to calling:
t.StopAs([]string{default_condition_name})
(see SetDefaultConditionName).
func (*Timer) StopAs ¶
StopAs stops the timer and registers the sample in the profile that started the timer. Each element in conds corresponds to a sub-profile. For example:
t := Profile("p1").StartTimer() // ... t.StopAs("foo", "bar")
Will have the sample be registered in the sub-profile:
p1 └ foo └ bar
If bar is not composite, or:
p1 └ foo └ bar └ default_condition_name
If bar is composite (see SetDefaultConditionName).