Jwang add resource measurements

This is the refactored version of the closed PR https://github.com/uwescience/myria/pull/575. The biggest changes are: 1. separated the resource stats collecting task from the heartbeat reporter to an independent reporter in WorkerSubQuery. 2. put the resource stats of each query within each Query object instead of in Server.

The whole pipeline works like this:
WorkerSubQuery has a task scheduled every second that collects resource stats from operators/tasks. It then sends the stats as a proto message from the worker to the master, meanwhile dumping them to postgres. The server receives these resource stats and assigns them to each Query object. Query appends them to its internal list of resource stats. 
When there is a REST API call to get the resource usage of a query, we first check if the query is still running. If so, its internal resource stats list is read and returned. Otherwise, the query has finished, then a Myria query will be issued to get resource stats from each worker's resource table in postgres. Caching the stats of a running query in memory instead of always issuing a Myria query can accelerate this process. It is necessary if we want real-time information for, for example, visualization or scheduling. 
Agreed
On Dec 11, 2014 4:29 PM, "jingjingwang" <notifications@github.com> wrote:

> In src/edu/washington/escience/myria/profiling/ProfilingLogger.java
> <https://github.com/uwescience/myria/pull/656#discussion-diff-21721503>:
>
> > +  private void flushProfilingResourceBatch() {
> > +    final long startTime = System.nanoTime();
> > +    try {
> > +      if (batchSizeResource == 0) {
> > +        return;
> > +      }
> > +      statementResource.executeBatch();
> > +      statementResource.clearBatch();
> > +      batchSizeResource = 0;
> > +    } catch (SQLException e) {
> > +      if (e instanceof BatchUpdateException) {
> > +        LOGGER.error("Error writing batch: ", e.getNextException());
> > +      }
> > +      throw new RuntimeException(e);
> > +    }
> > +    LOGGER.info("Flushing the profiling resource batch took {} milliseconds.", TimeUnit.NANOSECONDS.toMillis(System
>
> I think it's still "profiling" -- resource profiling :)
> I'll remove the word, but maybe we should avoid use the word "profiling"
> for any specific stats..? Now we have (Profiling)Event, Sent, and
> (Profiling)Resource.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/uwescience/myria/pull/656/files#r21721503>.
>