Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Critical bug produces incorrect CSV import from Profile Analyzer.

Discussion in 'Editor & General Support' started by qsleonard, Feb 7, 2022.

  1. qsleonard

    qsleonard

    Joined:
    Dec 26, 2018
    Posts:
    15
    Code (CSharp):
    1. void SaveMarkerTableCSV()
    2.         {
    3.             if (m_ProfileDataView.analysis == null)
    4.                 return;
    5.  
    6.             string path = EditorUtility.SaveFilePanel("Save marker table CSV data", "", "markerTable.csv", "csv");
    7.             if (path.Length != 0)
    8.             {
    9.                 var analytic = ProfileAnalyzerAnalytics.BeginAnalytic();
    10.                 using (StreamWriter file = new StreamWriter(path))
    11.                 {
    12.                     file.Write("Name");
    13.                     file.Write("Median Time, Min Time, Max Time, ");
    14.                     file.Write("Median Frame Index, Min Frame Index, Max Frame Index, ");
    15.                     file.Write("Min Depth, Max Depth, ");
    16.                     file.Write("Total Time, ");
    17.                     file.Write("Mean Time, Time Lower Quartile, Time Upper Quartile, ");
    18.                     file.Write("Count Total, Count Median, Count Min, Count Max, ");
    19.                     file.Write("Number of frames containing Marker, ");
    20.                     file.Write("First Frame Index, ");
    21.                     file.Write("Time Min Individual, Time Max Individual, ");
    22.                     file.Write("Min Individual Frame, Max Individual Frame, ");
    23.                     file.WriteLine("Time at Median Frame");
    24.  
    25.                     List<MarkerData> markerData = m_ProfileDataView.analysis.GetMarkers();
    26.                     markerData.Sort();
    27.                     foreach (MarkerData marker in markerData)
    28.                     {
    29.                         var markerName = marker.name;
    30.                         if (markerName.IndexOf('\"') >= 0)
    31.                             // replace all double quotation marks with single ones to avoid this breaking the escaping with double quotation marks
    32.                             markerName = markerName.Replace('\"', '\'');
    33.  
    34.                         int medianFrameIndex = m_ProfileAnalyzerWindow.GetRemappedUIFrameIndex(marker.medianFrameIndex, m_ProfileDataView);
    35.                         int minFrameIndex = m_ProfileAnalyzerWindow.GetRemappedUIFrameIndex(marker.minFrameIndex, m_ProfileDataView);
    36.                         int maxFrameIndex = m_ProfileAnalyzerWindow.GetRemappedUIFrameIndex(marker.maxFrameIndex, m_ProfileDataView);
    37.                         int firstFrameIndex = m_ProfileAnalyzerWindow.GetRemappedUIFrameIndex(marker.firstFrameIndex, m_ProfileDataView);
    38.                         int minIndividualFrameIndex = m_ProfileAnalyzerWindow.GetRemappedUIFrameIndex(marker.minIndividualFrameIndex, m_ProfileDataView);
    39.                         int maxIndividualFrameIndex = m_ProfileAnalyzerWindow.GetRemappedUIFrameIndex(marker.maxIndividualFrameIndex, m_ProfileDataView);
    40.  
    41.                         // "Escape" marker names in case it has commas in it.
    42.                         file.Write("{0}", markerName);
    43.                         file.Write("{0},{1},{2},",
    44.                             marker.msMedian, marker.msMin, marker.msMax);
    45.                         file.Write("{0},{1},{2},",
    46.                             medianFrameIndex, minFrameIndex, maxFrameIndex);
    47.                         file.Write("{0},{1},",
    48.                             marker.minDepth, marker.maxDepth);
    49.                         file.Write("{0},",
    50.                             marker.msTotal);
    51.                         file.Write("{0},{1},{2},",
    52.                             marker.msMean, marker.msLowerQuartile, marker.msUpperQuartile);
    53.                         file.Write("{0},{1},{2},{3},",
    54.                             marker.count, marker.countMedian, marker.countMin, marker.countMax);
    55.                         file.Write("{0},", marker.presentOnFrameCount);
    56.                         file.Write("{0},", firstFrameIndex);
    57.                         file.Write("{0},{1},",
    58.                             marker.msMinIndividual, marker.msMaxIndividual);
    59.                         file.Write("{0},{1},",
    60.                             minIndividualFrameIndex, maxIndividualFrameIndex);
    61.                         file.WriteLine("{0}", marker.msAtMedian);
    62.                     }
    63.                 }
    64.                 ProfileAnalyzerAnalytics.SendUIButtonEvent(ProfileAnalyzerAnalytics.UIButton.ExportSingleFrames, analytic);
    65.             }
    66.         }

    The problem is that CSV stands for "Comma-Separated Values" and a developer of this code forgot that float-point values also contain commas. Therefore imported table is totally ruined (instead of placing float-point values into the cells, it by standard creates new garbage colums).

    upload_2022-2-7_10-57-29.png

    upload_2022-2-7_10-29-19.png

    P.S.
    Also I want to say that having REAL Mean value in the Analyzer window would be very useful, as now "Mean" means "total time divided by total calls count". Maybe it is useful for someone, but for me Mean formula "total time divided by FRAMES count" makes a lot more sense, because right now some calls like GC.Collect could be on the top, despite they are called rarely.

    When I trying to optimize the game and get a sense whats going on generally, I want to pay attention to mean contribution of the calls over all the frames. And it is very confusing to see such sporadic calls on the top. Even if they take great amount of time to execute in particular frame, their impact is minor when we trying to analyze a whole game.
     
    Last edited: Feb 7, 2022
  2. alexeyzakharov

    alexeyzakharov

    Joined:
    Jul 2, 2014
    Posts:
    507
    thanks for reporting the issue and the clear explanation @qsleonard !

    do you mind filing a bug - we'll fix this asap.

    as a workaround could you please try to set your locale to en-US before exporting and importing csv data - that should result to numbers being written as 1234.56 with '.' as a decimal separator.
     
    qsleonard and MartinTilo like this.