Exemple #1
0
 public CtfStream(CtfPropertyBag properties)
 {
     ID            = properties.GetInt("id");
     _header       = properties.GetType("event.header");
     _context      = properties.GetType("packet.context");
     _eventContext = properties.GetType("event.context");
 }
 public CtfFloat(CtfPropertyBag bag)
     : base(CtfTypes.Float)
 {
     Exp       = bag.GetInt("exp_dig");
     Mant      = bag.GetInt("mant_dig");
     ByteOrder = bag.GetString("byte_order");
     _align    = bag.GetInt("align");
 }
Exemple #3
0
 public CtfClock(CtfPropertyBag bag)
 {
     Name        = bag.GetString("name");
     UUID        = new Guid(bag.GetString("uuid"));
     Description = bag.GetString("description");
     Frequency   = bag.GetUlong("freq");
     Offset      = bag.GetUlong("offset");
 }
Exemple #4
0
 public CtfEnvironment(CtfPropertyBag bag)
 {
     HostName    = bag.GetString("hostname");
     Domain      = bag.GetString("domain");
     TracerName  = bag.GetString("tracer");
     TracerMajor = bag.GetIntOrNull("tracer_major") ?? 0;
     TracerMinor = bag.GetIntOrNull("tracer_minor") ?? 0;
 }
Exemple #5
0
 public CtfTrace(CtfPropertyBag bag)
 {
     Major     = bag.GetShort("major");
     Minor     = bag.GetShort("minor");
     UUID      = new Guid(bag.GetString("uuid"));
     ByteOrder = bag.GetString("byte_order");
     Header    = bag.GetStruct("packet.header");
 }
        public CtfMetadataDeclaration(CtfDeclarationTypes declaration, CtfPropertyBag bag, string name, string text)
        {
            Definition = declaration;
            Properties = bag;
            Name       = name;
            RawText    = text;

            Debug.Assert(name == null || name == name.Trim());
        }
Exemple #7
0
        public CtfEvent(CtfPropertyBag bag)
        {
            ID       = bag.GetInt("id");
            Name     = bag.GetString("name");
            Stream   = bag.GetInt("stream_id");
            LogLevel = bag.GetUInt("loglevel");

            Definition = bag.GetStruct("fields");
        }
Exemple #8
0
        private CtfPropertyBag GetPropertyBag(string str, int start, int stop)
        {
            Debug.Assert(str[start] == '{');
            CtfPropertyBag result = new CtfPropertyBag();

            foreach (string rawStatement in EnumerateStatements(str, start + 1, stop))
            {
                string statement = StripComments(rawStatement);

                int i = statement.IndexOf('=');
                if (i <= 0)
                {
                    continue;
                }

                if (statement[i - 1] == ':')
                {
                    string name = statement.Substring(0, i - 1).Trim();

                    int open  = statement.IndexOf('{', i + 1);
                    int close = FindCloseBrace(statement, open);

                    if (close > stop || close == -1)
                    {
                        string[] structNameParts = statement.Substring(i + 1).Trim().Split(' ');

                        if (structNameParts.Length != 2 || structNameParts[0] != "struct")
                        {
                            throw new InvalidOperationException();
                        }

                        CtfUnresolvedType unresolved = new CtfUnresolvedType(structNameParts[1]);
                        result.AddValue(name, unresolved);
                    }
                    else
                    {
                        CtfField[] fields = ParseStructFields(statement, open, close).ToArray();
                        result.AddValue(name, new CtfStruct(null, fields));
                    }
                }
                else
                {
                    string name  = statement.Substring(0, i).Trim();
                    string value = statement.Substring(i + 1).Trim();

                    if (value.Length > 2 && value[0] == '\"' && value[value.Length - 1] == '\"')
                    {
                        value = value.Substring(1, value.Length - 2);
                    }

                    result.AddValue(name, value);
                }
            }

            return(result);
        }
 public CtfInteger(CtfPropertyBag bag)
     : base(CtfTypes.Integer)
 {
     Size     = bag.GetShort("size");
     _align   = bag.GetShortOrNull("align") ?? 8;
     Signed   = bag.GetBoolean("signed");
     Encoding = bag.GetString("encoding") ?? "none";
     Base     = bag.GetShortOrNull("base") ?? 10;
     Map      = bag.GetString("map");
 }
        public CtfStruct(CtfPropertyBag props, CtfField[] fields)
            : base(CtfTypes.Struct)
        {
            int alignment = 1;

            if (props != null)
            {
                alignment = props.GetIntOrNull("align") ?? 1;
            }

            _align = alignment;
            Fields = fields;
        }
