소스 검색

计算出关键函数的耗时值,输出到log中便于日常问题查询。

sat23 3 년 전
부모
커밋
1c83d175ff
1개의 변경된 파일26개의 추가작업 그리고 4개의 파일을 삭제
  1. 26 4
      SCBC Factory Tools/Business/CommonMethod.cs

+ 26 - 4
SCBC Factory Tools/Business/CommonMethod.cs

@@ -21,6 +21,7 @@ using System.Web;
 using System.Security.Cryptography.X509Certificates;
 using System.Net.Security;
 using System.Runtime.InteropServices;
+using System.Diagnostics;
 
 namespace MOKA_Factory_Tools
 {
@@ -380,6 +381,10 @@ namespace MOKA_Factory_Tools
                 ContentType = "application/x-www-form-urlencoded",
                 KeepAlive = false
             };
+
+            // 计算函数耗时;
+            Stopwatch watch = new Stopwatch();
+            watch.Start();
             switch (keymessage)
             {
                 case "DeviceID":
@@ -818,6 +823,8 @@ namespace MOKA_Factory_Tools
                         break;
                     }
             }
+            watch.Stop();
+            Log.WriteInfoLog(string.Format("[GetKeys] order={0},sn={1},keytype={2},keymessage={3}, Elapsed={4}", order,sn,keytype,keymessage,watch.Elapsed.TotalMilliseconds));
             return true;
         }
 
@@ -850,6 +857,9 @@ namespace MOKA_Factory_Tools
                 KeepAlive = false
             };
 
+            // 计算函数耗时;
+            Stopwatch watch = new Stopwatch();
+            watch.Start();
             item.URL = url + "/getWidevineAndAttestation.do?";
             item.Postdata = "type=" + keytype + "&order=" + order + "&sn=" + sn;
             HttpResult result = http.GetHtml(item);
@@ -870,6 +880,8 @@ namespace MOKA_Factory_Tools
                 return false;
             }
 
+            watch.Stop();
+            Log.WriteInfoLog(string.Format("[getWidevineAndAttestation] order={0},sn={1},keytype={2},Elapsed={3}", order, sn, keytype, watch.Elapsed.TotalMilliseconds));
             return true;
         }
 
@@ -891,6 +903,9 @@ namespace MOKA_Factory_Tools
                 KeepAlive = false
             };
 
+            // 计算函数耗时;
+            Stopwatch watch = new Stopwatch();
+            watch.Start();
             item.URL = url + "/getAcasKey.do?";
             item.Postdata = "type=" + keytype + "&sn=" + sn;
             if (sn.Trim().Length > 0)
@@ -916,7 +931,8 @@ namespace MOKA_Factory_Tools
                 ReportErrormsg("Fail to get ACAS key", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
                 return false;
             }
-
+            watch.Stop();
+            Log.WriteInfoLog(string.Format("[getAcasKey] order={0},sn={1},keytype={2},Elapsed={3}", order, sn, keytype, watch.Elapsed.TotalMilliseconds));
             return true;
         }
 
@@ -929,6 +945,9 @@ namespace MOKA_Factory_Tools
         /// <returns></returns>
         public static bool ReportErrormsg(string reportType, string reportData, SQLiteConnection sqliteConn)
         {
+            // 计算函数耗时;
+            Stopwatch watch = new Stopwatch();
+            watch.Start();
             ErrorInfo ErrorInfo1 = new ErrorInfo { reportType = reportType, reportData = reportData.Replace("'", ""), version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(), factory = FactoryName, mac = TestMode.MAC, reportTime = System.DateTime.Now.ToString(("yyyy-MM-dd HH:mm:ss")) };
             string jsonError = Newtonsoft.Json.JsonConvert.SerializeObject(ErrorInfo1, Newtonsoft.Json.Formatting.Indented);
             HttpHelper http = new HttpHelper();
@@ -961,13 +980,16 @@ namespace MOKA_Factory_Tools
                 JObject jObject = JObject.Parse(ParseText);
                 string message = jObject["message"].Value<string>();
                 string code = jObject["code"].Value<string>();
-                if (code == "1000")
-                    return true;
-                else
+                if (code != "1000")
                 {
                     Log.WriteErrorLog("\r\nError report return error:\r\n" + ParseText + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + jsonError);
                     return false;
                 }
+
+                watch.Stop();
+                Log.WriteInfoLog(string.Format("[ReportErrormsg] Elapsed={0}", watch.Elapsed.TotalMilliseconds));
+
+                return true;
             }
             catch (Exception ex)
             {