aome510 / spotify-player

A Spotify player in the terminal with full feature parity
MIT License
3.37k stars 147 forks source link

very high cpu usage?? #98

Closed apprehensions closed 1 year ago

apprehensions commented 1 year ago

i have noticed that with spotify_player, it causes the cpu usage to increase and my computer fans ramp up the speed due to the usage.

image

what the fuck is spotify_player doing? i'm not even doing anything.

aome510 commented 1 year ago

@wael444 I couldn't reproduce this issue. I use the app daily and in my laptop (M1 Mac), it never goes beyond 2% CPU usage. Does this issue only happen during the startup? Does it happen frequently as well?

aome510 commented 1 year ago

Also, can you provide the version and additional features of spotify_player that you're currently using?

apprehensions commented 1 year ago

Also, can you provide the version and additional features of spotify_player that you're currently using?

i installed spotify_player from cargo install, with the default features only.

apprehensions commented 1 year ago

https://user-images.githubusercontent.com/47404953/211155591-1e86aa82-057a-4b92-b43b-eebfecd64579.mp4

apprehensions commented 1 year ago

flamegraph

aome510 commented 1 year ago

20230107_172620_sc.mp4

Thanks for the demonstration . Can you also provide me a log of such run in ~/.cache/spotify-player?

apprehensions commented 1 year ago
2023-01-07T15:32:41.715516Z  INFO spotify_player::state: General configurations: AppConfig { theme: "dracula", client_id: "65b708073fc0480ea92a077233ca87bd", proxy: None, ap_port: None, app_refresh_duration_in_ms: 32, playback_refresh_duration_in_ms: 0, track_table_item_max_len: 32, play_icon: "⏸", pause_icon: "▶", playback_window_width: 6, enable_media_control: true, default_device: "spotify-player", device: DeviceConfig { name: "spotify-player", device_type: "speaker", volume: 50, bitrate: 160, audio_cache: false } }
2023-01-07T15:32:41.715576Z  WARN spotify_player::config::theme: Failed to open the theme config file (path="/home/wael/.config/spotify-player/theme.toml"): No such file or directory (os error 2). Use the default configurations instead
2023-01-07T15:32:41.715594Z  INFO spotify_player::state: Theme configurations: ThemeConfig { themes: [Theme { name: "dracula", palette: Palette { background: Color { color: Rgb(30, 31, 41) }, foreground: Color { color: Rgb(248, 248, 242) }, selection_background: Color { color: Rgb(68, 71, 90) }, selection_foreground: Color { color: Rgb(255, 255, 255) }, black: Color { color: Rgb(0, 0, 0) }, blue: Color { color: Rgb(189, 147, 249) }, cyan: Color { color: Rgb(139, 233, 253) }, green: Color { color: Rgb(80, 250, 123) }, magenta: Color { color: Rgb(255, 121, 198) }, red: Color { color: Rgb(255, 85, 85) }, white: Color { color: Rgb(187, 187, 187) }, yellow: Color { color: Rgb(241, 250, 140) }, bright_black: Color { color: Rgb(85, 85, 85) }, bright_white: Color { color: Rgb(255, 255, 255) }, bright_red: Color { color: Rgb(255, 85, 85) }, bright_magenta: Color { color: Rgb(255, 121, 198) }, bright_green: Color { color: Rgb(80, 250, 123) }, bright_cyan: Color { color: Rgb(139, 233, 253) }, bright_blue: Color { color: Rgb(189, 147, 249) }, bright_yellow: Color { color: Rgb(241, 250, 140) } }, component_style: ComponentStyle { block_title: Style { fg: Some(Magenta), bg: None, modifiers: [] }, playback_track: Style { fg: Some(Cyan), bg: None, modifiers: [Bold] }, playback_album: Style { fg: Some(Yellow), bg: None, modifiers: [] }, playback_metadata: Style { fg: Some(BrightBlack), bg: None, modifiers: [] }, playback_progress_bar: Style { fg: Some(Green), bg: Some(SelectionBackground), modifiers: [] }, current_playing: Style { fg: Some(Green), bg: None, modifiers: [Bold] }, page_desc: Style { fg: Some(Cyan), bg: None, modifiers: [Bold] }, table_header: Style { fg: Some(Blue), bg: None, modifiers: [] } } }, Theme { name: "ayu_light", palette: Palette { background: Color { color: Rgb(250, 250, 250) }, foreground: Color { color: Rgb(92, 103, 115) }, selection_background: Color { color: Rgb(240, 238, 228) }, selection_foreground: Color { color: Rgb(92, 103, 115) }, black: Color { color: Rgb(0, 0, 0) }, blue: Color { color: Rgb(65, 166, 217) }, cyan: Color { color: Rgb(77, 191, 153) }, green: Color { color: Rgb(134, 179, 0) }, magenta: Color { color: Rgb(240, 113, 120) }, red: Color { color: Rgb(255, 51, 51) }, white: Color { color: Rgb(255, 255, 255) }, yellow: Color { color: Rgb(242, 151, 24) }, bright_black: Color { color: Rgb(50, 50, 50) }, bright_white: Color { color: Rgb(255, 255, 255) }, bright_red: Color { color: Rgb(255, 101, 101) }, bright_magenta: Color { color: Rgb(255, 163, 170) }, bright_green: Color { color: Rgb(184, 229, 50) }, bright_cyan: Color { color: Rgb(127, 241, 203) }, bright_blue: Color { color: Rgb(115, 216, 255) }, bright_yellow: Color { color: Rgb(255, 201, 74) } }, component_style: ComponentStyle { block_title: Style { fg: Some(Magenta), bg: None, modifiers: [] }, playback_track: Style { fg: Some(Cyan), bg: None, modifiers: [Bold] }, playback_album: Style { fg: Some(Yellow), bg: None, modifiers: [] }, playback_metadata: Style { fg: Some(BrightBlack), bg: None, modifiers: [] }, playback_progress_bar: Style { fg: Some(Green), bg: Some(SelectionBackground), modifiers: [] }, current_playing: Style { fg: Some(Green), bg: None, modifiers: [Bold] }, page_desc: Style { fg: Some(Cyan), bg: None, modifiers: [Bold] }, table_header: Style { fg: Some(Blue), bg: None, modifiers: [] } } }, Theme { name: "gruvbox_dark", palette: Palette { background: Color { color: Rgb(30, 30, 30) }, foreground: Color { color: Rgb(230, 212, 163) }, selection_background: Color { color: Rgb(230, 212, 163) }, selection_foreground: Color { color: Rgb(83, 74, 66) }, black: Color { color: Rgb(30, 30, 30) }, blue: Color { color: Rgb(55, 115, 117) }, cyan: Color { color: Rgb(87, 142, 87) }, green: Color { color: Rgb(134, 135, 21) }, magenta: Color { color: Rgb(160, 75, 115) }, red: Color { color: Rgb(190, 15, 23) }, white: Color { color: Rgb(151, 135, 113) }, yellow: Color { color: Rgb(204, 136, 26) }, bright_black: Color { color: Rgb(127, 112, 97) }, bright_white: Color { color: Rgb(230, 212, 163) }, bright_red: Color { color: Rgb(247, 48, 40) }, bright_magenta: Color { color: Rgb(199, 112, 137) }, bright_green: Color { color: Rgb(170, 176, 30) }, bright_cyan: Color { color: Rgb(125, 182, 105) }, bright_blue: Color { color: Rgb(113, 149, 134) }, bright_yellow: Color { color: Rgb(247, 177, 37) } }, component_style: ComponentStyle { block_title: Style { fg: Some(Magenta), bg: None, modifiers: [] }, playback_track: Style { fg: Some(Cyan), bg: None, modifiers: [Bold] }, playback_album: Style { fg: Some(Yellow), bg: None, modifiers: [] }, playback_metadata: Style { fg: Some(BrightBlack), bg: None, modifiers: [] }, playback_progress_bar: Style { fg: Some(Green), bg: Some(SelectionBackground), modifiers: [] }, current_playing: Style { fg: Some(Green), bg: None, modifiers: [Bold] }, page_desc: Style { fg: Some(Cyan), bg: None, modifiers: [Bold] }, table_header: Style { fg: Some(Blue), bg: None, modifiers: [] } } }, Theme { name: "solarized_light", palette: Palette { background: Color { color: Rgb(253, 246, 227) }, foreground: Color { color: Rgb(101, 123, 131) }, selection_background: Color { color: Rgb(238, 232, 213) }, selection_foreground: Color { color: Rgb(88, 110, 117) }, black: Color { color: Rgb(7, 54, 66) }, blue: Color { color: Rgb(38, 139, 210) }, cyan: Color { color: Rgb(42, 161, 152) }, green: Color { color: Rgb(133, 153, 0) }, magenta: Color { color: Rgb(211, 54, 130) }, red: Color { color: Rgb(220, 50, 47) }, white: Color { color: Rgb(238, 232, 213) }, yellow: Color { color: Rgb(181, 137, 0) }, bright_black: Color { color: Rgb(0, 43, 54) }, bright_white: Color { color: Rgb(253, 246, 227) }, bright_red: Color { color: Rgb(203, 75, 22) }, bright_magenta: Color { color: Rgb(108, 113, 196) }, bright_green: Color { color: Rgb(88, 110, 117) }, bright_cyan: Color { color: Rgb(147, 161, 161) }, bright_blue: Color { color: Rgb(131, 148, 150) }, bright_yellow: Color { color: Rgb(101, 123, 131) } }, component_style: ComponentStyle { block_title: Style { fg: Some(Magenta), bg: None, modifiers: [] }, playback_track: Style { fg: Some(Cyan), bg: None, modifiers: [Bold] }, playback_album: Style { fg: Some(Yellow), bg: None, modifiers: [] }, playback_metadata: Style { fg: Some(BrightBlack), bg: None, modifiers: [] }, playback_progress_bar: Style { fg: Some(Green), bg: Some(SelectionBackground), modifiers: [] }, current_playing: Style { fg: Some(Green), bg: None, modifiers: [Bold] }, page_desc: Style { fg: Some(Cyan), bg: None, modifiers: [Bold] }, table_header: Style { fg: Some(Blue), bg: None, modifiers: [] } } }] }
2023-01-07T15:32:41.715667Z  WARN spotify_player::config::keymap: Failed to open the keymap config file (path="/home/wael/.config/spotify-player/keymap.toml"): No such file or directory (os error 2). Use the default configurations instead
2023-01-07T15:32:41.715674Z  INFO spotify_player::state: Keymap configurations: KeymapConfig { keymaps: [Keymap { key_sequence: KeySequence { keys: [None(Char('n'))] }, command: NextTrack }, Keymap { key_sequence: KeySequence { keys: [None(Char('p'))] }, command: PreviousTrack }, Keymap { key_sequence: KeySequence { keys: [None(Char('.'))] }, command: PlayRandom }, Keymap { key_sequence: KeySequence { keys: [None(Char(' '))] }, command: ResumePause }, Keymap { key_sequence: KeySequence { keys: [Ctrl(Char('r'))] }, command: Repeat }, Keymap { key_sequence: KeySequence { keys: [Ctrl(Char('s'))] }, command: Shuffle }, Keymap { key_sequence: KeySequence { keys: [None(Char('+'))] }, command: VolumeUp }, Keymap { key_sequence: KeySequence { keys: [None(Char('-'))] }, command: VolumeDown }, Keymap { key_sequence: KeySequence { keys: [None(Char('>'))] }, command: SeekForward }, Keymap { key_sequence: KeySequence { keys: [None(Char('<'))] }, command: SeekBackward }, Keymap { key_sequence: KeySequence { keys: [None(Enter)] }, command: ChooseSelected }, Keymap { key_sequence: KeySequence { keys: [None(Char('r'))] }, command: RefreshPlayback }, Keymap { key_sequence: KeySequence { keys: [None(Char('/'))] }, command: Search }, Keymap { key_sequence: KeySequence { keys: [Ctrl(Char(' '))] }, command: ShowActionsOnSelectedItem }, Keymap { key_sequence: KeySequence { keys: [None(Char('g')), None(Char('a'))] }, command: ShowActionsOnSelectedItem }, Keymap { key_sequence: KeySequence { keys: [None(Char('a'))] }, command: ShowActionsOnCurrentTrack }, Keymap { key_sequence: KeySequence { keys: [None(Char('R'))] }, command: RestartIntegratedClient }, Keymap { key_sequence: KeySequence { keys: [None(Tab)] }, command: FocusNextWindow }, Keymap { key_sequence: KeySequence { keys: [None(BackTab)] }, command: FocusPreviousWindow }, Keymap { key_sequence: KeySequence { keys: [None(Char('T'))] }, command: SwitchTheme }, Keymap { key_sequence: KeySequence { keys: [None(Char('D'))] }, command: SwitchDevice }, Keymap { key_sequence: KeySequence { keys: [None(Char('u')), None(Char('p'))] }, command: BrowseUserPlaylists }, Keymap { key_sequence: KeySequence { keys: [None(Char('u')), None(Char('a'))] }, command: BrowseUserFollowedArtists }, Keymap { key_sequence: KeySequence { keys: [None(Char('u')), None(Char('A'))] }, command: BrowseUserSavedAlbums }, Keymap { key_sequence: KeySequence { keys: [None(Char('g')), None(Char(' '))] }, command: CurrentlyPlayingContextPage }, Keymap { key_sequence: KeySequence { keys: [None(Char('g')), None(Char('t'))] }, command: TopTrackPage }, Keymap { key_sequence: KeySequence { keys: [None(Char('g')), None(Char('r'))] }, command: RecentlyPlayedTrackPage }, Keymap { key_sequence: KeySequence { keys: [None(Char('g')), None(Char('y'))] }, command: LikedTrackPage }, Keymap { key_sequence: KeySequence { keys: [None(Char('g')), None(Char('l'))] }, command: LibraryPage }, Keymap { key_sequence: KeySequence { keys: [None(Char('g')), None(Char('s'))] }, command: SearchPage }, Keymap { key_sequence: KeySequence { keys: [None(Char('g')), None(Char('b'))] }, command: BrowsePage }, Keymap { key_sequence: KeySequence { keys: [None(Backspace)] }, command: PreviousPage }, Keymap { key_sequence: KeySequence { keys: [Ctrl(Char('q'))] }, command: PreviousPage }, Keymap { key_sequence: KeySequence { keys: [None(Char('?'))] }, command: OpenCommandHelp }, Keymap { key_sequence: KeySequence { keys: [Ctrl(Char('h'))] }, command: OpenCommandHelp }, Keymap { key_sequence: KeySequence { keys: [None(Char('q'))] }, command: Quit }, Keymap { key_sequence: KeySequence { keys: [Ctrl(Char('c'))] }, command: Quit }, Keymap { key_sequence: KeySequence { keys: [None(Esc)] }, command: ClosePopup }, Keymap { key_sequence: KeySequence { keys: [None(Char('j'))] }, command: SelectNextOrScrollDown }, Keymap { key_sequence: KeySequence { keys: [Ctrl(Char('n'))] }, command: SelectNextOrScrollDown }, Keymap { key_sequence: KeySequence { keys: [None(Down)] }, command: SelectNextOrScrollDown }, Keymap { key_sequence: KeySequence { keys: [None(Char('k'))] }, command: SelectPreviousOrScrollUp }, Keymap { key_sequence: KeySequence { keys: [Ctrl(Char('p'))] }, command: SelectPreviousOrScrollUp }, Keymap { key_sequence: KeySequence { keys: [None(Up)] }, command: SelectPreviousOrScrollUp }, Keymap { key_sequence: KeySequence { keys: [None(Char('s')), None(Char('t'))] }, command: SortTrackByTitle }, Keymap { key_sequence: KeySequence { keys: [None(Char('s')), None(Char('a'))] }, command: SortTrackByArtists }, Keymap { key_sequence: KeySequence { keys: [None(Char('s')), None(Char('A'))] }, command: SortTrackByAlbum }, Keymap { key_sequence: KeySequence { keys: [None(Char('s')), None(Char('d'))] }, command: SortTrackByDuration }, Keymap { key_sequence: KeySequence { keys: [None(Char('s')), None(Char('D'))] }, command: SortTrackByAddedDate }, Keymap { key_sequence: KeySequence { keys: [None(Char('s')), None(Char('r'))] }, command: ReverseTrackOrder }] }
2023-01-07T15:32:41.715750Z  INFO spotify_player::auth: Creating a new session with new authentication credentials
2023-01-07T15:32:46.517686Z  INFO spotify_player::token: Getting new authentication token...
2023-01-07T15:32:47.132861Z  INFO spotify_player::token: Got new token: Token { access_token: "no", expires_in: Duration { secs: 3600, nanos: 0 }, expires_at: Some(2023-01-07T16:32:47.132850969Z), refresh_token: None, scopes: {} }
2023-01-07T15:32:47.132933Z  INFO spotify_player::streaming: Application's connect configurations: ConnectConfig { name: "spotify-player", device_type: Speaker, initial_volume: Some(32768), has_volume_ctrl: true, autoplay: false }
2023-01-07T15:32:47.132984Z  INFO spotify_player::streaming: Initializing a new integrated player with device_id=103dac35-7f36-449c-a727-17c95bc5879c
2023-01-07T15:32:47.133067Z  INFO spotify_player::streaming: Starting an integrated Spotify player using librespot's spirc protocol
2023-01-07T15:32:47.672972Z  INFO spotify_player::media_control: Initializing application's media control event watcher...
2023-01-07T15:32:47.854325Z  INFO client_request{request=GetUserSavedTracks}: spotify_player::client: successfully handled the client request, took: 181ms
2023-01-07T15:32:47.920045Z  INFO client_request{request=GetCurrentUser}: spotify_player::client: successfully handled the client request, took: 247ms
2023-01-07T15:32:47.985388Z  INFO client_request{request=GetUserFollowedArtists}: spotify_player::client: successfully handled the client request, took: 312ms
2023-01-07T15:32:48.288928Z  INFO client_request{request=GetUserSavedAlbums}: spotify_player::client: successfully handled the client request, took: 616ms
2023-01-07T15:32:48.316002Z  INFO client_request{request=GetUserPlaylists}: spotify_player::client: successfully handled the client request, took: 643ms
Got a panic: PanicInfo {
    payload: Any { .. },
    message: Some(
        called `Result::unwrap()` on an `Err` value: StreamError(BuildStreamError(BackendSpecific { err: BackendSpecificError { description: "ALSA function 'snd_pcm_sw_params' failed with error 'EINVAL: Invalid argument'" } })),
    ),
    location: Location {
        file: "/home/wael/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/librespot-playback-0.4.2/src/audio_backend/rodio.rs",
        line: 178,
        col: 53,
    },
    can_unwind: true,
}

