//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public static void checkType(com.android.ddmlib.log.EventContainer.EventValueType type) throws InvalidValueTypeException
 public static void checkType(this EventValueDescription.ValueTypes instance, EventContainer.EventValueTypes type)
 {
     if ((type != EventContainer.EventValueTypes.INT && type != EventContainer.EventValueTypes.LONG) && instance != EventValueDescription.ValueTypes.NOT_APPLICABLE)
     {
         throw new InvalidValueTypeException(string.Format("{0} doesn't support type {1}", type, instance));
     }
 }
 /// <summary>
 /// Builds a <seealso cref="EventValueDescription"/> with a name and a type.
 /// <p/>
 /// If the type is <seealso cref="EventValueType#INT"/> or <seealso cref="EventValueType#LONG"/>, the
 /// <seealso cref="#mValueType"/> is set to <seealso cref="ValueType#BYTES"/> by default. It set to
 /// <seealso cref="ValueType#NOT_APPLICABLE"/> for all other <seealso cref="EventValueType"/> values. </summary>
 /// <param name="name"> </param>
 /// <param name="type"> </param>
 internal EventValueDescription(string name, EventContainer.EventValueTypes type)
 {
     mName = name;
     mEventValueType = type;
     if (mEventValueType == EventContainer.EventValueTypes.INT || mEventValueType == EventContainer.EventValueTypes.LONG)
     {
         mValueType = ValueTypes.BYTES;
     }
     else
     {
         mValueType = ValueTypes.NOT_APPLICABLE;
     }
 }
Beispiel #3
0
        public EventContainer parse(string textLogLine)
        {
            // line will look like
            // 04-29 23:16:16.691 I/dvm_gc_info(  427): <data>
            // where <data> is either
            // [value1,value2...]
            // or
            // value
            if (textLogLine.Length == 0)
            {
                return(null);
            }

            // parse the header first
            var m = TEXT_LOG_LINE.Match(textLogLine);

            if (m.Success)
            {
                try
                {
                    int month        = Convert.ToInt32(m.Groups[0].Value);
                    int day          = Convert.ToInt32(m.Groups[1].Value);
                    int hours        = Convert.ToInt32(m.Groups[2].Value);
                    int minutes      = Convert.ToInt32(m.Groups[3].Value);
                    int seconds      = Convert.ToInt32(m.Groups[4].Value);
                    int milliseconds = Convert.ToInt32(m.Groups[5].Value);

                    // convert into seconds since epoch and nano-seconds.

                    /*Calendar cal = new GregorianCalendar();
                     * cal.set(cal.get(Calendar.YEAR), month - 1, day, hours, minutes, seconds);
                     * int sec = (int) Math.Floor(cal.timeInMillis/1000);
                     * int nsec = milliseconds*1000000;*/

                    var epoch = new DateTime(1970, 1, 1, 0, 0, 0);
                    var date  = new DateTime(DateTime.Now.Year, month, day, hours, minutes, 0);
                    var sec   = (int)Math.Floor(date.Subtract(epoch).TotalSeconds + seconds);
                    var nsec  = milliseconds * 1000000;

                    string tag = m.group(7);

                    // get the numerical tag value
                    int tagValue = -1;
                    //JAVA TO C# CONVERTER TODO TASK: There is no .NET Dictionary equivalent to the Java 'entrySet' method:
                    var tagSet = mTagMap;
                    foreach (var entry in tagSet)
                    {
                        if (tag.Equals(entry.Value))
                        {
                            tagValue = entry.Key.Value;
                            break;
                        }
                    }

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

                    int pid = int.Parse(m.group(8));

                    object data = parseTextData(m.group(9), tagValue);
                    if (data == null)
                    {
                        return(null);
                    }

                    // now we can allocate and return the EventContainer
                    EventContainer @event = null;
                    if (tagValue == GcEventContainer.GC_EVENT_TAG)
                    {
                        @event = new GcEventContainer(tagValue, pid, -1, sec, nsec, data); // tid
                    }
                    else
                    {
                        @event = new EventContainer(tagValue, pid, -1, sec, nsec, data); // tid
                    }

                    return(@event);
                }
                catch (SystemException)
                {
                    return(null);
                }
            }

            return(null);
        }
 /// <summary>
 /// Builds a <seealso cref="EventValueDescription"/> with a name and a type, and a <seealso cref="ValueType"/>.
 /// <p/> </summary>
 /// <param name="name"> </param>
 /// <param name="type"> </param>
 /// <param name="valueType"> </param>
 /// <exception cref="InvalidValueTypeException"> if type and valuetype are not compatible.
 ///  </exception>
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: EventValueDescription(String name, com.android.ddmlib.log.EventContainer.EventValueType type, ValueType valueType) throws InvalidValueTypeException
 internal EventValueDescription(string name, EventContainer.EventValueTypes type, ValueTypes valueType)
 {
     mName = name;
     mEventValueType = type;
     mValueType = valueType;
     mValueType.checkType(mEventValueType);
 }
