Tiny Core Base > TCB Tips & Tricks
How to find which extension provides a file
nick65go:
@Rich: From my point of view, you did a really good job! I mean you kept compatibility for old i486 CPU and improved the search comfort, BOTH in GUI and cmd line. Using just awk and shell, the search time (for you) is less than 2 seconds!
The number of extensions (in the future) will NOT dramatically increase (because missing MORE significant number of developers).
My assumptions are that the SIZE of database will NOT increase too much (+20% maxim as GZIP-ed) and the database is LOCATED in RAM memory, plus the UPDATE of the database is not so often performed. So, it seams that by this path you will soon arrive at diminishing return (Pareto principle). All is just an intellectual challenge, which I like.
Even if you can achieve, lets say search in 1/1000 seconds, which is 2,000.00 time faster than 2 seconds, the practical implication could be exploited only in loops or pipes programs, but not in GUI interface.
I wonder what (old?) computer specification you used (CPU, HDD, RAM), if you want to share, for your test.
polikuo:
Hi, Rich.
Nice work !!
You don't mind if I tweak a little right ?
Cause I really like to skip the zsync routine.
--- Code: ------ provides.sh
+++ /usr/local/bin/provides.sh
@@ -32,6 +32,7 @@
fi
chmod g+rw "$DB"
cd - > /dev/null
+touch $LIST
}
# --------------------------------------------------------------- #
@@ -85,7 +86,7 @@
[ -z "$TARGET" ] && exit 1
# Run zsync on the provides.db file if NZ equals 1.
-[ $NZ -eq 1 ] && UpdateProvidesDB
+[ $NZ -eq 1 ] || [ -n "$(find $LIST -mmin +15)" ] && UpdateProvidesDB
# Save string length of TARGET.
Length=${#TARGET}
--- End code ---
The idea here is similar to the sudo session.
On Ubuntu, for example, after typing the password in a sudo command, the system will not ask for password in the following 15 minutes.
The newer version of busybox supports -mmin option.
--- Code: ---tc@pi4:/tmp$ uname -a
Linux pi4 6.6.47-piCore-v8 #21 SMP PREEMPT Sat Aug 31 15:08:05 EDT 2024 aarch64 GNU/Linux
tc@pi4:/tmp$ busybox find --help
BusyBox v1.36.1 (2024-04-07 15:54:04 UTC) multi-call binary.
...
...
-mtime DAYS mtime is greater than (+N), less than (-N),
or exactly N days in the past
-mmin MINS mtime is greater than (+N), less than (-N),
or exactly N minutes in the past
--- End code ---
Rich:
Hi nick65go
--- Quote from: nick65go on November 18, 2024, 02:26:44 AM --- ... Using just awk and shell, the search time (for you) is less than 2 seconds! ...
--- End quote ---
Most of that time is consumed by zsync checking if the servers version of provides.db
is newer than the one on your computer.
If you use the -nz switch it skips the zsync check and the time drops to under 0.2 seconds.
--- Quote --- ... I wonder what (old?) computer specification you used (CPU, HDD, RAM), if you want to share, for your test.
--- End quote ---
I retired my old 800Mhz i686 (coppermine), 512 Meg RAM, PATA drives system
a year or two ago. It was a good machine for testing speed impact of optimizations.
Now I mostly use this machine:
--- Code: ---tc@E310:~$ sudo inxi -CfmDGnSM
System:
Host: E310 Kernel: 4.19.10-tinycore i686 bits: 32 Desktop: FLWM
Distro: TinyCore 10.1
Machine:
Type: Desktop System: Dell product: Dell DV051 v: N/A serial: 9Q5X2B1
Mobo: Dell model: 0JC474 serial: ..CN481115B2077P. BIOS: Dell v: A04
date: 04/04/2006
Memory:
RAM: total: 2.96 GiB used: 1.30 GiB (44.1%)
Array-1: capacity: 4 GiB note: est. slots: 2 EC: Single-bit ECC
Device-1: DIMM_1 size: 2 GiB speed: 533 MHz
Device-2: DIMM_2 size: 2 GiB speed: 533 MHz
CPU:
Topology: Single Core model: Intel Pentium 4 bits: 64 type: MT
L2 cache: 1024 KiB
Speed: 2793 MHz min/max: N/A Core speeds (MHz): 1: 2793 2: 2793
Flags: acpi apic bts cid clflush cmov constant_tsc cpuid cx16 cx8 de
ds_cpl dtes64 dts fpu fxsr ht lahf_lm lm mca mce mmx monitor msr mtrr pae
pat pbe pebs pge pni pse pse36 sep ss sse sse2 tm tsc vme xtpr
Graphics:
Device-1: Intel 82915G/GV/910GL Integrated Graphics driver: i915 v: kernel
Display: server: X.Org 1.20.4 driver: intel resolution: 1920x1080~60Hz
OpenGL: renderer: Mesa DRI Intel 915G x86/MMX/SSE2 v: 1.4 Mesa 19.2.3
Network:
Device-1: Intel 82562ET/EZ/GT/GZ - PRO/100 VE Ethernet driver: e100
IF: eth0 state: up speed: 100 Mbps duplex: full mac: 00:13:20:c4:4a:20
IF-ID-1: dummy0 state: down mac: 6e:93:1c:04:f2:dc
IF-ID-2: ip_vti0 state: down mac: 00:00:00:00
IF-ID-3: tunl0 state: down mac: 00:00:00:00
Drives:
Local Storage: total: 931.52 GiB used: 144.75 GiB (15.5%)
ID-1: /dev/sda vendor: HP model: MB0500EBNCR size: 465.76 GiB
ID-2: /dev/sdb vendor: HP model: MB0500EBNCR size: 465.76 GiB
tc@E310:~$
--- End code ---
Rich:
Hi polikuo
--- Quote from: polikuo on November 18, 2024, 06:27:00 AM --- ... Cause I really like to skip the zsync routine. ...
--- End quote ---
I get the feeling you don't like waiting for results from your computer. ::)
This is the timing for busybox awk:
--- Code: ---tc@E310:~/Scripting/Provides$ time ./provides.sh -nz glxinfo$
mesa-demos.tcz
real 0m 0.45s
user 0m 0.41s
sys 0m 0.04s
tc@E310:~/Scripting/Provides$ time ./provides.sh -nz glxinfo$
mesa-demos.tcz
real 0m 0.47s
user 0m 0.42s
sys 0m 0.04s
tc@E310:~/Scripting/Provides$
--- End code ---
This is the timing when gawk.tcz is installed:
--- Code: ---tc@E310:~/Scripting/Provides$ time ./provides.sh -nz glxinfo$
mesa-demos.tcz
real 0m 0.21s
user 0m 0.16s
sys 0m 0.04s
tc@E310:~/Scripting/Provides$ time ./provides.sh -nz glxinfo$
mesa-demos.tcz
real 0m 0.22s
user 0m 0.18s
sys 0m 0.03s
tc@E310:~/Scripting/Provides$
--- End code ---
I override the busybox default and use GNU awk if I detect it's present.
--- Quote --- ... The newer version of busybox supports -mmin option. ...
--- End quote ---
The current version of busybox on TC10 x86 does too.
--- Quote ---
--- Code: ---+[ $NZ -eq 1 ] || [ -n "$(find $LIST -mmin +15)" ] && UpdateProvidesDB
--- End code ---
--- End quote ---
That's pretty clever, but was the intent to override the -nz command
line switch every 15 minutes?
Maybe it makes more sense to remove the -nz command line switch
and just let it run a check when the file is at least 15 minutes old.
I would like to hear some opinions on this please.
CNK:
Works fine here (TC15 x86_64).
--- Quote ---Maybe it makes more sense to remove the -nz command line switch
and just let it run a check when the file is at least 15 minutes old.
I would like to hear some opinions on this please.
--- End quote ---
I like the switch - it would avoid trouble when internet access isn't working and connections are timing out. If someone really runs it on a 486 then there would be a performance advantage too.
I'd also suggest showing the help info if provides.sh is run with no arguments.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version