• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #region Copyright notice and license
2 
3 // Copyright 2015 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #endregion
18 
19 using System;
20 using System.IO;
21 using System.Threading;
22 using Grpc.Core.Internal;
23 
24 namespace Grpc.Core.Profiling
25 {
26     internal struct ProfilerEntry
27     {
28         public enum Type
29         {
30             BEGIN,
31             END,
32             MARK
33         }
34 
ProfilerEntryGrpc.Core.Profiling.ProfilerEntry35         public ProfilerEntry(Timespec timespec, Type type, string tag)
36         {
37             this.timespec = timespec;
38             this.type = type;
39             this.tag = tag;
40         }
41 
42         public Timespec timespec;
43         public Type type;
44         public string tag;
45 
ToStringGrpc.Core.Profiling.ProfilerEntry46         public override string ToString()
47         {
48             // mimic the output format used by C core.
49             return string.Format(
50                 "{{\"t\": {0}.{1}, \"thd\":\"unknown\", \"type\": \"{2}\", \"tag\": \"{3}\", " +
51                 "\"file\": \"unknown\", \"line\": 0, \"imp\": 0}}",
52                 timespec.TimevalSeconds, timespec.TimevalNanos.ToString("D9"),
53                 GetTypeAbbreviation(type), tag);
54         }
55 
GetTypeAbbreviationGrpc.Core.Profiling.ProfilerEntry56         internal static string GetTypeAbbreviation(Type type)
57         {
58             switch (type)
59             {
60                 case Type.BEGIN:
61                     return "{";
62 
63                 case Type.END:
64                     return "}";
65 
66                 case Type.MARK:
67                     return ".";
68                 default:
69                     throw new ArgumentException("Unknown type");
70             }
71         }
72     }
73 }
74