Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/vis15/src/logging/log-analyze/quantize.cxx
ViewVC logotype

View of /branches/vis15/src/logging/log-analyze/quantize.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4889 - (download) (as text) (annotate)
Thu Jan 5 19:32:00 2017 UTC (2 years, 7 months ago) by jhr
File size: 2210 byte(s)
  working on analysis
/*! \file quantize.cxx
 *
 * \author John Reppy
 */

/*
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2017 The University of Chicago
 * All rights reserved.
 */

#include "quantize.hxx"
#include <cstdlib>
#include <iostream>

buckets::buckets (uint32_t nThreads, uint32_t nBuckets, uint32_t nStates, uint64_t timeQ)
  : _runT(nBuckets*timeQ),
    _timeQ(timeQ),
    _bucket(new uint64_t[nThreads*nBuckets*(nStates+1)]),
    _lastT(new uint64_t[nThreads]),
    _state(new uint32_t[nThreads]),
    _nThreads(nThreads), _nBuckets(nBuckets), _nStates(nStates+1)
{
  // initialize arrays
    for (uint32_t i = 0;  i < nThreads;  i++) {
	this->_lastT[i] = 0;
	this->_state[i] = 0;
	for (uint32_t j = 0;  j < nBuckets;  j++) {
	    for (uint32_t k = 0;  k <= nStates;  k++) {
		this->_bucket[this->_index(i, j, k)] = 0;
	    }
	}
    }
}

buckets::~buckets ()
{
    delete[] this->_bucket;
    delete[] this->_lastT;
    delete[] this->_state;
}

void buckets::_addTime (uint32_t tid, uint32_t sid, uint64_t startT, uint64_t endT)
{
    if (endT <= startT) {
	return;
    }
    if (this->_runT < endT) {
	std::cerr << "addTime: end time " << endT << " is after run time " << this->_runT << "\n";
	exit (1);
    }
    uint32_t startB = startT / this->_timeQ;
    uint32_t endB = endT / this->_timeQ;
    sid += 1;  // state 0 holds total time
    if (startB == endB) {
	this->_bucket[this->_index(tid, startB, sid)] += (endT - startT);
    }
    else {
	uint64_t t = (startB + 1) * this->_timeQ;
	while (t < endT) {
	    uint64_t dt = t - startT;
	    this->_bucket[this->_index(tid, startB, sid)] += (t - startT);
	    startT = t;
	    t += this->_timeQ;
	    startB++;
	}
	this->_bucket[this->_index(tid, endB, sid)] += (endT - startT);
    }
}

void buckets::finish (uint64_t endT)
{
  // add total time per bucket
    for (uint32_t i = 0;  i < this->_nThreads;  i++) {
	this->_addTime (i, 0, this->_lastT[i], endT);
	for (uint32_t j = 0;  j < this->_nBuckets;  j++) {
	    uint64_t t = 0;
	    for (uint32_t k = 1;  k < this->_nStates;  k++) {
		t += this->_bucket[this->_index(i, j, k)];
	    }
	    this->_bucket[this->_index(i, j, 0)] = t;
	}
    }
}

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0