コード例 #1
0
ファイル: b2g-info.cpp プロジェクト: ahal/gonk-misc
void print_lmk_params()
{
#define LMK_DIR "/sys/module/lowmemorykiller/parameters/"

  puts("Low-memory killer parameters:\n");

  int notify_pages = str_to_int(read_whole_file(LMK_DIR "notify_trigger"), -1);
  printf("  notify_trigger %d KB\n", pages_to_kb(notify_pages));
  putchar('\n');

  vector<int> oom_adjs;
  {
    stringstream ss(read_whole_file(LMK_DIR "adj"));
    string item;
    while (getline(ss, item, ',')) {
      oom_adjs.push_back(str_to_int(item, -1));
    }
  }

  vector<int> minfrees;
  {
    stringstream ss(read_whole_file(LMK_DIR "minfree"));
    string item;
    while (getline(ss, item, ',')) {
      minfrees.push_back(pages_to_kb(str_to_int(item, -1)));
    }
  }

  Table t;
  t.start_row();
  t.add("oom_adj");
  t.add("min_free", Table::ALIGN_LEFT);

  for (size_t i = 0; i < max(oom_adjs.size(), minfrees.size()); i++) {
    t.start_row();
    if (i < oom_adjs.size()) {
      t.add(oom_adjs[i]);
    } else {
      t.add("");
    }

    if (i < minfrees.size()) {
      t.add_fmt("%d KB", minfrees[i]);
    } else {
      t.add("");
    }
  }

  t.print_with_indent(2);

#undef LMK_DIR
}
コード例 #2
0
ファイル: eca2tlu_demo.cpp プロジェクト: mkreider/ITA15
void setupPulseDemo(ECA& eca) {
  enable(eca, false);
  flush(eca);

  Table table;
  
  //add rules for double pulse __--_____----___
  table.add(TableEntry(EVT_DPULSE, OFFS0, MS_CH0_HI | MS_CH1_HI, CH_LVDS, 64));
  table.add(TableEntry(EVT_DPULSE, OFFS1, MS_CH0_LO | MS_CH1_LO, CH_LVDS, 64));
  table.add(TableEntry(EVT_DPULSE, OFFS2, MS_CH0_HI | MS_CH1_HI, CH_LVDS, 64));
  table.add(TableEntry(EVT_DPULSE, OFFS3, MS_CH0_LO | MS_CH1_LO, CH_LVDS, 64));
  
  //add rules for single pulses __--__
  table.add(TableEntry(EVT_PULSE0, 0,  MS_CHX_HI , CH_LVDS, 64));
  table.add(TableEntry(EVT_PULSE0, 40/8, MS_CHX_LO , CH_LVDS, 64));
  
  table.add(TableEntry(EVT_PULSE1, 0,  MS_CH0_HI | MS_CH1_HI, CH_LVDS, 64));
  table.add(TableEntry(EVT_PULSE1, 40/8, MS_CH0_LO | MS_CH1_LO, CH_LVDS, 64));
  
  table.add(TableEntry(EVT_PULSEALL, 0,  MS_CHX_HI, CH_LVDS, 64));
  table.add(TableEntry(EVT_PULSEALL, 40/8, MS_CHX_LO, CH_LVDS, 64));
  
  commit(eca, table);
  
    //dump(eca)
  //commit and arm

  activate(eca, CH_LVDS);
  enable(eca, true);

}
コード例 #3
0
ファイル: table_mgr.cpp プロジェクト: judasnow/qipai
void TableMgr::add(int key, int gui_num, bool eye, bool chi)
{
    Table* tbl = 0;

    if(chi)
    {
        if(eye)
        {
            tbl = m_check_eye_table[gui_num];
        }
        else
        {
            tbl = m_check_table[gui_num];
        }
    }
    else
    {
        if(eye)
        {
            tbl = m_check_feng_eye_table[gui_num];
        }
        else
        {
            tbl = m_check_feng_table[gui_num];
        }
    }

    tbl->add(key);
}
コード例 #4
0
ファイル: main.cpp プロジェクト: everett1992/opengl-pool
// inintialies everything
void setup(void)
{
	glClearColor(0.0, 0.0, 0.0, 0.0); 
	glEnable(GL_DEPTH_TEST); // Enable depth testing.
	
	// soposed to make stuff purdy
	glEnable(GL_POLYGON_SMOOTH);
	glEnable(GL_LINE_SMOOTH);

	// bunch of bullet stuff
    // Build the broadphase
    broadphase = new btDbvtBroadphase();
 
    // Set up the collision configuration and dispatcher
    collisionConfiguration = new btDefaultCollisionConfiguration();
    dispatcher = new btCollisionDispatcher(collisionConfiguration);
 
    // The actual physics solver
    solver = new btSequentialImpulseConstraintSolver;
 
    // The world.
    dynamicsWorld =
		new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
    dynamicsWorld->setGravity(btVector3(0,-20,0));
	dynamicsWorld->setInternalTickCallback(myTickCallback);
 

	// adds all objects to the simulation world
	cup.add(dynamicsWorld);
	table.add(dynamicsWorld);
	rackBalls();

	timer.start_clock();
}
コード例 #5
0
ファイル: b2g-info.cpp プロジェクト: ahal/gonk-misc
void
b2g_ps_add_table_headers(Table& t, bool show_threads)
{
  t.start_row();
  t.add("NAME");
  t.add(show_threads ? "TID" : "PID");
  t.add("PPID");
  t.add("CPU(s)");
  t.add("NICE");
  t.add("USS");
  t.add("PSS");
  t.add("RSS");
  t.add("VSIZE");
  t.add("OOM_ADJ");
  t.add("USER", Table::ALIGN_LEFT);
}
コード例 #6
0
ファイル: eca-snoop.cpp プロジェクト: GSI-CS-CO/bel_projects
int main(int argc, const char** argv) {
  Socket socket;
  Device device;
  MyHandler handler;
  
  /* Setup connection to FPGA via PCIe */
  socket.open();
  socket.passive("dev/wbs0");
  device.open(socket, "dev/wbm0");
  
  /* Find the ECA */
  std::vector<ECA> ecas;
  ECA::probe(device, ecas);
  assert (ecas.size() == 1);
  ECA& eca = ecas[0];
  
  assert (eca.channels.size() >= 2);
  assert (!eca.channels[1].queue.empty());
  handler.eca = &eca;
  handler.aq = &eca.channels[1].queue.front();
  
  /* Stop the ECA for now */
  eca.disable(true);
  eca.channels[1].drain(true);
  
  /* Program a catch all to channel 1 rule */
  Table table;
  table.add(TableEntry(0, 0, 0xdeadbeef, 1, 0));
  eca.store(table);
  eca.flipTables();
  
  /* Flush any crap pending in the AQ */
  ActionEntry ae;
  while (1) {
    handler.aq->refresh();
    if (!handler.aq->queued_actions) break;
    handler.aq->pop(ae);
  }
  
  /* Hook arrival interrupts via PCIe */
  std::vector<struct sdb_device> devs;
  device.sdb_find_by_identity(0x651, 0x8a670e73, devs);
  assert (devs.size() == 1);
  mydevice.sdb_component.addr_first = devs[0].sdb_component.addr_first;
  mydevice.sdb_component.addr_last  = devs[0].sdb_component.addr_last;
  socket.attach(&mydevice, &handler);
  
  /* Enable interrupt delivery to us */
  handler.aq->hook_arrival(true, mydevice.sdb_component.addr_first);
  eca.channels[1].freeze(false);
  eca.channels[1].drain(false);
  eca.interrupt(true);
  eca.disable(false);
  
  /* Wait forever, pumping out the actions as they arrive */
  while (true) socket.run();
  
  return 0;
}
コード例 #7
0
ファイル: test.cpp プロジェクト: Gabers-/csfiles
int main()
{
	Table aTable;
	Student s1("G30", 3.6);
	Student s2("G50", 3.9);
	Student s3("G40", 3.5);
	Student s4("G10", 3.8);

	aTable.add(s1.getId(), s1);
	aTable.add(s2.getId(), s2);
	aTable.add(s3.getId(), s3);
	aTable.add(s4.getId(), s4);

	aTable.listAll();
	
	return 0;
}
コード例 #8
0
ファイル: parallel.cpp プロジェクト: bluekidds/jtorch
  void Parallel::initOutput() {
    if (output == NULL) {
      output = new Table();
    }

    Table* out = (Table*)output;
    out->clearNoDelete();
    for (uint32_t i = 0; i < network_->size(); i++) {
      out->add((Tensor<float>*)(*network_)[i]->output);
    }
  }