Beispiel #5
0
        private object getObjectFromString(string value, EventContainer.EventValueTypes type)
        {
            try
            {
                switch (type)
                {
                    case EventContainer.EventValueTypes.INT:
                        return int.Parse(value);
                    case EventContainer.EventValueTypes.LONG:
                        return long.Parse(value);
                    case EventContainer.EventValueTypes.STRING:
                        return value;
                }
            }
            catch (Exception)
            {
                // do nothing, we'll return null.
            }

            return null;
        }
Beispiel #6
0
        public EventContainer parse(string textLogLine)
        {
            // line will look like
            // 04-29 23:16:16.691 I/dvm_gc_info(  427): <data>
            // where <data> is either
            // [value1,value2...]
            // or
            // value
            if (textLogLine.Length == 0)
            {
                return null;
            }

            // parse the header first
            var m = TEXT_LOG_LINE.Match(textLogLine);
            if (m.Success)
            {
                try
                {
                    int month = Convert.ToInt32(m.Groups[0].Value);
                    int day = Convert.ToInt32(m.Groups[1].Value);
                    int hours = Convert.ToInt32(m.Groups[2].Value);
                    int minutes = Convert.ToInt32(m.Groups[3].Value);
                    int seconds = Convert.ToInt32(m.Groups[4].Value);
                    int milliseconds = Convert.ToInt32(m.Groups[5].Value);

                    // convert into seconds since epoch and nano-seconds.
                    /*Calendar cal = new GregorianCalendar();
                    cal.set(cal.get(Calendar.YEAR), month - 1, day, hours, minutes, seconds);
                    int sec = (int) Math.Floor(cal.timeInMillis/1000);
                    int nsec = milliseconds*1000000;*/

                    var epoch = new DateTime(1970, 1, 1, 0, 0, 0);
                    var date = new DateTime(DateTime.Now.Year, month, day, hours, minutes, 0);
                    var sec = (int)Math.Floor(date.Subtract(epoch).TotalSeconds + seconds);
                    var nsec = milliseconds*1000000;

                    string tag = m.group(7);

                    // get the numerical tag value
                    int tagValue = -1;
                    //JAVA TO C# CONVERTER TODO TASK: There is no .NET Dictionary equivalent to the Java 'entrySet' method:
                    var tagSet = mTagMap;
                    foreach (var entry in tagSet)
                    {
                        if (tag.Equals(entry.Value))
                        {
                            tagValue = entry.Key.Value;
                            break;
                        }
                    }

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

                    int pid = int.Parse(m.group(8));

                    object data = parseTextData(m.group(9), tagValue);
                    if (data == null)
                    {
                        return null;
                    }

                    // now we can allocate and return the EventContainer
                    EventContainer @event = null;
                    if (tagValue == GcEventContainer.GC_EVENT_TAG)
                    {
                        @event = new GcEventContainer(tagValue, pid, -1, sec, nsec, data); // tid
                    }
                    else
                    {
                        @event = new EventContainer(tagValue, pid, -1, sec, nsec, data); // tid
                    }

                    return @event;
                }
                catch (SystemException)
                {
                    return null;
                }
            }

            return null;
        }
Beispiel #7
0
        public EventContainer parse(LogReceiver.LogEntry entry)
        {
            if (entry.len < 4)
            {
                return null;
            }

            int inOffset = 0;

            int tagValue = ArrayHelper.swap32bitFromArray(entry.data, inOffset);
            inOffset += 4;

            string tag = mTagMap[tagValue];
            if (tag == null)
            {
                Log.e("EventLogParser", string.Format("unknown tag number: {0:D}", tagValue));
            }

            List<object> list = new List<object>();
            if (parseBinaryEvent(entry.data, inOffset, list) == -1)
            {
                return null;
            }

            object data;
            if (list.Count == 1)
            {
                data = list[0];
            }
            else
            {
                data = list.ToArray();
            }

            EventContainer @event = null;
            if (tagValue == GcEventContainer.GC_EVENT_TAG)
            {
                @event = new GcEventContainer(entry, tagValue, data);
            }
            else
            {
                @event = new EventContainer(entry, tagValue, data);
            }

            return @event;
        }