pkg / profile

Simple profiling for Go
BSD 2-Clause "Simplified" License
1.99k stars 124 forks source link

dealing with `profile` (`Config`) object not being exported #25

Closed yoiang closed 8 years ago

yoiang commented 8 years ago

With the switch over to pkg/profile the library now does not allow intermediate handling of configuration objects.

Previously I could assemble configuration settings and pass them onto Start, eg: (in psuedocode)

    variable profiling options
    switch (command line profiling type option) {
        assign profiling type to profiling options
    }
    if (provided output destination) {
        assign specified destination to profiling options
    }
    ....Start(profiling options)

Now that the profile object is not exporting I am unclear how to code this same setup in a way that doesn't reek of poor code re-duplication RE: the Start call:

func StartWithDestination(profileType ProfileType, toOutputFolder string) interface {
    Stop()
} {

    switch profileType {
    case CPU:
        return profile.Start(profile.CPUProfile, profile.ProfilePath(toOutputFolder))

    case Memory:
        return profile.Start(profile.MemProfile, profile.ProfilePath(toOutputFolder))

    case Blocking:
        return profile.Start(profile.BlockProfile, profile.ProfilePath(toOutputFolder))
    }

    return nil
}

func Start(profileType ProfileType) interface {
    Stop()
} {
    switch profileType {
    case CPU:
        return profile.Start(profile.CPUProfile)

    case Memory:
        return profile.Start(profile.MemProfile)

    case Blocking:
        return profile.Start(profile.BlockProfile)
    }

    return nil
}

...

if len(toOutputFolder) > 0 {
    return profiler.StartWithDestination(profileType, toOutputFolder)
}
return profiler.Start(profileType)

Is there a way I can be smarter with the new library?

davecheney commented 8 years ago

If the profile type was made public, the you could create a []func(*Profile). Would that work?

On Mon, 15 Aug 2016, 03:24 Ian G notifications@github.com wrote:

With the switch over to pkg/profile the library now does not allow intermediate handling of configuration objects.

Previously I could assemble configuration settings and pass them onto Start, eg: (in psuedocode)

variable profiling options
switch (command line profiling type option) {
    assign profiling type to profiling options
}
if (provided output destination) {
    assign specified destination to profiling options
}
....Start(profiling options)

Now that the profile object is not exporting I am unclear how to code this same setup in a way that doesn't reek of poor code re-duplication RE: the Start call:

func StartWithDestination(profileType ProfileType, toOutputFolder string) interface { Stop() } {

switch profileType {
case CPU:
    return profile.Start(profile.CPUProfile, profile.ProfilePath(toOutputFolder))

case Memory:
    return profile.Start(profile.MemProfile, profile.ProfilePath(toOutputFolder))

case Blocking:
    return profile.Start(profile.BlockProfile, profile.ProfilePath(toOutputFolder))
}

return nil

} func Start(profileType ProfileType) interface { Stop() } { switch profileType { case CPU: return profile.Start(profile.CPUProfile)

case Memory:
    return profile.Start(profile.MemProfile)

case Blocking:
    return profile.Start(profile.BlockProfile)
}

return nil

}

... if len(toOutputFolder) > 0 { return profiler.StartWithDestination(profileType, toOutputFolder) }return profiler.Start(profileType)

Is there a way I can be smarter with the new library?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pkg/profile/issues/25, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAcAwRtoUoO6W_bJaQEqj5Zdqg_cQnCks5qf09dgaJpZM4Jj8UC .

yoiang commented 8 years ago

That would be perfect, thank you! :) On Sun, Aug 14, 2016 at 6:20 PM Dave Cheney notifications@github.com wrote:

If the profile type was made public, the you could create a []func(*Profile). Would that work?

On Mon, 15 Aug 2016, 03:24 Ian G notifications@github.com wrote:

With the switch over to pkg/profile the library now does not allow intermediate handling of configuration objects.

Previously I could assemble configuration settings and pass them onto Start, eg: (in psuedocode)

variable profiling options switch (command line profiling type option) { assign profiling type to profiling options } if (provided output destination) { assign specified destination to profiling options } ....Start(profiling options)

Now that the profile object is not exporting I am unclear how to code this same setup in a way that doesn't reek of poor code re-duplication RE: the Start call:

func StartWithDestination(profileType ProfileType, toOutputFolder string) interface { Stop() } {

switch profileType { case CPU: return profile.Start(profile.CPUProfile, profile.ProfilePath(toOutputFolder))

case Memory: return profile.Start(profile.MemProfile, profile.ProfilePath(toOutputFolder))

case Blocking: return profile.Start(profile.BlockProfile, profile.ProfilePath(toOutputFolder)) }

return nil } func Start(profileType ProfileType) interface { Stop() } { switch profileType { case CPU: return profile.Start(profile.CPUProfile)

case Memory: return profile.Start(profile.MemProfile)

case Blocking: return profile.Start(profile.BlockProfile) }

return nil }

... if len(toOutputFolder) > 0 { return profiler.StartWithDestination(profileType, toOutputFolder) }return profiler.Start(profileType)

Is there a way I can be smarter with the new library?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pkg/profile/issues/25, or mute the thread < https://github.com/notifications/unsubscribe-auth/AAAcAwRtoUoO6W_bJaQEqj5Zdqg_cQnCks5qf09dgaJpZM4Jj8UC

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pkg/profile/issues/25#issuecomment-239701350, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFedtEdoXv3mJDLh8Vc2ou3qxU6Jn1iks5qf5SWgaJpZM4Jj8UC .