コード例 #9
0
void ParallelTable::initOutput() {
  if (output == nullptr) {
    output.reset(new Table());
  }

  Table* out = (Table*)output.get();
  out->clear();
  for (uint32_t i = 0; i < network_.size(); i++) {
    out->add(network_[i]->output);
  }
}
コード例 #10
0
 bool count(Census &census, const Node &node) {
     const jschar *key = node.typeName();
     typename Table::AddPtr p = table.lookupForAdd(key);
     if (!p) {
         if (!table.add(p, key, EachType(census)))
             return false;
         if (!p->value().init(census))
             return false;
     }
     return p->value().count(census, node);
 }
コード例 #11
0
    bool count(Census &census, const Node &node) {
        if (!node.is<JSObject>())
            return other.count(census, node);

        const js::Class *key = node.as<JSObject>()->getClass();
        typename Table::AddPtr p = table.lookupForAdd(key);
        if (!p) {
            if (!table.add(p, key, EachClass(census)))
                return false;
            if (!p->value().init(census))
                return false;
        }
        return p->value().count(census, node);
    }
コード例 #12
0
/* ==================================================================================================== */
int main (int argc, const char** argv)
{

  /* Helpers */
  Socket socket;
  Device device;
  status_t status;
  std::vector<ECA> ecas;
  std::vector<TLU> tlus;
  std::vector<std::vector<uint64_t> > queues;
  Table table;
  uint32_t uQueueInterator = 0;
  uint32_t uQueueItemIterator = 0;
  uint32_t uQueuesTotal = 0;
  uint32_t uQueneItems = 0;
  uint64_t uTimeDiff = 0;
  uint32_t uShiftPosition = 0;
  uint32_t a_uEdges[EVENTS];
  uint64_t a_uFrequency[EVENTS];
  uint32_t uArrayIterator = 0;
  uint32_t uTestCase = 0;
  uint32_t uIOConfig = 0;
  uint32_t * p_uEdgesExpected = NULL;
  uint32_t * p_uFrequencyExpected = NULL;
  double dExpectedFrequency = 0.0;
  double dMeasuredFrequency = 0.0;
  
  /* Plausibility check for arguments */
  if (argc != 3)
  {
    fprintf(stderr, "%s: expecting argument <device> <test case>\n", argv[0]);
    return 1;
  }
  
  /* Initialize variables */
  for(uArrayIterator=0; uArrayIterator<EVENTS; uArrayIterator++)
  {
    a_uEdges[uArrayIterator] = 0;
    a_uFrequency[uArrayIterator] = 0;
  }
  
  /* Get the test case ID */
  if(!strcmp(argv[2],"testcase1"))
  {
    uTestCase = 1;
    uIOConfig = 0x0; /* All IOs = Inputs */
    p_uEdgesExpected = a_uEdgesExpectedTestCase1;
    p_uFrequencyExpected = a_uFrequencyExpectedTestCase1;
  }
  else  if(!strcmp(argv[2],"testcase2"))
  {
    uTestCase = 2;
    uIOConfig = 0x7; /* All IOs = Outputs */
    p_uEdgesExpected = a_uEdgesExpectedTestCase2;
    p_uFrequencyExpected = a_uFrequencyExpectedTestCase2;
  }
  else  if(!strcmp(argv[2],"testcase3"))
  {
    uTestCase = 3;
    uIOConfig = 0x0; /* All IOs = Inputs */
    p_uEdgesExpected = a_uEdgesExpectedTestCase3;
    p_uFrequencyExpected = a_uFrequencyExpectedTestCase3;
  }
  else
  {
    fprintf(stdout, "%s: unknown test case!\n", argv[0]);
    return 1;
  }
  fprintf(stdout, "%s: test case %d\n", argv[0], uTestCase);
  
  /* Try to open a (etherbone-) socket */
  socket.open();
  if ((status = device.open(socket, argv[1])) != EB_OK) 
  {
    fprintf(stderr, "%s: failed to open %s: (status %s)\n", argv[0], argv[1], eb_status(status));
    return 1;
  }
  else
  {
    fprintf(stdout, "%s: succeeded to open %s (status %s)\n", argv[0], argv[1], eb_status(status));
  }
  
  /* Find the ECA */
  ECA::probe(device, ecas);
  if (ecas.size() == 1)
  {
    fprintf(stdout, "%s: found one eca unit!\n", argv[0]);
  }
  else
  {
    fprintf(stdout, "%s: missing eca unit!\n", argv[0]);
    return 1;
  }
  ECA& eca = ecas[0];
  
  /* Find the TLU */
  TLU::probe(device, tlus);
  assert (tlus.size() == 1);
  TLU& tlu = tlus[0];
  /* Configure the TLU to record rising edge timestamps */
  tlu.hook(-1, false);
  tlu.set_enable(false); // no interrupts, please
  tlu.clear(-1);
  tlu.listen(-1, true, true, 8); /* Listen on all inputs */
  
  /* Find the IO reconfig to enable/disable outputs to specific IOs */
  std::vector<sdb_device> devs;
  device.sdb_find_by_identity(0x651, 0x4d78adfdU, devs);
  assert (devs.size() == 1);
  address_t ioconf = devs[0].sdb_component.addr_first;
  device.write(ioconf, EB_DATA32, uIOConfig);
  
  /* Show time */
  eca.refresh();
  fprintf(stdout, "%s: time (fmt): %s\n", argv[0], eca.date().c_str());
  fprintf(stdout, "%s: time (hex): 0x%"PRIx64"\n", argv[0], eca.time);
  
  /* Configure ECA to create IO pulses on GPIO and LVDS */
  eca.channels[0].drain(false); // GPIO
  eca.channels[1].drain(true); // PCIe
  eca.channels[2].drain(true); // LVDS
  eca.channels[0].freeze(false);
  eca.channels[1].freeze(false);
  eca.channels[2].freeze(false);
  eca.disable(true);
  eca.interrupt(false);
  
  /* Build table */   
  for (int i = 0; i < EVENTS*EVENT_MULTI; ++i)
  {
    table.add(TableEntry(0xdeadbeef, i*(HIGH_NS+LOW_NS)/8,               (0x1<<uShiftPosition),      0, 64));
    table.add(TableEntry(0xdeadbeef, i*(HIGH_NS+LOW_NS)/8+(HIGH_NS/8),   (0x1<<(uShiftPosition+16)), 0, 64));
    /* Take care on shift position */
    if(uShiftPosition==EVENTS-1) { uShiftPosition=0; }
    else                         { uShiftPosition++; }
  }

  /* Manage ECA */
  eca.store(table);
  eca.flipTables();
  eca.disable(false);
  eca.refresh();
  uint64_t start = eca.time + (CPU_DELAY_MS*1000*1000)/8;
  eca.streams[0].send(EventEntry(0xdeadbeef, 0, 0, start));
   
  /* Sleep ... until all events have finished */
  usleep(CPU_DELAY_MS*2000 + (long)(HIGH_NS+LOW_NS)*(EVENTS*EVENT_MULTI)/1000); 

  /* Read-out result */
  tlu.pop_all(queues);
  uQueuesTotal = queues.size();
  fprintf(stdout, "%s: found queues %d ...\n", argv[0], uQueuesTotal);
  
  /* Check each queue now */
  for(uQueueInterator=0; uQueueInterator<uQueuesTotal; uQueueInterator++)
  {
    std::vector<uint64_t>& queue = queues[uQueueInterator];
    uQueneItems = queue.size(); /* Get the actual size */
    fprintf(stdout, "%s: queue %d has a size of %d ...\n", argv[0], uQueueInterator, uQueneItems);
    /* Inspect items with queue contains data */
    if(uQueneItems)
    {
      for(uQueueItemIterator=0; uQueueItemIterator<uQueneItems; uQueueItemIterator++)
      {
        a_uEdges[uQueueInterator]++; /* Count up seen edges */
        fprintf(stdout, "%s: queue[%d][%d]: 0x%"PRIx64" (0x%"PRIx64")... ", argv[0], uQueueInterator, uQueueItemIterator, queue[uQueueItemIterator]/8, queue[uQueueItemIterator]);
        if(uQueueItemIterator>=1)
        {
          uTimeDiff = queue[uQueueItemIterator]-queue[uQueueItemIterator-1]; 
          fprintf(stdout, "(difference to previous time stamp 0x%"PRIx64" (%"PRIu64"))\n", uTimeDiff, uTimeDiff);
          a_uFrequency[uQueueInterator] += uTimeDiff; /* Sum up time stamps */
          /* Allow little jitter/uncertainty */
          if( ((*p_uFrequencyExpected+TOLERANCE_FACTOR_NS)<uTimeDiff) ||
              ((*p_uFrequencyExpected-TOLERANCE_FACTOR_NS)>uTimeDiff)
          )
          {
            fprintf(stdout, "%s: too much jitter for IO %d!\n", argv[0], uQueueInterator);
            return 1;
          }
        }
        else
        {
          fprintf(stdout, "\n");
        }
      }
    }
    p_uFrequencyExpected++;
  }
  
  /* Reset Frequency expected pointer */
  if(uTestCase==1)      { p_uFrequencyExpected = a_uFrequencyExpectedTestCase1; }
  else if(uTestCase==2) { p_uFrequencyExpected = a_uFrequencyExpectedTestCase2; }
  else                  { p_uFrequencyExpected = a_uFrequencyExpectedTestCase3; }
  
  /* Evaluate test case */
  for(uArrayIterator=0; uArrayIterator<EVENTS; uArrayIterator++)
  {
    /* Compare expected edges */
    if(a_uEdges[uArrayIterator] != *p_uEdgesExpected)
    {
      fprintf(stdout, "%s: wrong number of seen edges for IO %d!\n", argv[0], uArrayIterator);
      fprintf(stdout, "%s: expected %d edges!\n", argv[0], *p_uEdgesExpected);
      fprintf(stdout, "%s: measured %d edges!\n", argv[0], a_uEdges[uArrayIterator]);
      return 1;
    }
    
    /* Compare expected frequency (if we expected edges on this IO) */
    if(*p_uEdgesExpected)
    {
      dExpectedFrequency = *p_uFrequencyExpected;
      dMeasuredFrequency = a_uFrequency[uArrayIterator] / (a_uEdges[uArrayIterator]-1);
      
      if(dMeasuredFrequency!=dExpectedFrequency)
      {
        /* Allow little jitter/uncertainty */
        if( ((dExpectedFrequency+TOLERANCE_FACTOR_NS)<dMeasuredFrequency) ||
            ((dExpectedFrequency-TOLERANCE_FACTOR_NS)>dMeasuredFrequency)
          )
        {
          fprintf(stdout, "%s: average frequency does not match for IO %d!\n", argv[0], uArrayIterator);
          fprintf(stdout, "%s: expected average frequency on %f: \n", argv[0], dExpectedFrequency);
          fprintf(stdout, "%s: measured average frequency on %f: \n", argv[0], dMeasuredFrequency);
          return 1;
        }
      }
    }
    
    /* Increase compare pointers */
    p_uFrequencyExpected++;
    p_uEdgesExpected++;
    
  }

  /* Done */
  return 0;
  
}
コード例 #13
0
ファイル: main.cpp プロジェクト: radekula/other
int main(int argc, char *argv[])
{
	gtk_init(&argc, &argv);

	Window *main_window = new Window();
	main_window->resize(-1,-1);

	VBox *main_vbox = new VBox();
	HBox *menu_hbox = new HBox();

    pixbuf = new Pixbuf();
    pixbuf->set_scale(5);

	image = new Image();
	image->set_from_pixbuf(pixbuf);  
	menu_hbox->add(image, 1, 1, 0);
	
	VBox *s_vbox = new VBox();
	
	Label *label = new Label("Sąsiedztwo: ");
	s_vbox->add(label, 1, 1, 0);
	
	Table *table = new Table();
	s_vbox->add(table, 0, 0, 0);
	
	for(int y = 0; y < 3; y++)
	{
		for(int x = 0; x < 3; x++)
		{
			sasiedztwo[x][y] = new ToggleButton();
			sasiedztwo[x][y]->set_label(std::to_string(x + (y * 3) + 1));
			
			if(x == 1 && y == 1)
			{
				table->add(new Label("x"), x, y, x + 1, y + 1);
				continue;
			};
			
			table->add(sasiedztwo[x][y], x, y, x + 1, y + 1);
		};
	};

	Label *label2 = new Label(" ");
	s_vbox->add(label2, 1, 1, 0);
	
	menu_hbox->add(s_vbox, 0, 0, 0);
	main_vbox->add(menu_hbox, 1, 1, 0);

	Button *start_button = new Button("Start");
	start_button->set_on_clicked(line_fill);
	main_vbox->add(start_button, 0, 0, 0);

	Button *stop_button = new Button("Stop");
	stop_button->set_on_clicked(stop);
	main_vbox->add(stop_button, 0, 0, 0);
	
	main_window->add(main_vbox);

    clear_image(main_window->get_ref(), 0);   
	main_window->show();
	
	g_timeout_add(50, refresh_screen, 0);
	
	gtk_main();
		
	return 0;
};
コード例 #14
0
ファイル: b2g-info.cpp プロジェクト: ahal/gonk-misc
int
print_b2g_info(bool show_threads)
{
  // TODO: switch between kb and mb for RSS etc.
  // TODO: Sort processes?

  Table t;

  // This sits atop USS/PSS/RSS/VSIZE.
  t.multi_col_header("megabytes", 3, 7);

  if (!show_threads) {
    b2g_ps_add_table_headers(t, /* show_threads */ false);
  }

  for (vector<Process*>::const_iterator it =
         ProcessList::singleton().b2g_processes().begin();
       it != ProcessList::singleton().b2g_processes().end(); ++it) {

    if (show_threads) {
      b2g_ps_add_table_headers(t, /* show_threads */ true);
    }

    Process* p = *it;
    t.start_row();
    t.add(p->name());
    t.add(p->pid());
    t.add(p->ppid());
    t.add_fmt("%0.1f", p->stime_s() + p->utime_s());
    t.add(p->nice());
    t.add_fmt("%0.1f", p->uss_mb());
    t.add_fmt("%0.1f", p->pss_mb());
    t.add_fmt("%0.1f", p->rss_mb());
    t.add_fmt("%0.1f", p->vsize_mb());
    t.add(p->oom_adj());
    t.add(p->user(), Table::ALIGN_LEFT);

    if (show_threads) {
      for (vector<Thread*>::const_iterator thread_it =
             p->threads().begin();
           thread_it != p->threads().end(); ++thread_it) {
        t.start_row();

        Thread* thread = *thread_it;
        t.add(thread->name());
        t.add(thread->tid());
        t.add(thread->nice());
      }

      if (it + 1 != ProcessList::singleton().b2g_processes().end()) {
        t.add_delimiter();
      }
    }
  }

  t.print();
  putchar('\n');

  print_system_meminfo();
  putchar('\n');

  print_lmk_params();

  return 0;
}
コード例 #15
0
ファイル: b2g-info.cpp プロジェクト: ahal/gonk-misc
void print_system_meminfo()
{
  // We can't use sysinfo() here because iit doesn't tell us how much cached
  // memory we're using.  (On B2G, this is often upwards of 30mb.)
  //
  // Instead, we have to parse /proc/meminfo.

  FILE* meminfo = fopen("/proc/meminfo", "r");
  if (!meminfo) {
    perror("Couldn't open /proc/meminfo");
    return;
  }

  // These are all in kb.
  int total = -1;
  int free = -1;
  int buffers = -1;
  int cached = -1;

  char line[256];
  while(fgets(line, sizeof(line), meminfo)) {
    if (sscanf(line, "MemTotal: %d kB", &total) == 0 &&
        sscanf(line, "MemFree: %d kB", &free) == 0 &&
        sscanf(line, "Buffers: %d kB", &buffers) == 0 &&
        sscanf(line, "Cached: %d kB", &cached)) {
      // These four values should appear first in meminfo, so if this line
      // doesn't match any of them, we're done parsing.
      break;
    }
  }

  fclose(meminfo);

  if (total == -1 || free == -1 || buffers == -1 || cached == -1) {
    fprintf(stderr, "Unable to parse /proc/meminfo.\n");
    return;
  }

  int actually_used = total - free - buffers - cached;

  puts("System memory info:\n");

  Table t;

  t.start_row();
  t.add("Total");
  t.add_fmt("%0.1f MB", kb_to_mb(total));

  t.start_row();
  t.add("Used - cache");
  t.add_fmt("%0.1f MB", kb_to_mb(total - free - buffers - cached));

  t.start_row();
  t.add("B2G procs (PSS)");

  int b2g_mem_kb = 0;
  for (vector<Process*>::const_iterator it = ProcessList::singleton().b2g_processes().begin();
       it != ProcessList::singleton().b2g_processes().end(); ++it) {
    b2g_mem_kb += (*it)->pss_kb();
  }
  t.add_fmt("%0.1f MB", b2g_mem_kb / 1024.0);

  t.start_row();
  t.add("Non-B2G procs");
  t.add_fmt("%0.1f MB", kb_to_mb(total - free - buffers - cached - b2g_mem_kb));

  t.start_row();
  t.add("Free + cache");
  t.add_fmt("%0.1f MB", kb_to_mb(free + buffers + cached));

  t.start_row();
  t.add("Free");
  t.add_fmt("%0.1f MB", kb_to_mb(free));

  t.start_row();
  t.add("Cache");
  t.add_fmt("%0.1f MB", kb_to_mb(buffers + cached));

  t.print_with_indent(2);
}
コード例 #16
0
void Database::deleteQuery(string queryCmd) {
	// create necessary tables
	Table returnTable = Table();
	Table tableFrom = Table();

	// get the indicies of the starting positions of the three parts of the query
	int select_i = -1, from_i = -1, where_i = -1;

	for (int i = 0; i < queryCmd.length(); i ++) {
		if (queryCmd.substr(i,6).compare("SELECT") == 0) select_i = i + 6;
		if (queryCmd.substr(i,4).compare("FROM") == 0) from_i = i + 4;
		if (queryCmd.substr(i,5).compare("WHERE") == 0) where_i = i + 5;
	}

	// build a string vector of the attributes to return
	string attrTemp = "";
	vector<string> attrStrings;
	for (int i = select_i; i < from_i - 4; i ++) {
		if (queryCmd.substr(i,1).compare(",") != 0) attrTemp += queryCmd.substr(i,1);
		if (queryCmd.substr(i,1).compare(",") == 0 || i == from_i - 4 - 1) {
			trimWS(attrTemp);
			attrStrings.push_back(attrTemp);
			attrTemp = "";
		}
	}

	// get the table to select from
	string tableFromName = queryCmd.substr(from_i + 1, where_i - 5 - from_i - 2);
	bool found = false;
	for (int i = 0; i < getTables().size(); i ++) {
		if (getTables()[i].getName().compare(tableFromName) == 0) {
			tableFrom = Table(getTables()[i]);
			found = true;
		}
	}
	if (!found) throw Database_exception("Couldn't find the table specified [" + tableFromName + "]");

	// put those attributes in returnTable
	for (int i = 0; i < tableFrom.getAttributes().size(); i ++) {
		returnTable.add(tableFrom.getAttributes()[i]);
	}

	// remove unessecary attributes
	for (int i = 0; i < returnTable.getAttributes().size(); i ++) {
		bool goodAttr = false;
		for (int j = 0; j < attrStrings.size(); j ++) {
			if (returnTable.getAttributes()[i].getAttribute().compare(attrStrings[j]) == 0 || attrStrings[0].compare("*") == 0) goodAttr = true;
		}

		if (!goodAttr) returnTable.deleteATT(returnTable.getAttributes()[i].getAttribute());
	}

	// at this point, returnTable has the correct aTTs, and fromTable is the table we're selecting from

	// convert the where clause into postfix
	string exp = queryCmd.substr(where_i + 1,queryCmd.length() - where_i);
	queue<string> postfix = expressionToPostfix(exp);

	// for each record, evaluate the postfix exp for it's values, then add it to the returnTable if it's true
	for (int i = 0; i < tableFrom.getSize(); i ++) {

		Record testRecord = tableFrom[i];
		queue<string> testPostfix = postfix;
		stack<string> t_stack;

		while (!testPostfix.empty()) {
			string token = testPostfix.front();
			testPostfix.pop();
			
			// if its a value, move it to the stack
			if (!isOp(token)) t_stack.push(token);

			// its an operator, pop off two values and evaluate them
			else {
				string op2 = t_stack.top();
				t_stack.pop();
				string op1 = t_stack.top();
				t_stack.pop();

				// evaluate
				if (token.compare("=") == 0) {
					t_stack.push(evalE(op1,op2, tableFrom, testRecord));
				} else if (token.compare(">") == 0) {
					t_stack.push(evalG(op1,op2, tableFrom, testRecord));
				} else if (token.compare("<") == 0) {
					t_stack.push(evalL(op1,op2, tableFrom, testRecord));
				} else if (token.compare("!=") == 0) {
					t_stack.push(evalNE(op1,op2, tableFrom, testRecord));
				} else if (token.compare(">=") == 0) {
					t_stack.push(evalGE(op1,op2, tableFrom, testRecord));
				} else if (token.compare("<=") == 0) {
					t_stack.push(evalLE(op1,op2, tableFrom, testRecord));
				} else if (token.compare("&&") == 0) {
					t_stack.push(evalA(op1,op2, tableFrom, testRecord)); 
				} else if (token.compare("||") == 0) {
					t_stack.push(evalO(op1,op2, tableFrom, testRecord));
				} else throw Database_exception("Evaluation failed, likely bad query string");
			}
		}

		// remove
		if (t_stack.top().compare("true") == 0) {
			for (int i = 0; i < tables.size(); i ++) {
				// if *, remove whole record
				if (attrStrings[0].compare("*") == 0) {
					if (tables[i].getName().compare(tableFromName) == 0) {
						dropTable(tableFromName);
					}
				}
				// otherwise need to null out
				else {
					// get the right table
					if (tables[i].getName().compare(tableFromName) == 0) {
						// for each removeable attribute
						for (int j = 0; j < tables[i].getAttributes().size(); j ++) {
							for (int k = 0; k < attrStrings.size(); k ++) {
								// if this attribute is to be deleted
								if (tables[i].getAttributes()[j].getAttribute().compare(attrStrings[k]) == 0) {
									for (int l = 0; l < tables[i].getSize(); l ++) {
										tables[i][l].nullValue(j);
									}
								}
							}
						}
					}

				}

			}
		}

	}

}
コード例 #17
0
ファイル: main.cpp プロジェクト: BDM30/review2014
int main()
{
    Test test;
    QTest::qExec(&test);
    printf("\n\n\n");

    Table *t = new Table;
    char choice = '-';
    char s[100];

    HashFunc *f1 = new Func1;
    HashFunc *f2 = new Func2;




    while(choice != '0')
    {
        printf("0 - Exit\n");
        printf("1 - Add string\n");
        printf("2 - Del string\n");
        printf("3 - Show stats\n");
        printf("4 - Search string\n");
	printf("5 - Select hash-function\n");
        choice = getc(stdin);
        getc(stdin);
        printf("\n");


        if (choice == '1')
        {
            printf("Enter the string: ");
            fgets(s, 200, stdin);
            t->add(s);
            printf("\n\n");
        }
        else if (choice == '2')
        {
            printf("Enter the string: ");
            fgets(s, 200, stdin);
            t->del(s);
            printf("\n\n");
        }
        else if (choice == '3')
        {
            printf("Enter the string: ");
            fgets(s, 200, stdin);
            if(t->exist(s))
                printf("Yes");
            else
                printf("No");

            printf("\n\n");
        }
        else if (choice == '4')
        {
            printf("Numer of cells: %i\n", t->cells());
            t->stats();
            printf("Load factor is %lf\n", t->loadFactor);
            printf("Number of conflicts is %i\n", t->conflicts);
            printf("Maximum length of conflict is %i\n\n", t->lconf);
        }
        else if (choice == '5')
        {
            printf("Enter the number of func (1/2): ");
            char c = '-';
            c = getc(stdin);
            getc(stdin);
            if (c == '1')
                t->changeFunc(f1);
            else if (c == '2')
                t->changeFunc(f2);

        }
    }









    delete t;
    return 0;
}