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

Use system_properties.h api instead of getprop #1233

Conversation

panos-lunarg
Copy link
Contributor

@panos-lunarg panos-lunarg commented Aug 22, 2023

Use the appropriate Android NDK Api to get property values instead of launching a new process with popen("getprop ...");

Fixes #1231

@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 28144.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 3105 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 3105 passed.

@panos-lunarg panos-lunarg force-pushed the panos_use_system_properties_api_instead_of_getprop branch from 00c0c86 to c65ae20 Compare August 22, 2023 17:12
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 28300.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 3107 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 3107 passed.

@panos-lunarg panos-lunarg force-pushed the panos_use_system_properties_api_instead_of_getprop branch from c65ae20 to cf62b76 Compare August 23, 2023 06:48
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 28667.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 3112 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 3112 passed.

static const prop_info* GetAndroidPropertyInfo(const char* name)
{
// According to system_properties.h "Property lookup is expensive, so it can be useful to cache the result of this
// function.". For that reason we cache property infos.
Copy link
Contributor

Choose a reason for hiding this comment

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

I saw that comment too, how much overhead is it? Was not sure it is worth the added complexity.

const std::string prop_name = std::string(name);
const prop_info* pi;

auto prop_name_info = property_name_info_cache.find(prop_name);
Copy link
Contributor

Choose a reason for hiding this comment

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

is this a problem in respect to multi-threading, or is this code never used concurrently?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I'd better add some lock here

std::string command = "getprop ";
command += name;
// Note: GetAndroidPropertyInfo caches property info look ups. That means if a property is not set
// during start up, setting it or changing its value during run time will not be noticed and won't have any effect.
Copy link
Contributor

Choose a reason for hiding this comment

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

that's fine with our usage. But not sure other users wont run into this. For example we did have an issue where the property was not set in the initial run, and that caused issues of differently changing the output name. For that reason we now set the property before we start the app, so no problem for us. But this is a bit of a trap I could see others running into.

Copy link
Contributor

Choose a reason for hiding this comment

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

We discussed this at length internally and this comment was the result of the conversation. Otherwise if we want to pick up at frame time the values of properties that were unset at startup we'd have the impact of __system_property_find every frame, at least until it wasn't nullptr. I also don't know (as you asked above) how much performance impact there is here. I gathered from Panos that he was just honoring the guidance in system_properties.h.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I didn't measure performance impact, I just followed the hint. I'll do some measurement to get a rough idea

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did some measurement and I didn't see any difference. I'll drop the cache for simplicity's sake

Use the appropriate Android NDK Api to get property values instead of
launching a new process with popen("getprop ...");
@panos-lunarg panos-lunarg force-pushed the panos_use_system_properties_api_instead_of_getprop branch from cf62b76 to 4fe54f0 Compare August 24, 2023 08:17
@ci-tester-lunarg
Copy link

CI gfxreconstruct build queued with queue ID 29329.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 3124 running.

@ci-tester-lunarg
Copy link

CI gfxreconstruct build # 3124 passed.

@panos-lunarg panos-lunarg merged commit d1153da into LunarG:dev Aug 28, 2023
5 checks passed
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.

Investigate use of the Android property API instead of calling getprop
4 participants