Esempio n. 1
0
  /** Loads stats from /proc/[pid]/stat and /proc/[pid]/statm files */
  public static ProcessStatus getProcStats(String pid) {

    // using a space as the delimeter.
    String data;

    // get the /proc/[pid]/stat as a string and them split into string array
    // using a space as the delimeter.
    try {
      data = FileReadUtil.readFirstLine(String.format(STAT_FILE, pid));
      String[] procStatData = data.split(SPACE_VALUE);
      long startTimeSecs =
          UnsignedLong.valueOf(procStatData[STAT_STARTTIME])
              .dividedBy(UnsignedLong.fromLongBits(HZ))
              .longValue();
      long currTimeSecs = new Date().getTime() / 1000;
      long upTimeSecs = currTimeSecs - (getBootTime() + startTimeSecs);
      return new ProcessStatus(
          upTimeSecs,
          Long.parseLong(procStatData[STAT_NUM_THREADS]),
          startTimeSecs,
          Integer.parseInt(procStatData[STAT_PID]),
          Long.parseLong(procStatData[STAT_RSS]) * getPageSize(),
          Long.parseLong(procStatData[STAT_VSIZE]));
    } catch (Exception e) {
      _log.error("Error occurred while getting service stats from /stats file: {}", e);
    }

    return null;
  }
Esempio n. 2
0
 @Test
 public void testGetULong() throws Exception {
   try (Cursor cursor =
       new SimpleCursor(
           QueryResult.newBuilder()
               .addFields(
                   Field.newBuilder()
                       .setName("col0")
                       .setType(Field.Type.TYPE_LONGLONG)
                       .setFlags(Field.Flag.VT_UNSIGNED_FLAG_VALUE)
                       .build())
               .addRows(
                   Row.newBuilder().addValues(ByteString.copyFromUtf8("18446744073709551615")))
               .build())) {
     cursor.next();
     Assert.assertEquals(UnsignedLong.fromLongBits(-1), cursor.getULong("col0"));
   }
 }
Esempio n. 3
0
 @Test
 public void testGetULong() throws Exception {
   try (Cursor cursor =
       new SimpleCursor(
           QueryResult.newBuilder()
               .addFields(Field.newBuilder().setName("col1").setType(Query.Type.UINT64).build())
               .addFields(Field.newBuilder().setName("null").setType(Query.Type.UINT64).build())
               .addRows(
                   Query.Row.newBuilder()
                       .addLengths("18446744073709551615".length())
                       .addLengths(-1) // SQL NULL
                       .setValues(ByteString.copyFromUtf8("18446744073709551615")))
               .build())) {
     Row row = cursor.next();
     Assert.assertNotNull(row);
     Assert.assertEquals(UnsignedLong.fromLongBits(-1), row.getULong("col1"));
     Assert.assertFalse(row.wasNull());
     Assert.assertEquals(null, row.getULong("null"));
     Assert.assertTrue(row.wasNull());
   }
 }