Skip to content

Commit

Permalink
#1824 Adds diagnostic report generation to File>>Reports menu to log …
Browse files Browse the repository at this point in the history
…thread dumps and generate a processing diagnostic/status report. (#1825)

Co-authored-by: Dennis Sheirer <[email protected]>
  • Loading branch information
DSheirer and Dennis Sheirer authored Feb 4, 2024
1 parent 3acaea0 commit 7b9adc1
Show file tree
Hide file tree
Showing 12 changed files with 501 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2022 Dennis Sheirer
* Copyright (C) 2014-2024 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -35,11 +35,10 @@
import io.github.dsheirer.identifier.decoder.ChannelStateIdentifier;
import io.github.dsheirer.identifier.decoder.DecoderLogicalChannelNameIdentifier;
import io.github.dsheirer.sample.Listener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Channel metadata containing details about the channel configuration, decoder state and current
Expand All @@ -66,17 +65,51 @@ public class ChannelMetadata implements Listener<IdentifierUpdateNotification>,
private AliasModel mAliasModel;
private AliasList mAliasList;

/**
* Constructs an instance
* @param aliasModel for alias lookups
* @param timeslot for this metadata
*/
public ChannelMetadata(AliasModel aliasModel, Integer timeslot)
{
mAliasModel = aliasModel;
mTimeslot = timeslot;
}

/**
* Constructs an instance
* @param aliasModel for alias lookups
*/
public ChannelMetadata(AliasModel aliasModel)
{
this(aliasModel, null);
}

/**
* Creates a textual description of this channel metadata.
*/
public String getDescription()
{
StringBuilder sb = new StringBuilder();
sb.append("Channel Metadata Description\n");
sb.append("\tTimeslot: ").append(mTimeslot).append("\n");
Identifier decoder = getDecoderTypeConfigurationIdentifier();
sb.append("\tDecoder: ").append(decoder != null ? decoder : "(null)").append("\n");
Identifier state = getChannelStateIdentifier();
sb.append("\tState: ").append(state != null ? state : "(null)").append("\n");
Identifier system = getSystemConfigurationIdentifier();
sb.append("\tSystem: ").append(system != null ? system : "(null)").append("\n");
Identifier site = getSiteConfigurationIdentifier();
sb.append("\tSite: ").append(site != null ? site : "(null)").append("\n");
Identifier channel = getChannelNameConfigurationIdentifier();
sb.append("\tChannel: ").append(channel != null ? channel : "(null)").append("\n");
Identifier frequency = getFrequencyConfigurationIdentifier();
sb.append("\tFrequency: ").append(frequency != null ? frequency : "(null)").append("\n");
Identifier logical = getDecoderLogicalChannelNameIdentifier();
sb.append("\tLogical Channel: ").append(logical != null ? logical : "(null)").append("\n");
return sb.toString();
}

public Integer getTimeslot()
{
return mTimeslot;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2024 Dennis Sheirer
*
* * ******************************************************************************
* * Copyright (C) 2014-2020 Dennis Sheirer
* *
* * This program is free software: you can redistribute it and/or modify
* * it under the terms of the GNU General Public License as published by
* * the Free Software Foundation, either version 3 of the License, or
* * (at your option) any later version.
* *
* * This program is distributed in the hope that it will be useful,
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* * GNU General Public License for more details.
* *
* * You should have received a copy of the GNU General Public License
* * along with this program. If not, see <http://www.gnu.org/licenses/>
* * *****************************************************************************
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
* ****************************************************************************
*/
package io.github.dsheirer.channel.metadata;

Expand All @@ -29,16 +26,16 @@
import io.github.dsheirer.identifier.decoder.DecoderLogicalChannelNameIdentifier;
import io.github.dsheirer.preference.PreferenceType;
import io.github.dsheirer.sample.Listener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.table.AbstractTableModel;
import java.awt.EventQueue;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.table.AbstractTableModel;

public class ChannelMetadataModel extends AbstractTableModel implements IChannelMetadataUpdateListener
{
Expand Down Expand Up @@ -84,6 +81,47 @@ public void preferenceUpdated(PreferenceType preferenceType)
}
}

/**
* Creates a diagnostic description of the channel metadata and metadata-channel map.
* @return diagnostic description.
*/
public String getDiagnosticInformation()
{
StringBuilder sb = new StringBuilder();
Map<ChannelMetadata,Channel> mapCopy = new HashMap<>(mMetadataChannelMap);
List<ChannelMetadata> metadataCopy = new ArrayList<>(mChannelMetadata);

sb.append("Channel Metadata Model Diagnostics\n");

for(ChannelMetadata channelMetadata: metadataCopy)
{
sb.append("\n--------------- CHANNEL METADATA ITEM --------------------\n\n");
if(mapCopy.containsKey(channelMetadata))
{
Channel channel = mapCopy.get(channelMetadata);
sb.append("\tMapped Channel:").append(channel).append("\n");
sb.append("\t\tSource Configuration: ").append(channel.getSourceConfiguration()).append("\n");
}
else
{
sb.append("\tMapped Channel: **Channel Metadata Is Not In the Metadata:Channel Map**\n");
}

sb.append(channelMetadata.getDescription());
}

//Check for orphaned map entries that don't match the current channel metadata list.
for(Map.Entry<ChannelMetadata,Channel> entry: mapCopy.entrySet())
{
if(!metadataCopy.contains(entry.getKey()))
{
sb.append("\n\tWARNING: orphaned Metadata Channel map entry - channel: " + entry.getValue()).append("\n");
}
}

return sb.toString();
}

public void dispose()
{
MyEventBus.getGlobalEventBus().unregister(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.github.dsheirer.channel.metadata.ChannelAndMetadata;
import io.github.dsheirer.channel.metadata.ChannelMetadata;
import io.github.dsheirer.channel.metadata.ChannelMetadataModel;
import io.github.dsheirer.channel.state.AbstractChannelState;
import io.github.dsheirer.controller.channel.event.ChannelStartProcessingRequest;
import io.github.dsheirer.controller.channel.event.ChannelStopProcessingRequest;
import io.github.dsheirer.controller.channel.event.PreloadDataContent;
Expand Down Expand Up @@ -52,6 +53,7 @@
import io.github.dsheirer.util.ThreadPool;
import java.awt.GraphicsEnvironment;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -72,9 +74,10 @@
*/
public class ChannelProcessingManager implements Listener<ChannelEvent>
{
private static final String DIVIDER = "-------------------------------------------------------------------------\n";
private final static Logger mLog = LoggerFactory.getLogger(ChannelProcessingManager.class);
private static final String TUNER_UNAVAILABLE_DESCRIPTION = "TUNER UNAVAILABLE";
private Map<Channel,ProcessingChain> mProcessingChains = new ConcurrentHashMap<>();
private Map<Channel,ProcessingChain> mProcessingChainsMap = new ConcurrentHashMap<>();
private Lock mLock = new ReentrantLock();

private ChannelSourceEventErrorListener mSourceErrorListener = new ChannelSourceEventErrorListener();
Expand Down Expand Up @@ -131,7 +134,7 @@ private boolean isProcessing(Channel channel)

try
{
isProcessing = mProcessingChains.containsKey(channel) && mProcessingChains.get(channel).isProcessing();
isProcessing = mProcessingChainsMap.containsKey(channel) && mProcessingChainsMap.get(channel).isProcessing();
}
finally
{
Expand All @@ -147,7 +150,7 @@ private boolean isProcessing(Channel channel)
*/
public boolean isProcessing()
{
return !mProcessingChains.isEmpty();
return !mProcessingChainsMap.isEmpty();
}

/**
Expand All @@ -156,7 +159,7 @@ public boolean isProcessing()
*/
public ProcessingChain getProcessingChain(Channel channel)
{
return mProcessingChains.get(channel);
return mProcessingChainsMap.get(channel);
}

/**
Expand All @@ -175,7 +178,7 @@ public Channel getChannel(ProcessingChain processingChain)

try
{
for(Map.Entry<Channel,ProcessingChain> entry : mProcessingChains.entrySet())
for(Map.Entry<Channel,ProcessingChain> entry : mProcessingChainsMap.entrySet())
{
if(entry.getValue() == processingChain)
{
Expand Down Expand Up @@ -206,7 +209,7 @@ private Channel getChannel(TunerChannelSource tunerChannelSource)

try
{
for(Map.Entry<Channel,ProcessingChain> entry : mProcessingChains.entrySet())
for(Map.Entry<Channel,ProcessingChain> entry : mProcessingChainsMap.entrySet())
{
if(entry.getValue().hasSource(tunerChannelSource))
{
Expand Down Expand Up @@ -556,10 +559,10 @@ private boolean addProcessingChain(Channel channel, ProcessingChain processingCh

try
{
if(!mProcessingChains.containsKey(channel))
if(!mProcessingChainsMap.containsKey(channel))
{
added = true;
mProcessingChains.put(channel, processingChain);
mProcessingChainsMap.put(channel, processingChain);
getChannelMetadataModel().add(new ChannelAndMetadata(channel, processingChain.getChannelState().getChannelMetadata()));
}
}
Expand All @@ -584,7 +587,7 @@ private ProcessingChain removeProcessingChain(Channel channel)

try
{
removed = mProcessingChains.remove(channel);
removed = mProcessingChainsMap.remove(channel);

if(removed != null)
{
Expand Down Expand Up @@ -660,7 +663,7 @@ public void shutdown()
mDelayedChannelStartTasks.remove(delayedTask);
}

List<Channel> channelsToStop = new ArrayList<>(mProcessingChains.keySet());
List<Channel> channelsToStop = new ArrayList<>(mProcessingChainsMap.keySet());

for(Channel channel : channelsToStop)
{
Expand All @@ -683,7 +686,7 @@ public void shutdown()
public void convertToTrafficChannel(ChannelConversionRequest request)
{
//Update the channel to processing chain map.
ProcessingChain processingChain = mProcessingChains.remove(request.getCurrentChannel());
ProcessingChain processingChain = mProcessingChainsMap.remove(request.getCurrentChannel());

if(processingChain != null)
{
Expand All @@ -697,7 +700,7 @@ public void convertToTrafficChannel(ChannelConversionRequest request)
request.getTrafficChannel().setProcessing(true);
});

mProcessingChains.put(request.getTrafficChannel(), processingChain);
mProcessingChainsMap.put(request.getTrafficChannel(), processingChain);
mChannelMetadataModel.updateChannelMetadataToChannelMap(processingChain.getChannelState().getChannelMetadata(),
request.getTrafficChannel());

Expand Down Expand Up @@ -803,7 +806,7 @@ private class ChannelSourceEventErrorListener implements Listener<SourceEvent>

try
{
for(Map.Entry<Channel,ProcessingChain> entry: mProcessingChains.entrySet())
for(Map.Entry<Channel,ProcessingChain> entry: mProcessingChainsMap.entrySet())
{
if(entry.getValue().hasSource(sourceEvent.getSource()))
{
Expand Down Expand Up @@ -841,4 +844,54 @@ private class ChannelSourceEventErrorListener implements Listener<SourceEvent>
}
}
}

/**
* Creates a diagnostic report.
* @return report text.
*/
public String getDiagnosticInformation()
{
StringBuilder sb = new StringBuilder();
sb.append("Channel Processing Manager - Diagnostics Report\n\n");
sb.append(DIVIDER);
sb.append("\tChannel to Processing Chain Map Contents\n");
Map<Channel,ProcessingChain> mapCopy = new HashMap<>(mProcessingChainsMap);
for(Map.Entry<Channel,ProcessingChain> entry: mapCopy.entrySet())
{
sb.append("\n\n--------------- CHANNEL:PROCESSING CHAIN MAP ENTRY --------------------\n");
try
{
Channel channel = entry.getKey();
sb.append("\tChannel: " + channel).append("\n");
sb.append("\t\tSource Configuration: " + channel.getSourceConfiguration()).append("\n");
ProcessingChain chain = entry.getValue();
sb.append("\tProcessing Chain - Processing: ").append(chain.isProcessing()).append("\n");
AbstractChannelState state = chain.getChannelState();
sb.append("Channel State: ").append(state.getClass()).append("\n");
for(ChannelMetadata metadata: state.getChannelMetadata())
{
sb.append(metadata.getDescription()).append("\n");
}

Source source = chain.getSource();

if(source != null)
{
sb.append("Channel Source Class: " + source.getClass()).append("\n");
sb.append("\t\tTo String:").append(source).append("\n");
sb.append("\t\tHash:").append(Integer.toHexString(source.hashCode()).toUpperCase()).append("\n");
}
else
{
sb.append("Channel Source: (null)\n");
}
}
catch(Throwable t)
{
sb.append("\tError while logging diagnostics of map entry - " + t.getMessage()).append("\n");
}
}

return sb.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2023 Dennis Sheirer
* Copyright (C) 2014-2024 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -147,6 +147,7 @@ public String getStateDescription()
sb.append(" REQUESTED CF: ").append(FREQUENCY_FORMAT.format(requestedCenterFrequency / 1E6d));
sb.append(" MIXER:").append(FREQUENCY_FORMAT.format(appliedFrequencyOffset / 1E6d));
sb.append(" | Polyphase Indices: ").append(indexes);
sb.append(" HASH:").append(Integer.toHexString(pcs.hashCode()).toUpperCase());
}

return sb.toString();
Expand Down
Loading

0 comments on commit 7b9adc1

Please sign in to comment.