Пример #1
0
static inline uint32_t
value_len(WT_RAND_STATE *rnd, uint64_t keyno, uint32_t min, uint32_t max)
{
	/*
	 * Focus on relatively small items, admitting the possibility of larger
	 * items. Pick a size close to the minimum most of the time, only create
	 * a larger item 1 in 20 times, and a really big item 1 in somewhere
	 * around 2500 items.
	 */
	if (keyno % 2500 == 0 && max < KILOBYTE(80)) {
		min = KILOBYTE(80);
		max = KILOBYTE(100);
	} else if (keyno % 20 != 0 && max > min + 20)
		max = min + 20;
	return (mmrand(rnd, min, max));
}
Пример #2
0
void
val_gen_setup(WT_RAND_STATE *rnd, WT_ITEM *value)
{
	size_t i, len;
	char *p;

	memset(value, 0, sizeof(WT_ITEM));

	/*
	 * Set initial buffer contents to recognizable text.
	 *
	 * Add a few extra bytes in order to guarantee we can always offset
	 * into the buffer by a few extra bytes, used to generate different
	 * data for column-store run-length encoded files.
	 */
	len = MAX(KILOBYTE(100), g.c_value_max) + 20;
	p = dmalloc(len);
	for (i = 0; i < len; ++i)
		p[i] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i % 26];

	value->mem = p;
	value->memsize = len;
	value->data = value->mem;
	value->size = 0;

	val_dup_data_len = value_len(rnd,
	    (uint64_t)mmrand(rnd, 1, 20), g.c_value_min, g.c_value_max);
}
Пример #3
0
void cGenIndex::Work(void)
{
  eof=error=pstart=false;
  memset(fileSize,0,sizeof(fileSize));

  if(rewrite) {
    writeFile=writeName->OpenWrite();
    if(writeFile<0) {
      printf("Failed to open output file(s)\n");
      return;
      }
    }

  replayFile=fileName->Open();
  readNo=fileName->FileNumber();
  fileSize[readNo]=fileName->FileSize();
  readOffset=0;

  fileNo=rewrite ? 1 : readNo;
  fileOffset=0;
  splitOffset=splitsize*MEGABYTE(1);
  sSize=0;

  if(replayFile>=0) {
    if(index->Open()) {
      int lastoff=0;
      while(!error && NextFile()) {
        int count=read(replayFile,buff,sizeof(buff));
        if(count<0) {
          printf("read vdr: %s\n",strerror(errno));
          return;
          }
        else if(count==0) {
          if(fileSize[readNo]!=readOffset)
            printf("file %d read/size mismatch\n",readNo);
          eof=true;
          continue;
          }
        else {
          readOffset+=count;

          if(!quiet && (readOffset<lastoff || readOffset>lastoff+KILOBYTE(256)) && fileSize[readNo]) {
            printf("offset %lld %d%%\r",readOffset,(int)(readOffset*100/fileSize[readNo])); fflush(stdout);
            lastoff=readOffset;
            }

          int used=Process(buff,count);
          if(used<0) {
            error=true;
            break;
            }
          if(count-used) printf("bummer, count!=0\n");
          }
        }
      if(!error && !quiet) Statistics();
      }
    }
  else printf("Failed to open input file(s)\n");
}
Пример #4
0
cPidFilter *cLogger::AddFilter(int Pid, int Section, int Mask, int Mode, int IdleTime, bool Crc)
{
  cPidFilter *filter=NewFilter(IdleTime);
  if(filter) {
    if(Pid>1) filter->SetBuffSize(KILOBYTE(64));
    filter->Start(Pid,Section,Mask,Mode,Crc);
    PRINTF(L_CORE_AUEXTRA,"%d: added filter pid=0x%.4x sct=0x%.2x/0x%.2x/0x%.2x idle=%d crc=%d",cardNum,Pid,Section,Mask,Mode,IdleTime,Crc);
    }
  else PRINTF(L_GEN_ERROR,"no free slot or filter failed to open for logger %d",cardNum);
  return filter;
}
Пример #5
0
static void
key_gen_common(WT_ITEM *key, uint64_t keyno, const char * const suffix)
{
	int len;
	char *p;

	p = key->mem;

	/*
	 * The key always starts with a 10-digit string (the specified row)
	 * followed by two digits, a random number between 1 and 15 if it's
	 * an insert, otherwise 00.
	 */
	u64_to_string_zf(keyno, key->mem, 11);
	p[10] = '.';
	p[11] = suffix[0];
	p[12] = suffix[1];
	len = 13;

	/*
	 * In a column-store, the key is only used for Berkeley DB inserts,
	 * and so it doesn't need a random length.
	 */
	if (g.type == ROW) {
		p[len] = '/';

		/*
		 * Because we're doing table lookup for key sizes, we weren't
		 * able to set really big keys sizes in the table, the table
		 * isn't big enough to keep our hash from selecting too many
		 * big keys and blowing out the cache. Handle that here, use a
		 * really big key 1 in 2500 times.
		 */
		len = keyno % 2500 == 0 && g.c_key_max < KILOBYTE(80) ?
		    KILOBYTE(80) :
		    (int)g.key_rand_len[keyno % WT_ELEMENTS(g.key_rand_len)];
	}

	key->data = key->mem;
	key->size = (size_t)len;
}
Пример #6
0
cString cSatipBufferStatistics::GetBufferStatistic()
{
  debug16("%s", __PRETTY_FUNCTION__);
  cMutexLock MutexLock(&mutexM);
  uint64_t elapsed = timerM.Elapsed(); /* in milliseconds */
  timerM.Set();
  long bitrate = elapsed ? (long)(1000.0L * dataBytesM / KILOBYTE(1) / elapsed) : 0L;
  long totalSpace = SATIP_BUFFER_SIZE;
  float percentage = (float)((float)usedSpaceM / (float)totalSpace * 100.0);
  long totalKilos = totalSpace / KILOBYTE(1);
  long usedKilos = usedSpaceM / KILOBYTE(1);
  if (!SatipConfig.GetUseBytes()) {
     bitrate *= 8;
     totalKilos *= 8;
     usedKilos *= 8;
     }
  cString s = cString::sprintf("Buffer bitrate: %ld k%s/s\nBuffer usage: %ld/%ld k%s (%2.1f%%)\n", bitrate,
                               SatipConfig.GetUseBytes() ? "B" : "bit", usedKilos, totalKilos,
                               SatipConfig.GetUseBytes() ? "B" : "bit", percentage);
  dataBytesM = 0;
  usedSpaceM = 0;
  return s;
}
Пример #7
0
cString cSatipSectionStatistics::GetSectionStatistic()
{
  debug16("%s", __PRETTY_FUNCTION__);
  cMutexLock MutexLock(&mutexM);
  uint64_t elapsed = timerM.Elapsed(); /* in milliseconds */
  timerM.Set();
  long bitrate = elapsed ? (long)(1000.0L * filteredDataM / KILOBYTE(1) / elapsed) : 0L;
  if (!SatipConfig.GetUseBytes())
     bitrate *= 8;
  // no trailing linefeed here!
  cString s = cString::sprintf("%4ld (%4ld k%s/s)", numberOfCallsM, bitrate,
                               SatipConfig.GetUseBytes() ? "B" : "bit");
  filteredDataM = numberOfCallsM = 0;
  return s;
}
Пример #8
0
cString cSatipTunerStatistics::GetTunerStatistic()
{
  debug16("%s", __PRETTY_FUNCTION__);
  mutexM.Lock();
  uint64_t elapsed = timerM.Elapsed(); /* in milliseconds */
  timerM.Set();
  long bitrate = elapsed ? (long)(1000.0L * dataBytesM / KILOBYTE(1) / elapsed) : 0L;
  dataBytesM = 0;
  mutexM.Unlock();

  if (!SatipConfig.GetUseBytes())
     bitrate *= 8;
  cString s = cString::sprintf("%ld k%s/s", bitrate, SatipConfig.GetUseBytes() ? "B" : "bit");
  return s;
}
Пример #9
0
SCCAMSlot::SCCAMSlot(SCCIAdapter *sCCIAdapter, int cardIndex, int slot)
 : cCamSlot(sCCIAdapter)
 , checkTimer(-SLOT_CAID_CHECK - 1000)
 , rb(KILOBYTE(4), 5 + LEN_OFF, false, "SC-CI slot answer")
{
  this->sCCIAdapter = sCCIAdapter;
  this->cardIndex = cardIndex;
  this->slot = slot;
  version = 0;
  caids[0] = 0;
  doReply = false;
  lastStatus = msReset;
  frame.SetRb(&rb);
  Reset(false);
}
Пример #10
0
void
key_gen_setup(WT_ITEM *key)
{
	size_t i, len;
	char *p;

	len = MAX(KILOBYTE(100), g.c_key_max);
	p = dmalloc(len);
	for (i = 0; i < len; ++i)
		p[i] = "abcdefghijklmnopqrstuvwxyz"[i % 26];

	key->mem = p;
	key->memsize = len;
	key->data = key->mem;
	key->size = 0;
}
Пример #11
0
SCCIAdapter::SCCIAdapter(cDevice *Device, int cardIndex, int cafd, bool SoftCSA, bool FullTS)
{
  for (int i = 0; i < MAX_SOCKETS; i++)
  {
    sids[i] = 0;
    sockets[i] = 0;
  }

  this->cardIndex = cardIndex;
  device = Device;
  capmt = new CAPMT;
  fd_ca = cafd;
  softcsa = SoftCSA;
  fullts = FullTS;

  decsa = softcsa ? new DeCSA(cardIndex) : 0;
  UDPSocket::bindx(this);

  memset(version, 1, sizeof(version));
  memset(slots, 0, sizeof(slots));
  memset(caids, 0, sizeof(caids));
  caidsLength = 0;
  Channels.Lock(false);
  for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel))
  {
    if (!channel->GroupSep() && channel->Ca() >= CA_ENCRYPTED_MIN)
    {
      for (const int *ids = channel->Caids(); *ids; ids++)
        addCaid(0, caidsLength, (unsigned short) *ids);
    }
  }
  Channels.Unlock();
  rb = new cRingBufferLinear(KILOBYTE(8), 6 + LEN_OFF, false, "SC-CI adapter read");
  if (rb)
  {
    rb->SetTimeouts(0, CAM_READ_TIMEOUT);
    frame.SetRb(rb);
  }
  INFOLOG("%s: built caid table with %i caids for %i channels", __FUNCTION__, caidsLength, Channels.Count());
  SetDescription("SC-CI adapter on device %d", cardIndex);
  for (int i = 0; i < MAX_CI_SLOTS && i * MAX_CI_SLOT_CAIDS < caidsLength; i++)
    slots[i] = new SCCAMSlot(this, cardIndex, i);
  Start();
}
Пример #12
0
cString cSatipPidStatistics::GetPidStatistic()
{
  debug16("%s", __PRETTY_FUNCTION__);
  cMutexLock MutexLock(&mutexM);
  const int numberOfElements = sizeof(mostActivePidsM) / sizeof(pidStruct);
  uint64_t elapsed = timerM.Elapsed(); /* in milliseconds */
  timerM.Set();
  cString s("Active pids:\n");
  for (int i = 0; i < numberOfElements; ++i) {
      if (mostActivePidsM[i].pid >= 0) {
         long bitrate = elapsed ? (long)(1000.0L * mostActivePidsM[i].dataAmount / KILOBYTE(1) / elapsed) : 0L;
         if (!SatipConfig.GetUseBytes())
            bitrate *= 8;
         s = cString::sprintf("%sPid %d: %4d (%4ld k%s/s)\n", *s, i,
                              mostActivePidsM[i].pid, bitrate,
                              SatipConfig.GetUseBytes() ? "B" : "bit");
         }
      }
  for (int i = 0; i < numberOfElements; ++i) {
      mostActivePidsM[i].pid = -1;
      mostActivePidsM[i].dataAmount = 0L;
      }
  return s;
}
Пример #13
0
cPicturePlayer::cPicturePlayer(void)
{
  size = KILOBYTE(100); // will be adjusted automatically if files are larger
  length = 0;
  buffer = MALLOC(uchar, size);
}
Пример #14
0
bool run(ASTNode* mainNode, RuntimeError* error, ExternalFunctions externals, char** libsToLoad, int libsCount)
{
    assert(mainNode->nodeType == AST_MAIN);

    getValueFunc = getGetValueFuncPtr();

    MemoryStack stack = makeMemoryStack(MEGABYTE(16));
    Array<HINSTANCE> libraries = makeArray<HINSTANCE>(KILOBYTE(1));

    Scope scalarTypesScope = makeScope(nullptr);
    Scope globalScope = makeScope(&scalarTypesScope);

    pushType(&scalarTypesScope, &stack, TypeDefinition{ makeSlice("s64"), {}, 8 });
    pushType(&scalarTypesScope, &stack, TypeDefinition{ makeSlice("u64"), {}, 8 });
    pushType(&scalarTypesScope, &stack, TypeDefinition{ makeSlice("f64"), {}, 8 });

    pushType(&scalarTypesScope, &stack, TypeDefinition{ makeSlice("s32"), {}, 4 });
    pushType(&scalarTypesScope, &stack, TypeDefinition{ makeSlice("u32"), {}, 4 });
    pushType(&scalarTypesScope, &stack, TypeDefinition{ makeSlice("f32"), {}, 4 });

    pushType(&scalarTypesScope, &stack, TypeDefinition{ makeSlice("s16"), {}, 2 });
    pushType(&scalarTypesScope, &stack, TypeDefinition{ makeSlice("u16"), {}, 2 });

    pushType(&scalarTypesScope, &stack, TypeDefinition{ makeSlice("s8"), {}, 1 });
    pushType(&scalarTypesScope, &stack, TypeDefinition{ makeSlice("u8"), {}, 1 });

    ExternalArgumentDefinition binarys32Args[] = { { "a", "s32" }, { "b", "s32" } };
    ExternalArgumentDefinition binaryf32Args[] = { { "a", "f32" }, { "b", "f32" } };
    ExternalDefinition buildInExternals[] = {
        { &scalarS32FuncsHandler, "opAdd", "s32", binarys32Args, ArrayCount(binarys32Args) },
        { &scalarS32FuncsHandler, "opSub", "s32", binarys32Args, ArrayCount(binarys32Args) },
        { &scalarS32FuncsHandler, "opEqualsOrLess", "s32", binarys32Args, ArrayCount(binarys32Args) },
        { &scalarS32FuncsHandler, "opEqualsOrsGreater", "s32", binarys32Args, ArrayCount(binarys32Args) },
        { &scalarS32FuncsHandler, "opLess", "s32", binarys32Args, ArrayCount(binarys32Args) },
        { &scalarS32FuncsHandler, "opGreater", "s32", binarys32Args, ArrayCount(binarys32Args) },
        { &scalarS32FuncsHandler, "opEquals", "s32", binarys32Args, ArrayCount(binarys32Args) },
        { &scalarS32FuncsHandler, "opNot", "s32", binarys32Args, ArrayCount(binarys32Args) },
    };

    loadExternals(&scalarTypesScope, &stack, ExternalFunctions{ buildInExternals, ArrayCount(buildInExternals) });
    loadExternals(&scalarTypesScope, &stack, externals);
    loadLibrariries(&libraries, &scalarTypesScope, &stack, libsToLoad, libsCount);

    bool stillWorking = true;

    // load all global function and type definitions
    ListIterator<ASTNode> iterator = makeIterator(&mainNode->main.statements);
    while (stillWorking && hasNext(&iterator))
    {
        ASTNode* statement = getNext(&iterator);
        if (statement->nodeType == AST_STATEMENT_FUNCTION_DEFINITION ||
            statement->nodeType == AST_STATEMENT_TYPE_DEFINITION)
            stillWorking = runStatement(statement, &stack, &globalScope, error);
        else
        {
            // TODO: illigal statement exception? Or do this on parsing stage? 
        }
    }

    if (stillWorking)
    {
        FunctionIdentifier mainIdentifier = {};
        mainIdentifier.name = makeSlice("main");

        Function* func = getFunction(&globalScope, mainIdentifier);

        if (func != nullptr)
            stillWorking = runStatement(func->body, &stack, &globalScope, error);
        else
        {
            stillWorking = false;
            *error = RuntimeError{ RET_UNDEFINED_FUNCTION, mainIdentifier.name, 0 };
        }
    }

    scopeFreeMemory(&globalScope, &stack);
    scopeFreeMemory(&scalarTypesScope, &stack);

    freeAllLibraries(&libraries);

    freeArray(&libraries);
    freeMemoryStack(&stack);
    return stillWorking;
}