Stack backtrace:
   0: spotify_player::init_logging::{{closure}}
   1: std::panicking::rust_panic_with_hook
   2: std::panicking::begin_panic_handler::{{closure}}
   3: std::sys_common::backtrace::__rust_end_short_backtrace
   4: rust_begin_unwind
   5: core::panicking::panic_fmt
   6: core::result::unwrap_failed
   7: librespot_playback::audio_backend::rodio::mk_rodio
   8: std::sys_common::backtrace::__rust_begin_short_backtrace
   9: core::ops::function::FnOnce::call_once{{vtable.shim}}
  10: std::sys::unix::thread::Thread::new::thread_start
  11: <unknown>
  12: <unknown>

why in the hell would the spotify player need audio? that is handled by spotifyd/librespot.

aome510 commented 1 year ago

why in the hell would the spotify player need audio? that is handled by spotifyd/librespot.

You can run it without spotifyd/librespot as a spotify client by itself. spotify_player can be used either as a remote controller (like spotify-tui) to control other running client or as a single client itself (like ncspot).

Got a panic: PanicInfo {
    payload: Any { .. },
    message: Some(
        called `Result::unwrap()` on an `Err` value: StreamError(BuildStreamError(BackendSpecific { err: BackendSpecificError { description: "ALSA function 'snd_pcm_sw_params' failed with error 'EINVAL: Invalid argument'" } })),
    ),
    location: Location {
        file: "/home/wael/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/librespot-playback-0.4.2/src/audio_backend/rodio.rs",
        line: 178,
        col: 53,
    },
    can_unwind: true,
}

