X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.utils.thread%2Fsrc%2Forg%2Fsimantics%2Futils%2Fthreads%2Flogger%2FThreadLogger.java;h=d569d4aad2a3c4b4c70fd7d95a3d0be9963c7b85;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=99ac51fecc15ef552e70126a7a64cd616f4ae016;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/logger/ThreadLogger.java b/bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/logger/ThreadLogger.java index 99ac51fec..d569d4aad 100644 --- a/bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/logger/ThreadLogger.java +++ b/bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/logger/ThreadLogger.java @@ -1,91 +1,91 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.utils.threads.logger; - -import java.io.DataOutput; -import java.io.DataOutputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; - -public class ThreadLogger implements IThreadLogger { - - public static String LOG_FILE = "d:\\threads.log"; - - public static boolean LOG = false; - - static Object loggerCreationLock = new Object(); - static ThreadLogger logger = null; - - DataOutput log; - - public ThreadLogger() { - if(LOG) { - try { - FileOutputStream stream = new FileOutputStream(LOG_FILE); - log = new DataOutputStream(stream); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - } - } - - public static ThreadLogger getInstance() { - if(logger == null) { - synchronized (loggerCreationLock) { - if(logger == null) - logger = new ThreadLogger(); - } - } - return logger; - } - - public class Task implements ITask { - - String name; - long beginTime; - long endTime; - long threadId; - - public Task(String name) { - this.name = name; - this.threadId = Thread.currentThread().getId(); - this.beginTime = System.nanoTime(); - } - - @Override - public void finish() { - this.endTime = System.nanoTime(); - if(LOG && log != null) { - - try { - synchronized(log) { - log.writeUTF(name); - log.writeLong(threadId); - log.writeLong(beginTime); - log.writeLong(endTime); - } - } catch(IOException e) { - e.printStackTrace(); - } - - } - } - - } - - @Override - public ITask begin(String taskName) { - return new Task(taskName); - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.utils.threads.logger; + +import java.io.DataOutput; +import java.io.DataOutputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; + +public class ThreadLogger implements IThreadLogger { + + public static String LOG_FILE = "d:\\threads.log"; + + public static boolean LOG = false; + + static Object loggerCreationLock = new Object(); + static ThreadLogger logger = null; + + DataOutput log; + + public ThreadLogger() { + if(LOG) { + try { + FileOutputStream stream = new FileOutputStream(LOG_FILE); + log = new DataOutputStream(stream); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + } + + public static ThreadLogger getInstance() { + if(logger == null) { + synchronized (loggerCreationLock) { + if(logger == null) + logger = new ThreadLogger(); + } + } + return logger; + } + + public class Task implements ITask { + + String name; + long beginTime; + long endTime; + long threadId; + + public Task(String name) { + this.name = name; + this.threadId = Thread.currentThread().getId(); + this.beginTime = System.nanoTime(); + } + + @Override + public void finish() { + this.endTime = System.nanoTime(); + if(LOG && log != null) { + + try { + synchronized(log) { + log.writeUTF(name); + log.writeLong(threadId); + log.writeLong(beginTime); + log.writeLong(endTime); + } + } catch(IOException e) { + e.printStackTrace(); + } + + } + } + + } + + @Override + public ITask begin(String taskName) { + return new Task(taskName); + } + +}