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

Allow specifying more options from the command line #99

Merged

Conversation

mojomojomojo
Copy link
Contributor

/minidump:<seconds_until_minidump>
/samplerate:<sample_rate>
/symsearchpath:<symbol_search_path>
/symcachedir:<symbol_cache_dir>
/usesymserver:<use_symbol_server_p>
/symserver:<symbol_server_URL>

Specifying any of these will alter the behavior of the created sleepy.exe process, but will not result in the options (saved in the registry) being changed.

@CyberShadow
Copy link
Member

  • Please rebase, I'm seeing two almost-identical commits and a merge commit in the commit list.
  • I'm seeing some mixed tabs and spaces, ideally tabs should only be used for identation and spaces for alignment.
  • The _nosave variables are OK, but it would be much nicer if the state and logic could be encapsulated in a single place. Perhaps a class/struct template?

@CyberShadow
Copy link
Member

The _nosave variables are OK, but it would be much nicer if the state and logic could be encapsulated in a single place. Perhaps a class/struct template?

There's many ways to cut this cake, but the way I would do this personally is something like

template <typename T>
class OptionValue
{
    T configurationValue; /// value as stored in the Windows Registry
    std::optional<T> commandLineValue; /// value specified on the command line, if any
public:
    const T& get() { return commandLineValue ? *commandLineValue : configurationValue; }
    // (add constructor / setters)
};

This way there is no confusion as to which value should go where, and what the order of operations (loading/saving) is. Not sure if std::optional is available in the compiler we're using for automated builds, though.

@mojomojomojo
Copy link
Contributor Author

I tried rebasing, and that's what resulted in the extra commits. Even though this seems simple, I don't seem to know what I'm doing.

@CyberShadow CyberShadow force-pushed the config-options-from-commandline2 branch from bdfcb79 to 6aaa8fd Compare April 6, 2022 14:41
@CyberShadow
Copy link
Member

OK, I rebased it for you. Run git stash save if there are any uncommitted changes you want to keep, then run git fetch && git reset --hard mojomojomojo/config-options-from-commandline2 (replace mojomojomojo with the name of the remote pointing to your fork) to update your local reference.

…-configurables will only be temporarily overridden by cmdline switches
@mojomojomojo mojomojomojo force-pushed the config-options-from-commandline2 branch from 6aaa8fd to 6a578b0 Compare April 6, 2022 14:44
@mojomojomojo
Copy link
Contributor Author

I'm really sorry I keep screwing this part up.

@mojomojomojo
Copy link
Contributor Author

Is there a way to know things about the compiler environment without actually breaking the build?

@CyberShadow
Copy link
Member

I think you could look at appveyor.yml (and the files it references) or at a build log from CI, the information will probably be there (unless AppVeyor just chooses something for us).

@mojomojomojo
Copy link
Contributor Author

I don't think MSVC 2012 will support c++17.

@mojomojomojo
Copy link
Contributor Author

mojomojomojo commented Apr 6, 2022

I'll rework this change a bit. Sorry I've been treating the project like it's a bomb instead of something beautiful.

@mojomojomojo
Copy link
Contributor Author

I've made some changes in the manner you've recommended.

@CyberShadow
Copy link
Member

Thank you! From a quick glance I would suggest to remove all unused methods and to use a consistent code style.

@CyberShadow
Copy link
Member

Egyptian vs. Allman braces; I see you fixed it, thanks :)

@mojomojomojo mojomojomojo force-pushed the config-options-from-commandline2 branch from 188145c to a51d8fa Compare April 7, 2022 21:33
@mojomojomojo
Copy link
Contributor Author

As for unused methods, it seems to me that the ones left for Overridable<T> are the basics for utility. Even though there's nothing in there now that's using them, I used them when I was debugging the code.

@mojomojomojo
Copy link
Contributor Author

Are there things I should do to get this PR better-suited for merging?

@CyberShadow
Copy link
Member

Could you please add a commit which removes unused methods? That way, if they're ever needed for debugging in the future, they can be revived by reverting the commit.

@CyberShadow CyberShadow force-pushed the config-options-from-commandline2 branch from 6e34147 to 6e6e9bb Compare May 19, 2022 15:32
Copy link
Member

@CyberShadow CyberShadow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good otherwise, thanks!

Comment on lines 105 to 113
operator T() const
{
return GetValue();
}

T GetValue() const
{
return is_overridden ? override_value : config_value;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need exactly one of these, not both

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cast operator gets used any time you try to get the value in an expression. I like this kind of thing that C++ allows, but if you prefer the verbose kind, that's what I'll do.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, the problem is when you accidentally use the wrong way to get the value, and the code doing so looks completely correct... Too much magic/sugar can be a bad thing.

Comment on lines 97 to 102
T& operator =( const T& new_value )
{
is_overridden = false;
config_value = new_value;
return config_value;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need either this or SetConfigValue, not both. I would prefer the explicit method over the operator overload.

// setters
void SetConfigValue( const T& new_value )
{
is_overridden = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am on the fence if this is a good idea.

On one hand, if the profiler behaves some way, then you go into the settings, don't change anything, save & exit, and then the profiler behaves some other way, that's bad.

On the other hand, if you go into the settings and clearly see that the settings don't correspond to the profiler's current behavior, that's also bad.

Ideally the settings should indicate that some values are overridden. Maybe a pop-up message box shown when they're opened is sufficient.

Anyway, this is a pretty minor thing to worry about.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order for me to observe what you're describing, I'd have to specify command-line parameters when I invoke the app, and then go into the settings. This seems like a very niche case to me.

Is there a truly correct way to handle this?

Perhaps I could disable the GUI controls in the settings if the item is specified on the command line (as well as ignore the value of the control when we update the settings when the window closes).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would work, but I suggest something simpler such as showing a warning if any setting is overridden, and/or just refusing to open the settings dialog at all.

@CyberShadow
Copy link
Member

CyberShadow commented May 19, 2022

Wait, I just realized that the settings controls are initialized from the effective value, not the settings value. I'm not sure if that's right either. It avoids the UI conundrum above but replaces it with a different one - if you go into the settings, don't change anything, and exit, now future invocations of the profiler will behave differently.

@mojomojomojo
Copy link
Contributor Author

This commit attempts to address the situation you've described.
GUI elements in the option window show the override value and are disabled when the corresponding cmdline option is specified. The override value will not be written to the saved config.

Copy link
Member

@CyberShadow CyberShadow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you.

Copy link
Member

@CyberShadow CyberShadow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misclicked at the last moment.

@CyberShadow CyberShadow merged commit dcec532 into VerySleepy:master May 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants