use of com.cloud.utils.Profiler in project CloudStack-archive by CloudStack-extras.
the class GlobalLock method lock.
public boolean lock(int timeoutSeconds) {
int remainingMilliSeconds = timeoutSeconds * 1000;
Profiler profiler = new Profiler();
boolean interrupted = false;
try {
while (true) {
synchronized (this) {
if (ownerThread != null && ownerThread == Thread.currentThread()) {
s_logger.warn("Global lock re-entrance detected");
lockCount++;
if (s_logger.isTraceEnabled())
s_logger.trace("lock " + name + " is acquired, lock count :" + lockCount);
return true;
}
if (ownerThread != null) {
profiler.start();
try {
wait(((long) timeoutSeconds) * 1000L);
} catch (InterruptedException e) {
interrupted = true;
}
profiler.stop();
remainingMilliSeconds -= profiler.getDuration();
if (remainingMilliSeconds < 0)
return false;
continue;
} else {
// take ownership temporarily to prevent others enter into stage of acquiring DB lock
ownerThread = Thread.currentThread();
addRef();
}
}
if (DbUtil.getGlobalLock(name, remainingMilliSeconds / 1000)) {
synchronized (this) {
lockCount++;
holdingStartTick = System.currentTimeMillis();
if (s_logger.isTraceEnabled())
s_logger.trace("lock " + name + " is acquired, lock count :" + lockCount);
return true;
}
} else {
synchronized (this) {
ownerThread = null;
releaseRef();
return false;
}
}
}
} finally {
if (interrupted) {
Thread.currentThread().interrupt();
}
}
}
use of com.cloud.utils.Profiler in project CloudStack-archive by CloudStack-extras.
the class SecurityGroupManagerImpl2Test method _schedule.
protected void _schedule(final int numVms) {
System.out.println("Starting");
List<Long> work = new ArrayList<Long>();
for (long i = 100; i <= 100 + numVms; i++) {
work.add(i);
}
Profiler profiler = new Profiler();
profiler.start();
_sgMgr.scheduleRulesetUpdateToHosts(work, false, null);
profiler.stop();
System.out.println("Done " + numVms + " in " + profiler.getDuration() + " ms");
}
use of com.cloud.utils.Profiler in project CloudStack-archive by CloudStack-extras.
the class SecurityGroupQueueTest method testNumJobsEqToNumVms2.
protected void testNumJobsEqToNumVms2(int numProducers, int maxVmId) {
queue.clear();
Thread[] pThreads = new Thread[numProducers];
Producer[] producers = new Producer[numProducers];
int numProduced = 0;
Profiler p = new Profiler();
p.start();
for (int i = 0; i < numProducers; i++) {
producers[i] = new Producer(maxVmId);
pThreads[i] = new Thread(producers[i]);
numProduced += i + 1;
pThreads[i].start();
}
for (int i = 0; i < numProducers; i++) {
try {
pThreads[i].join();
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}
p.stop();
System.out.println("Num Vms= " + maxVmId + " Queue size = " + queue.size() + " time=" + p.getDuration() + " ms");
assertEquals(maxVmId, queue.size());
}
use of com.cloud.utils.Profiler in project cosmic by MissionCriticalCloud.
the class SynchronousListener method waitFor.
public synchronized Answer[] waitFor(final int s) throws InterruptedException {
if (_disconnected) {
return null;
}
if (_answers != null) {
return _answers;
}
final Profiler profiler = new Profiler();
profiler.start();
if (s <= 0) {
wait();
} else {
final int ms = s * 1000;
wait(ms);
}
profiler.stop();
if (s_logger.isTraceEnabled()) {
s_logger.trace("Synchronized command - sending completed, time: " + profiler.getDurationInMillis() + ", answer: " + (_answers != null ? _answers[0].toString() : "null"));
}
return _answers;
}
use of com.cloud.utils.Profiler in project cosmic by MissionCriticalCloud.
the class ClusterServiceServletImpl method executePostMethod.
private String executePostMethod(final HttpClient client, final PostMethod method) {
int response = 0;
String result = null;
try {
final Profiler profiler = new Profiler();
profiler.start();
response = client.executeMethod(method);
if (response == HttpStatus.SC_OK) {
result = method.getResponseBodyAsString();
profiler.stop();
if (s_logger.isDebugEnabled()) {
s_logger.debug("POST " + _serviceUrl + " response :" + result + ", responding time: " + profiler.getDurationInMillis() + " ms");
}
} else {
profiler.stop();
s_logger.error("Invalid response code : " + response + ", from : " + _serviceUrl + ", method : " + method.getParameter("method") + " responding time: " + profiler.getDurationInMillis());
}
} catch (final HttpException e) {
s_logger.error("HttpException from : " + _serviceUrl + ", method : " + method.getParameter("method"));
} catch (final IOException e) {
s_logger.error("IOException from : " + _serviceUrl + ", method : " + method.getParameter("method"));
} finally {
method.releaseConnection();
}
return result;
}
Aggregations