add back optimization option

This commit is contained in:
Mathieu Lacage
2007-06-07 12:25:40 +02:00
parent 9cec524f88
commit 8435bfc4fe
3 changed files with 107 additions and 5 deletions

View File

@@ -35,6 +35,7 @@ bool PacketHistory::m_enable = false;
uint32_t PacketHistory::m_maxSize = 0;
uint16_t PacketHistory::m_chunkUid = 0;
PacketHistory::DataFreeList PacketHistory::m_freeList;
bool g_optOne = false;
void
PacketHistory::Enable (void)
@@ -42,6 +43,12 @@ PacketHistory::Enable (void)
m_enable = true;
}
void
PacketHistory::SetOptOne (bool optOne)
{
g_optOne = optOne;
}
void
PacketHistory::ReserveCopy (uint32_t size)
{
@@ -278,6 +285,71 @@ PacketHistory::TryToAppend (uint32_t value, uint8_t **pBuffer, uint8_t *end)
return false;
}
void
PacketHistory::AppendValueExtra (uint32_t value, uint8_t *buffer)
{
if (value < 0x200000)
{
uint8_t byte = value & (~0x80);
buffer[0] = 0x80 | byte;
value >>= 7;
byte = value & (~0x80);
buffer[1] = 0x80 | byte;
value >>= 7;
byte = value & (~0x80);
buffer[2] = value;
return;
}
if (value < 0x10000000)
{
uint8_t byte = value & (~0x80);
buffer[0] = 0x80 | byte;
value >>= 7;
byte = value & (~0x80);
buffer[1] = 0x80 | byte;
value >>= 7;
byte = value & (~0x80);
buffer[2] = 0x80 | byte;
value >>= 7;
buffer[3] = value;
return;
}
{
uint8_t byte = value & (~0x80);
buffer[0] = 0x80 | byte;
value >>= 7;
byte = value & (~0x80);
buffer[1] = 0x80 | byte;
value >>= 7;
byte = value & (~0x80);
buffer[2] = 0x80 | byte;
value >>= 7;
byte = value & (~0x80);
buffer[3] = 0x80 | byte;
value >>= 7;
buffer[4] = value;
}
}
void
PacketHistory::AppendValue (uint32_t value, uint8_t *buffer)
{
if (value < 0x80)
{
buffer[0] = value;
return;
}
if (value < 0x4000)
{
uint8_t byte = value & (~0x80);
buffer[0] = 0x80 | byte;
value >>= 7;
buffer[1] = value;
return;
}
AppendValueExtra (value, buffer);
}
void
PacketHistory::UpdateTail (uint16_t written)
{
@@ -331,6 +403,35 @@ uint16_t
PacketHistory::AddSmall (const struct PacketHistory::SmallItem *item)
{
NS_ASSERT (m_data != 0);
if (g_optOne)
{
uint32_t typeUidSize = GetUleb128Size (item->typeUid);
uint32_t sizeSize = GetUleb128Size (item->size);
uint32_t n = typeUidSize + sizeSize + 2 + 2 + 2;
restart:
if (m_used + n <= m_data->m_size &&
(m_head == 0xffff ||
m_data->m_count == 1 ||
m_used == m_data->m_dirtyEnd))
{
uint8_t *buffer = &m_data->m_data[m_used];
Append16 (item->next, buffer);
buffer += 2;
Append16 (item->prev, buffer);
buffer += 2;
AppendValue (item->typeUid, buffer);
buffer += typeUidSize;
AppendValue (item->size, buffer);
buffer += sizeSize;
Append16 (item->chunkUid, buffer);
}
else
{
ReserveCopy (n);
goto restart;
}
return n;
}
append:
uint8_t *start = &m_data->m_data[m_used];
uint8_t *end = &m_data->m_data[m_data->m_size];

View File

@@ -27,10 +27,6 @@
#include "ns3/assert.h"
#include "packet-printer.h"
namespace {
class ItemList;
}
namespace ns3 {
class Chunk;
@@ -39,6 +35,7 @@ class Buffer;
class PacketHistory {
public:
static void Enable (void);
static void SetOptOne (bool optOne);
inline PacketHistory (uint32_t uid, uint32_t size);
inline PacketHistory (PacketHistory const &o);
@@ -64,6 +61,8 @@ public:
void PrintDefault (std::ostream &os, Buffer buffer) const;
void Print (std::ostream &os, Buffer buffer, PacketPrinter const &printer) const;
static void PrintStats (void);
private:
/**
head -(next)-> tail
@@ -113,6 +112,8 @@ private:
inline bool TryToAppendFast (uint32_t value, uint8_t **pBuffer, uint8_t *end);
inline bool TryToAppend32 (uint32_t value, uint8_t **pBuffer, uint8_t *end);
inline bool TryToAppend16 (uint16_t value, uint8_t **pBuffer, uint8_t *end);
void AppendValue (uint32_t value, uint8_t *buffer);
void AppendValueExtra (uint32_t value, uint8_t *buffer);
inline void Reserve (uint32_t n);
void ReserveCopy (uint32_t n);
uint32_t DoPrint (struct PacketHistory::SmallItem *item, uint32_t current,

View File

@@ -179,7 +179,7 @@ int main (int argc, char *argv[])
char const *nAscii = argv[0] + strlen ("--n=");
n = atoi (nAscii);
}
if (strncmp ("--enable-history", argv[0], strlen ("--enable-metadata")) == 0)
if (strncmp ("--enable-metadata", argv[0], strlen ("--enable-metadata")) == 0)
{
Packet::EnableMetadata ();
}