Example #1
0
        internal void Flush()
        {
            // Write strings and callstacks.

            long strpos    = m_Out.BaseStream.Position;
            long strtab_sz = 8 * m_SeenStrings.Count;

            {
                var buf = new MemoryStream();
                foreach (var s in m_SeenStrings)
                {
                    var bytes = Encoding.UTF8.GetBytes(s);
                    m_Out.Write((uint)(strtab_sz + buf.Length));
                    m_Out.Write((int)bytes.Length);
                    buf.Write(bytes, 0, bytes.Length);
                }

                buf.Position = 0;
                buf.CopyTo(m_Out.BaseStream);
            }

            // Call stacks.
            long stkpos    = m_Out.BaseStream.Position;
            long stktab_sz = 8 * m_SeenStacks.Count;

            {
                var buf  = new MemoryStream();
                var bufh = new BinaryWriter(buf);
                foreach (var s in m_SeenStacks)
                {
                    int cnt = s.Length;
                    m_Out.Write((uint)(stktab_sz + buf.Length));
                    m_Out.Write(cnt);
                    foreach (ulong addr in s)
                    {
                        bufh.Write(addr);
                    }
                }
                buf.Position = 0;
                buf.CopyTo(m_Out.BaseStream);
            }

            // Patch up offsets
            m_Out.BaseStream.Position = 0;
            m_Out.Write(strpos);
            m_Out.Write(stkpos);
            m_Out.BaseStream.Position = m_Out.BaseStream.Length;

            MetaData.Save(m_Out);
            MetaData.Status = TraceStatus.Ready;
        }
Example #2
0
        internal void Flush()
        {
            // Write strings and callstacks.

            long strpos    = m_Out.BaseStream.Position;
            long strtab_sz = 8 * m_SeenStrings.Count;

            {
                var buf = new MemoryStream();
                foreach (var s in m_SeenStrings)
                {
                    var bytes = Encoding.UTF8.GetBytes(s);
                    m_Out.Write((uint)(strtab_sz + buf.Length));
                    m_Out.Write((int)bytes.Length);
                    buf.Write(bytes, 0, bytes.Length);
                }

                buf.Position = 0;
                buf.CopyTo(m_Out.BaseStream);
            }

            // Call stacks.
            long stkpos    = m_Out.BaseStream.Position;
            long stktab_sz = 8 * m_SeenStacks.Count;

            {
                // MemoryStream.Capacity can't be larger than 4G. So we use multiple streams.
                var  addressList      = new List <BinaryWriter>();
                uint addressBufLength = 0;

                foreach (var s in m_SeenStacks)
                {
                    int cnt = s.Length;
                    m_Out.Write((uint)(stktab_sz + addressBufLength));
                    m_Out.Write(cnt);

                    var addressStream = new BinaryWriter(new MemoryStream());
                    addressList.Add(addressStream);
                    foreach (ulong addr in s)
                    {
                        addressStream.Write(addr);
                    }

                    addressBufLength += (uint)addressStream.BaseStream.Length;
                }

                foreach (var addressStream in addressList)
                {
                    addressStream.BaseStream.Position = 0;
                    addressStream.BaseStream.CopyTo(m_Out.BaseStream);
                }
            }

            // Patch up offsets
            m_Out.BaseStream.Position = 0;
            m_Out.Write(strpos);
            m_Out.Write(stkpos);
            m_Out.BaseStream.Position = m_Out.BaseStream.Length;

            MetaData.Save(m_Out);
            MetaData.Status = TraceStatus.Ready;
        }