alba4k / albafetch

Faster neofetch alternative, written in C. Still improving :)
MIT License
66 stars 10 forks source link

[Bug Report] Stuck in the middle #131

Closed Dominiquini closed 2 hours ago

Dominiquini commented 3 days ago

Describe the bug The application gets stuck in the middle of the output

Expected behavior The app should print and exit

Screenshots albafetch

Desktop (please complete the following information):

Possibly relevant config lines:

Additional context Installed from AUR - albafetch-bin (https://aur.archlinux.org/packages/albafetch-bin)

alba4k commented 3 days ago

Huh

for some reason it gets stuck trying to count the installed packages

would you mind trying to disable pkg_snap pkg_flatpak and pkg_pacman one by one and see which one is causing the issue?

You can check /etc/xdg/albafetch.conf for a reference syntax, not sure if the changes will actually be read if you change any settings from that file, pretty sure that's only on -git (actually, I'm not even sure if I implemented that in git or you still have to copy it to your home dir. Should probably check)

Dominiquini commented 2 days ago

I haven't tested the changes you proposed (I can test them later), but I saw here that the application isn't freezing, it just takes a long time to run (more than 2 minutes!) Maybe this option should be disabled by default!

Thanks.

alba4k commented 2 days ago

It should totally not take that long, especially if it's just pacman. Could you please tell me what you get as installed packages? pip takes a long time to run, which is why I have disabled it by default

debug build, with pip ![immagine](https://github.com/user-attachments/assets/e9e52e56-275a-4bde-a9d1-5884472e995f)
debug build, without pip ![immagine](https://github.com/user-attachments/assets/ce6f955e-7edd-4b21-b202-fcdd76cd3bee)

What is taking two minutes though? it can't be pacman, maybe flatpak or snap?

Dominiquini commented 2 days ago

What is taking two minutes though? it can't be pacman, maybe flatpak or snap?

I think it's pacman that's taking too long! I'm using EndeavourOS live and I don't have any flatpak or snap installed! I also didn't install anything using pip!

albafetch

If you want, I can test here on my PC how long it takes to extract the number of installed packages... Do you know what command I can run here that simulates what the application uses? Let me know if I can help with anything. If you send me a debug build, I can try running it here and send you the result!

Thanks

alba4k commented 1 day ago

albafetch basically counts the number of subdirectories inside of /var/lib/pacman/local, basically just like ls /var/lib/pacman/local | wc -l (subtracting 2 because of . and .. being counted too). Weird that such an operation is taking this long (unless your disk is really slow, but I don't think that is the culprit)

You can do that with pacman too using pacman -Qq | wc -l

You can get a debug build by cloning this repository and running make debug inside of it

Dominiquini commented 1 day ago

I run this commands and both are very fast in my PC:

=> time ls /var/lib/pacman/local | wc -l
3560

real    0m0,011s
user    0m0,006s
sys     0m0,008s_
=> time pacman -Qq | wc -l
3559

real    0m0,028s
user    0m0,018s
sys     0m0,032s_

Later I can test the debug version and share the results!

Thanks

Dominiquini commented 1 day ago

Debug (--no-pip): albafetch-no-pip

Debug: albafetch

alba4k commented 2 hours ago

Tried to look into this.

No idea what the culprit is. I even tried going through it with chatgpt (which I usually barely use) out of desperation and yeah it was doing the same stuff I was doing.

This is the code in question, or at least so I think. If you're comfortable with coding in C try to put some printfs in ./src/info/packages.c and try to find out what part is taking this long.

if(_pkg_pacman && (dir = opendir(path)) != NULL) {
    while((entry = readdir(dir)) != NULL)
        if(entry->d_type == DT_DIR && strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0)
            ++count;
    closedir(dir);

    if(count) {
        snprintf(dest, 255 - strlen(buf), "%s%u%s", done ? ", " : "", count, _pkg_mgr ? " (pacman)" : "");
        done = true;
    }
}

Yeah, no clue, I wonder if pacman really is the part that's taking long, or if it could be something outside of that

Dominiquini commented 2 hours ago

I found where the problem is!

This command takes forever to run on my PC:

$ time snap list
error: cannot list snaps: cannot communicate with server: Get "http://localhost/v2/snaps": dial unix /run/snapd.socket: connect: no such file or directory

real    2m0,014s
user    0m0,153s
sys     0m0,118s

I will try to fix my snap installation and try again!

Thanks for the help!

Dominiquini commented 2 hours ago

My 'snapd' service was not running and this caused the slow down of the application! Maybe you should check first if snapd is active before quering about installed snaps!

Thanks and sorry for the bug! The problem was only on my machine!