Exemple #11
0
        private CtfMetadataDeclaration ParseOneDeclaration(string metadata, int index, out int end)
        {
            end = -1;
            int open = metadata.IndexOf('{', index);

            if (open == -1)
            {
                return(null);
            }

            int start = metadata.Substring(0, open).LastIndexOf('\n') + 1;

            if (start == 0)
            {
                return(null);
            }

            CtfDeclarationTypes directive = CtfDeclarationTypes.Unknown;

            string[] directiveElements = metadata.Substring(start, open - start).Trim().Split(' ');
            string   directiveString   = directiveElements[0];

            string name = null;

            switch (directiveString)
            {
            case "trace":
                directive = CtfDeclarationTypes.Trace;
                break;

            case "typealias":
                directive = CtfDeclarationTypes.TypeAlias;

                int closeBrace = FindCloseBrace(metadata, open) + 1;

                CtfPropertyBag bag = GetPropertyBag(metadata, open, closeBrace);

                CtfMetadataType t = null;
                switch (directiveElements[1])
                {
                case "integer":
                    t = new CtfInteger(bag);
                    break;

                default:
                    throw new IOException();
                }

                int colonEquals = metadata.IndexOf(":=", closeBrace) + 2;

                int semi = colonEquals;
                while (metadata[++semi] != ';')
                {
                    ;
                }

                name = metadata.Substring(colonEquals, semi - colonEquals).Trim();

                end = semi + 1;

                return(new CtfMetadataDeclaration(CtfDeclarationTypes.TypeAlias, t, name, directiveElements[1]));

            case "env":
                directive = CtfDeclarationTypes.Environment;
                break;

            case "clock":
                directive = CtfDeclarationTypes.Clock;
                break;

            case "struct":
                directive = CtfDeclarationTypes.Struct;
                name      = directiveElements[1];
                break;

            case "stream":
                directive = CtfDeclarationTypes.Stream;
                break;

            case "event":
                directive = CtfDeclarationTypes.Event;
                break;

            default:
                break;
            }

            int close = FindCloseBrace(metadata, open);
            int curr  = close;

            while (metadata[curr++] != ';')
            {
                ;
            }

            int nameStart = metadata.IndexOf(":=", close);

            if (name == null && nameStart != -1 && nameStart < curr)
            {
                nameStart += 2; // move past :=
                name       = metadata.Substring(nameStart, curr - nameStart - 1).Trim();
            }

            Debug.Assert(metadata[open] == '{');
            Debug.Assert(metadata[close] == '}');

            end = curr;
            if (directive == CtfDeclarationTypes.Struct)
            {
                CtfPropertyBag bag   = null;
                Match          match = s_align.Match(metadata, close, end - close);
                if (match.Success)
                {
                    bag = new CtfPropertyBag();
                    bag.AddValue("align", match.Groups[1].ToString());
                }

                CtfField[] fields = ParseStructFields(metadata, open, close).ToArray();
                return(new CtfMetadataDeclaration(directive, bag, fields, name, metadata.Substring(index, curr - index)));
            }
            else
            {
                CtfPropertyBag properties = GetPropertyBag(metadata, open, close);
                return(new CtfMetadataDeclaration(directive, properties, name, metadata.Substring(index, curr - index)));
            }
        }
Exemple #12
0
        private CtfMetadataType ParseOneType(string statement, out int index)
        {
            CtfMetadataType type = null;
            Match           match;

            if ((match = s_integer.Match(statement)).Success)
            {
                Group          group = match.Groups[1];
                CtfPropertyBag bag   = GetPropertyBag(group.ToString());

                type  = new CtfInteger(bag);
                index = group.Index + group.Length;
            }
            else if ((match = s_struct.Match(statement)).Success)
            {
                var group = match.Groups[1];

                if (group.ToString() != "{")
                {
                    throw new InvalidOperationException();
                }

                int open  = group.Index;
                int close = FindCloseBrace(statement, open);

                CtfField[] fields = ParseStructFields(statement, open, close).ToArray();

                type  = new CtfStruct(null, fields);
                index = close + 1;
            }
            else if ((match = s_float.Match(statement)).Success)
            {
                int open  = match.Index + match.Length - 1;
                int close = FindCloseBrace(statement, open);

                CtfPropertyBag bag = GetPropertyBag(statement, open, close);
                type  = new CtfFloat(bag);
                index = close + 1;
            }
            else if ((match = s_variant.Match(statement)).Success)
            {
                string switchVariable = match.Groups[1].ToString();

                int open  = statement.IndexOf('{');
                int close = FindCloseBrace(statement, open);

                if (close == -1)
                {
                    throw new InvalidOperationException();
                }


                CtfField[] fields = ParseStructFields(statement, open, close).ToArray();

                type  = new CtfVariant(switchVariable, fields);
                index = close + 1;
            }
            else if ((match = s_variable.Match(statement)).Success)
            {
                var typeGroup = match.Groups[1];

                string typeName = typeGroup.ToString().Trim();
                if (typeName == "string")
                {
                    type = new CtfString();
                }
                else
                {
                    type = new CtfUnresolvedType(typeName);
                }

                index = typeGroup.Index + typeGroup.Length;
            }
            else if ((match = s_enum.Match(statement)).Success)
            {
                var    groups   = match.Groups;
                string typeName = groups[1].ToString().Trim();

                int open  = statement.IndexOf('{');
                int close = FindCloseBrace(statement, open);
                if (close == -1)
                {
                    throw new InvalidOperationException();
                }

                CtfNamedRange[] ranges = ParseNamedRanges(statement, open + 1, close).ToArray();

                // TODO: Can enums just be an inline defined integer?
                type  = new CtfEnum(new CtfUnresolvedType(typeName), ranges);
                index = close + 1;
            }
            else
            {
                // TODO:  Floating point

                index = 0;
                return(null);
            }

            return(type);
        }