[OpenWrt-Devel] [PATCH] iwinfo: add channel survey
Koen Vandeputte
koen.vandeputte at ncentric.com
Wed Jun 6 10:11:33 EDT 2018
On 2018-06-05 10:23, Nick wrote:
> ....
>>
>> +static char * format_channel_time(uint64_t time)
>> +{
>> + static char buf[30];
>> +
>> + if (!time)
>> + snprintf(buf, sizeof(buf), "unknown");
>> + else
>> + snprintf(buf, sizeof(buf), "%llu ms", time);
>> +
>> + return buf;
>> +}
>> +
Out of curiosity:
Any reason to use a static char buffer inside this function instead of
using some char buffer provided by the caller?
This would:
- Avoid using slow heap memory and use faster stack memory (if the
caller allocates it on stack)
- Automatically makes the function re-entrant & threadsafe this way
>> static char * format_noise(int noise)
>> {
>> static char buf[10];
>> @@ -531,6 +543,19 @@ static char * print_phyname(const struct iwinfo_ops *iw, const char *ifname)
>> return "?";
>> }
>>
>> +static void print_survey(const struct iwinfo_ops *iw, const char *ifname)
>> +{
>> + struct iwinfo_survey_entry entry;
>> + iw->survey(ifname, &entry);
>> + printf("%s\tESSID:\t\t\t\t%s\n", ifname, print_ssid(iw, ifname));
>> + printf("\tChannel:\t\t\t%s (%s)\n", print_channel(iw, ifname), format_frequency(entry.frequency));
>> + printf("\tNoise:\t\t\t\t%s\n", format_noise(entry.noise));
>> + printf("\tchannel Active Time:\t\t%s\n", format_channel_time(entry.channel_time));
>> + printf("\tChannel Busy Time:\t\t%s\n",format_channel_time(entry.channel_time_busy));
>> + printf("\tExtension Channel Busy Time:\t%s\n",format_channel_time(entry.channel_time_ext_busy));
>> + printf("\tChannel Receive Time:\t\t%s\n",format_channel_time(entry.channel_time_rx));
>> + printf("\tChannel Transmit Time:\t\t%s\n",format_channel_time(entry.channel_time_tx));
>> +}
>> ...
Koen
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list