Changeset 1707


Ignore:
Timestamp:
Jun 26, 2010, 9:51:11 PM (11 years ago)
Author:
Paul Lelgemann
Message:

o KeySearcher: more precise statistics in the new visualization of distributed search

Location:
trunk/CrypPlugins/KeySearcher
Files:
2 added
1 deleted
5 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/KeySearcher/Converter/TimeSpanToStringConverter.cs

    r1706 r1707  
    55namespace KeySearcherConverter
    66{
    7     public class TimeSpanConverter : IValueConverter
     7    public class TimeSpanToStringConverter : IValueConverter
    88    {
    99        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
     
    1919                return "~";
    2020
     21            var seconds = timeSpan.Seconds;
     22            if (seconds == 0 && timeSpan.Milliseconds > 0)
     23                seconds = 1;
     24
    2125            if (timeSpan.Days > 0)
    2226                return string.Format("{0:D2} days, {1:D2}:{2:D2}:{3:D2}", timeSpan.Days, timeSpan.Hours,
    23                                      timeSpan.Minutes, timeSpan.Seconds);
     27                                     timeSpan.Minutes, seconds);
    2428
    25             return string.Format("{0:D2}:{1:D2}:{2:D2}", timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
     29            return string.Format("{0:D2}:{1:D2}:{2:D2}", timeSpan.Hours, timeSpan.Minutes, seconds);
    2630        }
    2731
  • trunk/CrypPlugins/KeySearcher/KeySearcher.cs

    r1705 r1707  
    619619        {
    620620            GuiLogMessage("Launching p2p based bruteforce logic...", NotificationLevel.Info);
    621             ValidateConnectionToPeerToPeerSystem();
    622621
    623622            try
     
    633632            }
    634633        }
    635 
    636 
    637         #region P2P connection validation
    638 
    639         private void ValidateConnectionToPeerToPeerSystem()
    640         {
    641             if (P2PManager.IsConnected)
    642             {
    643                 return;
    644             }
    645 
    646             if(settings.AutoconnectPeerToPeer)
    647             {
    648                 HandleAutoconnect();
    649             } else
    650             {
    651                 GuiLogMessage("P2P network not connected and autoconnect disabled. Cannot compute job.",
    652                               NotificationLevel.Error);
    653             }
    654         }
    655 
    656         private void HandleAutoconnect()
    657         {
    658             P2PManager.ConnectionManager.OnP2PConnectionStateChangeOccurred += HandleConnectionStateChange;
    659             connectResetEvent = new AutoResetEvent(false);
    660 
    661             P2PManager.Connect();
    662 
    663             connectResetEvent.WaitOne();
    664 
    665             if (P2PManager.IsConnected)
    666             {
    667                 GuiLogMessage("P2P network was connected due to plugin setting.",
    668                               NotificationLevel.Info);
    669             }
    670             else
    671             {
    672                 GuiLogMessage("P2P network could not be connected.",
    673                               NotificationLevel.Error);
    674             }
    675         }
    676 
    677         void HandleConnectionStateChange(object sender, bool newState)
    678         {
    679             connectResetEvent.Set();
    680         }
    681 
    682         #endregion
    683634
    684635        internal LinkedList<ValueKey> BruteForceWithLocalSystem(KeyPattern.KeyPattern pattern, bool redirectResultsToStatisticsGenerator = false)
  • trunk/CrypPlugins/KeySearcher/KeySearcher.csproj

    r1705 r1707  
    103103  </ItemGroup>
    104104  <ItemGroup>
    105     <Compile Include="Converter\TimeSpanConverter.cs" />
     105    <Compile Include="Converter\TimeSpanToStringConverter.cs" />
    106106    <Compile Include="Converter\DateTimeConverter.cs" />
    107107    <Compile Include="Converter\LongToSizeMetricString.cs" />
    108     <Compile Include="Converter\TimeSpanToRoundedStringConverter.cs" />
    109108    <Compile Include="Converter\TrueToVisibleOrCollapsedConverter.cs" />
    110109    <Compile Include="Converter\FalseToVisibleConverter.cs" />
     
    114113    <Compile Include="KeyPattern\KeyPatternPool.cs" />
    115114    <Compile Include="KeySearcher.cs" />
     115    <Compile Include="P2P\Helper\ConnectionHelper.cs" />
    116116    <Compile Include="P2P\Presentation\StatisticsGenerator.cs" />
    117117    <Compile Include="P2P\Presentation\StatusContainer.cs" />
  • trunk/CrypPlugins/KeySearcher/P2P/DistributedBruteForceManager.cs

    r1705 r1707  
    22using System.Diagnostics;
    33using System.Numerics;
    4 using System.Threading;
    54using System.Windows.Threading;
     5using Cryptool.P2P;
    66using Cryptool.PluginBase;
    77using KeySearcher.Helper;
    88using KeySearcher.KeyPattern;
    99using KeySearcher.P2P.Exceptions;
     10using KeySearcher.P2P.Helper;
    1011using KeySearcher.P2P.Presentation;
    1112using KeySearcher.P2P.Storage;
     
    1819    {
    1920        private readonly StorageKeyGenerator keyGenerator;
    20         private readonly KeyPoolTree keyPoolTree;
    2121        private readonly KeySearcher keySearcher;
    2222        private readonly KeySearcherSettings settings;
     23        private readonly KeyQualityHelper keyQualityHelper;
    2324        private readonly P2PQuickWatchPresentation quickWatch;
    2425        private readonly KeyPatternPool patternPool;
     
    2728        internal readonly Stopwatch StopWatch;
    2829
     30        private KeyPoolTree keyPoolTree;
     31
    2932        public DistributedBruteForceManager(KeySearcher keySearcher, KeyPattern.KeyPattern keyPattern, KeySearcherSettings settings,
    3033                                            KeyQualityHelper keyQualityHelper, P2PQuickWatchPresentation quickWatch)
     
    3235            this.keySearcher = keySearcher;
    3336            this.settings = settings;
     37            this.keyQualityHelper = keyQualityHelper;
    3438            this.quickWatch = quickWatch;
    3539
     
    4852            StatisticsGenerator = new StatisticsGenerator(status, quickWatch, keySearcher, settings, this);
    4953            quickWatch.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(UpdateStatusContainerInQuickWatch));
     54        }
     55
     56        public void Execute()
     57        {
     58            status.CurrentOperation = "Initializing connection to the peer-to-peer system";
     59            new ConnectionHelper(keySearcher, settings).ValidateConnectionToPeerToPeerSystem();
     60
     61            if (!P2PManager.IsConnected)
     62            {
     63                keySearcher.GuiLogMessage("Unable to use peer-to-peer system.", NotificationLevel.Error);
     64                return;
     65            }
    5066
    5167            status.CurrentOperation = "Initializing distributed key pool tree";
    5268            keyPoolTree = new KeyPoolTree(patternPool, this.keySearcher, keyQualityHelper, keyGenerator, status, StatisticsGenerator);
    53            
     69
    5470            keySearcher.GuiLogMessage(
    5571                "Total amount of patterns: " + patternPool.Length + ", each containing " + patternPool.PartSize +
    5672                " keys.", NotificationLevel.Info);
    5773            status.CurrentOperation = "Ready for calculation";
    58         }
    5974
    60         public void Execute()
    61         {
    6275            status.StartDate = keyPoolTree.StartDate();
    6376
     
    155168            status.IsCurrentProgressIndeterminate = false;
    156169            status.CurrentOperation = "Idle";
     170            status.RemainingTimeTotal = new TimeSpan(0);
    157171        }
    158172
  • trunk/CrypPlugins/KeySearcher/P2P/Presentation/StatisticsGenerator.cs

    r1705 r1707  
    99using KeySearcher.KeyPattern;
    1010using KeySearcherPresentation.Controls;
     11using Timer = System.Timers.Timer;
    1112
    1213namespace KeySearcher.P2P.Presentation
     
    2021        private readonly BigInteger totalAmountOfChunks;
    2122        private readonly Stopwatch stopWatch;
     23        private readonly Timer elapsedTimeTimer;
     24        private readonly Timer trafficUpdateTimer;
    2225
    2326        private DateTime lastDateOfGlobalStatistics;
     
    4447
    4548            status.PropertyChanged += StatusPropertyChanged;
     49
     50            elapsedTimeTimer = new Timer(1000);
     51            elapsedTimeTimer.Elapsed += ElapsedTimeTimerTick;
     52            elapsedTimeTimer.Start();
     53
     54            trafficUpdateTimer = new Timer(10000);
     55            trafficUpdateTimer.Elapsed += TrafficUpdateTimerTick;
     56            trafficUpdateTimer.Start();
     57        }
     58
     59        void TrafficUpdateTimerTick(object sender, System.Timers.ElapsedEventArgs e)
     60        {
     61            UpdateTrafficStatistics();
     62        }
     63
     64        void ElapsedTimeTimerTick(object sender, EventArgs e)
     65        {
     66            status.ElapsedTime = DateTime.Now.Subtract(status.StartDate);
     67
     68            if (status.RemainingTimeTotal > new TimeSpan(0))
     69                status.RemainingTimeTotal = status.RemainingTimeTotal.Subtract(TimeSpan.FromSeconds(1));
    4670        }
    4771
     
    5478                    break;
    5579                case "StoredBytes":
    56                     status.SentBytesByLinkManager = P2PManager.P2PBase.TotalBytesSentOnAllLinks();
     80                    UpdateTrafficStatistics();
    5781                    break;
    5882                case "RetrievedBytes":
    59                     status.ReceivedBytesByLinkManager = P2PManager.P2PBase.TotalBytesReceivedOnAllLinks();
     83                    UpdateTrafficStatistics();
    6084                    break;
    6185            }
     86        }
     87
     88        private void UpdateTrafficStatistics()
     89        {
     90            status.SentBytesByLinkManager = P2PManager.P2PBase.TotalBytesSentOnAllLinks();
     91            status.ReceivedBytesByLinkManager = P2PManager.P2PBase.TotalBytesReceivedOnAllLinks();
     92            status.TotalBytesByLinkManager = status.ReceivedBytesByLinkManager + status.SentBytesByLinkManager;
    6293        }
    6394
     
    72103            var overheadInTicks = (double)status.DhtOverheadInReadableTime.Ticks /
    73104                           distributedBruteForceManager.StopWatch.Elapsed.Ticks;
    74             var overheadInPercent = Math.Round(overheadInTicks, 2);
    75             overheadInPercent *= 100;
     105            var overheadInPercent = overheadInTicks * 100;
     106            overheadInPercent = Math.Round(overheadInPercent, 2);
     107           
    76108            status.DhtOverheadInPercent = overheadInPercent + " %";
    77109        }
     
    125157                status.RemainingTimeTotal = new TimeSpan(-1);
    126158            }
    127 
    128             status.ElapsedTime = DateTime.Now.Subtract(status.StartDate);
    129159
    130160            lastDateOfGlobalStatistics = DateTime.Now;
  • trunk/CrypPlugins/KeySearcher/Presentation/Controls/P2PQuickWatchPresentation.xaml

    r1705 r1707  
    22        <UserControl.Resources>
    33                <Converter:TrueToVisibleOrCollapsedConverter x:Key="TrueToVisibleOrCollapsedConverter" />
    4         <Converter:TimeSpanToRoundedStringConverter x:Key="TimeSpanToRoundedStringConverter" />
    54        <Converter:LongToSizeMetricString x:Key="LongToSizeMetricString" />
    65        <Converter:DateTimeConverter x:Key="DateTimeConverter" />
    7         <Converter:TimeSpanConverter x:Key="TimeSpanConverter" />
     6        <Converter:TimeSpanToStringConverter x:Key="TimeSpanToStringConverter" />
    87        <RotateTransform x:Key="HeaderRotate" Angle="270" />
    98        <Style x:Key="ValueRow1">
     
    6968                        <Label Content="{Binding EstimatedFinishDate, FallbackValue=-}" Style="{StaticResource ValueRow3}" Grid.Column="3" />
    7069                        <Label Content="Elapsed:" Grid.Column="2" Grid.Row="2" />
    71                         <Label Content="{Binding ElapsedTime, FallbackValue=-, Converter={StaticResource TimeSpanConverter}}" Style="{StaticResource ValueRow2}" Grid.Column="2" Grid.Row="2" />
     70                        <Label Content="{Binding ElapsedTime, FallbackValue=-, Converter={StaticResource TimeSpanToStringConverter}}" Style="{StaticResource ValueRow2}" Grid.Column="2" Grid.Row="2" />
    7271                        <Label Content="Remaining:" Grid.Column="3" Grid.Row="2" />
    73                         <Label Content="{Binding RemainingTimeTotal, FallbackValue=-, Converter={StaticResource TimeSpanConverter}}" Style="{StaticResource ValueRow3}" Grid.Column="3" Grid.Row="2" />
     72                        <Label Content="{Binding RemainingTimeTotal, FallbackValue=-, Converter={StaticResource TimeSpanToStringConverter}}" Style="{StaticResource ValueRow3}" Grid.Column="3" Grid.Row="2" />
    7473                    </Grid>
    7574                                </Border>
     
    9998                            <ProgressBar Value="{Binding ProgressOfCurrentChunk, FallbackValue=0}" IsIndeterminate="{Binding IsCurrentProgressIndeterminate, FallbackValue=false}" Maximum="1" />
    10099                            <Viewbox>
    101                                 <Label Content="{Binding RemainingTime, Converter={StaticResource TimeSpanConverter}}" HorizontalAlignment="Center" Grid.Column="2" Grid.Row="1" />
     100                                <Label Content="{Binding RemainingTime, Converter={StaticResource TimeSpanToStringConverter}}" HorizontalAlignment="Center" Grid.Column="2" Grid.Row="1" />
    102101                            </Viewbox>
    103102                        </Grid>
     
    132131                        <Label Content="{Binding RequestsPerNode, FallbackValue=-}" Style="{StaticResource ValueRow3}" Grid.Column="3" Grid.Row="1" />
    133132                        <Label Content="Overhead (abs):" Grid.Column="2" Grid.Row="2" />
    134                         <Label Content="{Binding DhtOverheadInReadableTime, FallbackValue=-, Converter={StaticResource TimeSpanToRoundedStringConverter}}" Style="{StaticResource ValueRow2}" Grid.Column="2" Grid.Row="2" />
     133                        <Label Content="{Binding DhtOverheadInReadableTime, FallbackValue=-, Converter={StaticResource TimeSpanToStringConverter}}" Style="{StaticResource ValueRow2}" Grid.Column="2" Grid.Row="2" />
    135134                        <Label Content="Overhead (%):" Grid.Column="3" Grid.Row="2" />
    136135                        <Label Content="{Binding DhtOverheadInPercent, FallbackValue=-}" Style="{StaticResource ValueRow3}" Grid.Column="3" Grid.Row="2" />
Note: See TracChangeset for help on using the changeset viewer.