a lot of logs to pinpoint cpu usage on some systems

This commit is contained in:
Master Kwoth 2017-07-05 18:15:46 +02:00
parent 269a4e3157
commit 42923c5272
3 changed files with 17 additions and 4 deletions

View File

@ -108,6 +108,7 @@ namespace NadekoBot.Modules.Music
int index; int index;
try try
{ {
_log.Info("Added");
index = mp.Enqueue(songInfo); index = mp.Enqueue(songInfo);
} }
catch (QueueFullException) catch (QueueFullException)
@ -169,11 +170,13 @@ namespace NadekoBot.Modules.Music
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Queue([Remainder] string query) public async Task Queue([Remainder] string query)
{ {
_log.Info("Getting player");
var mp = await _music.GetOrCreatePlayer(Context); var mp = await _music.GetOrCreatePlayer(Context);
_log.Info("Resolving song");
var songInfo = await _music.ResolveSong(query, Context.User.ToString()); var songInfo = await _music.ResolveSong(query, Context.User.ToString());
_log.Info("Queueing song");
try { await InternalQueue(mp, songInfo, false); } catch (QueueFullException) { return; } try { await InternalQueue(mp, songInfo, false); } catch (QueueFullException) { return; }
_log.Info("--------------");
if ((await Context.Guild.GetCurrentUserAsync()).GetPermissions((IGuildChannel)Context.Channel).ManageMessages) if ((await Context.Guild.GetCurrentUserAsync()).GetPermissions((IGuildChannel)Context.Channel).ManageMessages)
{ {
Context.Message.DeleteAfter(10); Context.Message.DeleteAfter(10);

View File

@ -156,6 +156,7 @@ namespace NadekoBot.Services.Music
_log.Info("Starting"); _log.Info("Starting");
using (var b = new SongBuffer(await data.Song.Uri(), "")) using (var b = new SongBuffer(await data.Song.Uri(), ""))
{ {
_log.Info("Created buffer, buffering...");
AudioOutStream pcm = null; AudioOutStream pcm = null;
try try
{ {
@ -171,16 +172,19 @@ namespace NadekoBot.Services.Music
_log.Info("Buffering failed due to a cancel or error."); _log.Info("Buffering failed due to a cancel or error.");
continue; continue;
} }
_log.Info("Buffered. Getting audio client...");
var ac = await GetAudioClient(); var ac = await GetAudioClient();
_log.Info("Got Audio client");
if (ac == null) if (ac == null)
{ {
_log.Info("Can't join");
await Task.Delay(900, cancelToken); await Task.Delay(900, cancelToken);
// just wait some time, maybe bot doesn't even have perms to join that voice channel, // just wait some time, maybe bot doesn't even have perms to join that voice channel,
// i don't want to spam connection attempts // i don't want to spam connection attempts
continue; continue;
} }
pcm = ac.CreatePCMStream(AudioApplication.Music, bufferMillis: 500); pcm = ac.CreatePCMStream(AudioApplication.Music, bufferMillis: 500);
_log.Info("Created pcm stream");
OnStarted?.Invoke(this, data); OnStarted?.Invoke(this, data);
byte[] buffer = new byte[3840]; byte[] buffer = new byte[3840];
@ -189,6 +193,7 @@ namespace NadekoBot.Services.Music
while ((bytesRead = b.Read(buffer, 0, buffer.Length)) > 0 while ((bytesRead = b.Read(buffer, 0, buffer.Length)) > 0
&& (MaxPlaytimeSeconds <= 0 || MaxPlaytimeSeconds >= CurrentTime.TotalSeconds)) && (MaxPlaytimeSeconds <= 0 || MaxPlaytimeSeconds >= CurrentTime.TotalSeconds))
{ {
_log.Info("Sending stuff");
AdjustVolume(buffer, Volume); AdjustVolume(buffer, Volume);
await pcm.WriteAsync(buffer, 0, bytesRead, cancelToken).ConfigureAwait(false); await pcm.WriteAsync(buffer, 0, bytesRead, cancelToken).ConfigureAwait(false);
unchecked { _bytesSent += bytesRead; } unchecked { _bytesSent += bytesRead; }
@ -309,6 +314,7 @@ namespace NadekoBot.Services.Music
do do
{ {
await Task.Delay(500); await Task.Delay(500);
_log.Info("Waiting for something to happen");
} }
while ((Queue.Count == 0 || Stopped) && !Exited); while ((Queue.Count == 0 || Stopped) && !Exited);
} }

View File

@ -282,6 +282,7 @@ namespace NadekoBot.Services.Music
public async Task<SongInfo> ResolveYoutubeSong(string query, string queuerName) public async Task<SongInfo> ResolveYoutubeSong(string query, string queuerName)
{ {
_log.Info("Getting video");
var (link, video) = await GetYoutubeVideo(query); var (link, video) = await GetYoutubeVideo(query);
if (video == null) // do something with this error if (video == null) // do something with this error
@ -294,6 +295,7 @@ namespace NadekoBot.Services.Music
//if (m.Captures.Count > 0) //if (m.Captures.Count > 0)
// int.TryParse(m.Groups["t"].ToString(), out gotoTime); // int.TryParse(m.Groups["t"].ToString(), out gotoTime);
_log.Info("Creating song info");
var song = new SongInfo var song = new SongInfo
{ {
Title = video.Title.Substring(0, video.Title.Length - 10), // removing trailing "- You Tube" Title = video.Title.Substring(0, video.Title.Length - 10), // removing trailing "- You Tube"
@ -314,12 +316,14 @@ namespace NadekoBot.Services.Music
private async Task<(string, YouTubeVideo)> GetYoutubeVideo(string query) private async Task<(string, YouTubeVideo)> GetYoutubeVideo(string query)
{ {
_log.Info("Getting link");
var link = (await _google.GetVideoLinksByKeywordAsync(query).ConfigureAwait(false)).FirstOrDefault(); var link = (await _google.GetVideoLinksByKeywordAsync(query).ConfigureAwait(false)).FirstOrDefault();
if (string.IsNullOrWhiteSpace(link)) if (string.IsNullOrWhiteSpace(link))
{ {
_log.Info("No song found."); _log.Info("No song found.");
return (null, null); return (null, null);
} }
_log.Info("Getting all videos");
var allVideos = await Task.Run(async () => { try { return await YouTube.Default.GetAllVideosAsync(link).ConfigureAwait(false); } catch { return Enumerable.Empty<YouTubeVideo>(); } }).ConfigureAwait(false); var allVideos = await Task.Run(async () => { try { return await YouTube.Default.GetAllVideosAsync(link).ConfigureAwait(false); } catch { return Enumerable.Empty<YouTubeVideo>(); } }).ConfigureAwait(false);
var videos = allVideos.Where(v => v.AdaptiveKind == AdaptiveKind.Audio); var videos = allVideos.Where(v => v.AdaptiveKind == AdaptiveKind.Audio);
var video = videos var video = videos