I suspect this may be the source of the high CPU error. Can you build the main branch without the streamng feature and try it again

git clone https://github.com/aome510/spotify-player.git && cd spotify-player
cargo run --no-default-features

Note it needs a running Spotify client (e.g spotifyd) to use the app

apprehensions commented 1 year ago

now that i think of it, where are the default features stored?

apprehensions commented 1 year ago

cargo run --no-default-features also yes, that solves it.

aome510 commented 1 year ago

now that i think of it, where are the default features stored?

The default features are media-control (cross-platform media control), rodio-backend, which includes streaming feature.

If you only use spotify-player as the remote controller, using no default feature should be enough unless you want other optional features such as image view, lyric finder, etc.

aome510 commented 1 year ago

cargo run --no-default-features also yes, that solves it.

Hope that this is enough to use for now.

Got a panic: PanicInfo {
    payload: Any { .. },
    message: Some(
        called `Result::unwrap()` on an `Err` value: StreamError(BuildStreamError(BackendSpecific { err: BackendSpecificError { description: "ALSA function 'snd_pcm_sw_params' failed with error 'EINVAL: Invalid argument'" } })),
    ),
    location: Location {
        file: "/home/wael/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/librespot-playback-0.4.2/src/audio_backend/rodio.rs",
        line: 178,
        col: 53,
    },
    can_unwind: true,
}

In case it's related, you can refer to this https://github.com/aome510/spotify-player/issues/38#issuecomment-1136512745 to try to fix the issue.

I'll close this issue for now