public void testGetItem() {
    {
      PSI psi = st.getStackItem("group1", "item1", "context");
      assertNotNull(psi);
      assertEquals("group1", psi.getGroup());
      assertEquals("item1", psi.getItem());
      assertEquals(m_timer.getTimeMillis(0), psi.getCreationTime());

      psi.close();

      TestItem item = getItem("group1", "item1");
      assertNotNull(item);
      assertEquals(m_timer.getTimeMillis(1) - m_timer.getTimeMillis(0), item.getTotalTime());
      assertEquals(0L, item.getChildsTime());
    }
    int tID = m_timer.currentTimerId();
    {
      PSI psi1 = st.getStackItem("g1", "i1");
      PSI psi2 = st.getStackItem("g1", "i2");
      psi2.close();
      assertEquals(
          m_timer.getTimeMillis(tID + 2) - m_timer.getTimeMillis(tID + 1), psi1.getChildsTime());
      psi1.close();
      assertEquals(
          m_timer.getTimeMillis(tID + 3) - m_timer.getTimeMillis(tID),
          getItem("g1", "i1").getTotalTime());
      assertEquals(
          m_timer.getTimeMillis(tID + 2) - m_timer.getTimeMillis(tID + 1),
          getItem("g1", "i1").getChildsTime());
    }
  }
 private boolean stackContainsItem(PSI item) {
   for (PSI psi : m_stack) {
     if (psi.getGroup().equals(item.getGroup()) && psi.getItem().equals(item.getItem()))
       return true;
   }
   return false;
 }
  public synchronized String getSnapshot() {

    HashSet<Object> requestsKeys = new HashSet<Object>();
    HashSet<Object> servicesKeys = new HashSet<Object>();

    for (Object key : m_act_stat.keySet()) {
      if (m_act_stat.get(key).idleInfo == null) {
        requestsKeys.add(key);
      } else {
        servicesKeys.add(key);
      }
    }

    StringWriter buf = new StringWriter();
    PrintWriter printer = new PrintWriter(buf);

    printer.printf("\nREQUESTS\n");
    for (Object key : requestsKeys) {
      printer.println("=========" + key.toString());
      ActivityStatus status = m_act_stat.get(key);
      Stack<PSI> stackPSI = status.ps.getStack();
      printer.print("Stack = ");
      int i = 0;
      for (PSI psi : stackPSI) {
        if (i != 0) {
          repeat(printer, ' ', 8, false);
        }
        printer.println("" + psi.getGroup() + "." + psi.getItem() + "." + psi.getContext());
        i = i + 1;
      }
    }

    printer.printf("\nSERVICES\n");
    for (Object key : servicesKeys) {
      printer.println("=========" + key.toString());
      ActivityStatus status = m_act_stat.get(key);
      printer.println("IdleInfo = " + status.idleInfo);
      Stack<PSI> stackPSI = status.ps.getStack();
      printer.print("Stack = ");
      int i = 0;
      for (PSI psi : stackPSI) {
        if (i != 0) {
          repeat(printer, ' ', 8, false);
        }
        printer.println("" + psi.getGroup() + "." + psi.getItem() + "." + psi.getContext());
        i = i + 1;
      }
    }

    printer.close();
    buf.flush();
    return buf.toString();
  }
  public void testRelease() {
    {
      try {
        st.release(new PSI(st, "g1", "i1", 823502L, 10));
      } catch (EmptyStackException e) {
      }
    }
    {
      PSI psi0 = st.getStackItem("g2", "i0");
      PSI psi1 = st.getStackItem("g2", "i1");
      st.getStackItem("g2", "i2");
      PSI psi3 = st.getStackItem("g2", "i3");

      Mockery ctx = new Mockery();
      final Log log = ctx.mock(Log.class);
      LogFactory lf = new ServerImplTest.TestLogFactory(log);
      Api api = new Api();
      api.setIntfImplementor(LogFactory.class, lf);
      ApiStack.pushApi(api);
      try {
        psi3.close();
        ctx.checking(
            new Expectations() {
              {
                one(log).error(with(any(String.class)));
              }
            });
        psi1.close(); // must be error reported
        ctx.assertIsSatisfied();
        psi0.close(); // no errors
      } finally {
        ApiStack.popApi();
      }
    }
  }
    public void release(PSI psi) throws EWrongPSI {
      long totalTime;
      boolean bInner;
      synchronized (m_profiler) {
        PSI e = m_stack.pop();
        if (psi.getStackNumber() != e.getStackNumber()) {
          ApiAlgs.getLog(this)
              .error(
                  psi.getGroup() + "." + psi.getItem() + " / " + e.getGroup() + "." + e.getItem());
          while (psi.getStackNumber() < e.getStackNumber()) e = m_stack.pop();
        }

        totalTime = m_timer.get() - psi.getCreationTime();

        if (!m_stack.isEmpty()) {
          PSI parent = m_stack.peek();
          parent.addChildTime(totalTime);
        }
        bInner = stackContainsItem(psi);
      }
      m_profiler.reportItem(psi.getGroup(), psi.getItem(), totalTime, psi.getChildsTime(), bInner);
    }