commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LANG-1373) Stopwatch based capability for nested, named, timings in a call stack
Date Sat, 27 Jan 2018 21:44:00 GMT

    [ https://issues.apache.org/jira/browse/LANG-1373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16342330#comment-16342330
] 

ASF GitHub Bot commented on LANG-1373:
--------------------------------------

Github user kinow commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/311#discussion_r164282304
  
    --- Diff: src/main/java/org/apache/commons/lang3/time/StackWatch.java ---
    @@ -0,0 +1,329 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.commons.lang3.time;
    +
    +import java.util.Deque;
    +import java.util.LinkedList;
    +import org.apache.commons.lang3.StringUtils;
    +
    +/**
    + * <p>
    + * The {@code StackWatch}, provides a wrapper around the {@code StopWatch} for creating
multiple and
    + * possibly nested named timings.
    + * </p>
    + * <p>
    + * While the {@code StopWatch} provides functionality to time the length of operations,
there is no
    + * context or name to go with the time tracked. It is also not possible to time nested
calls with
    + * the {@code StopWatch}.
    + * </p>
    + * <p>
    + * {@code StackWatch} provides that functionality, allowing successive calls to {@link
StackWatch#startTiming(String, String...)} to track
    + * nested calls.
    + * </p>
    + * <p>
    + * Each start provides a timing name and a parent timing name, thus providing context
to the timing.
    + * </p>
    + * <p>
    + * At the end of a timing 'run', a visitor interface provides the ability to visit all
the timing
    + * 'nodes' and capture their output, including the level of the call if nested.
    + * </p>
    + * <p>
    + * The {@code TimeRecordNodes} provide a tree structure in support of nesting.
    + * A {@code Deque} is use to track the current time node.
    + * </p>
    + *
    + * <pre>
    + *   {@code
    + *    private void outerFunction() {
    + *      try {
    + *        StackWatch watch = new StackWatch("OuterFunction");
    + *        watch.start();
    + *        functionOne();
    + *        watch.stop();
    + *        watch.visit(new TimingRecordNodeVisitor() {
    + *          {@literal @}Override
    + *          public void visitRecord(int level, TimingRecordNode node) {
    + *            ...
    + *          }
    + *        });
    + *      } catch (Exception e){}
    + *    }
    + *    private void functionOne(StackWatch watch) throws Exception {
    + *      watch.startTiming("One", "OneFunc");
    + *      functionOneOne(watch);
    + *      watch.stopTiming();
    + *    }
    + *
    + *    private void functionOneOne(StackWatch watch) throws Exception {
    + *      watch.startTiming("OneOne", "OneFunc");
    + *      functionOneTwo(watch);
    + *      watch.stopTiming();
    + *    }
    + *
    + *    private void functionOneTwo(StackWatch watch) throws Exception {
    + *      watch.startTiming("OneTwo", "OneFunc");
    + *      watch.stopTiming();
    + *    }
    + *   }
    + * </pre>
    + *
    + *
    + * <p>
    + * This class is not thread safe, and is meant to track timings across multiple calls
on the same
    + * thread
    + * </p>
    + */
    +public class StackWatch {
    +
    +  /**
    +   * The default name for the root level timing if not provided
    +   */
    +  public static final String DEFAULT_ROOT_NAME = "ROOT_TIMING";
    --- End diff --
    
    Here is needs to be four spaced as well. You can look at another file and compare that
(e.g. https://github.com/apache/commons-lang/blob/f50ec5e608286b0c48d6b9b4c792352de8353804/src/main/java/org/apache/commons/lang3/concurrent/AtomicSafeInitializer.java#L58).


> Stopwatch based capability for nested, named, timings in a call stack
> ---------------------------------------------------------------------
>
>                 Key: LANG-1373
>                 URL: https://issues.apache.org/jira/browse/LANG-1373
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.time.*
>            Reporter: Otto Fowler
>            Priority: Major
>
> While working on adding some timing functionality to a Metron feature, I came across
the
> Stopwatch class, but found that it didn’t suite my needs.
> What I wanted to do was to create a timing from a top level function in our Stellar dsl,
and have have a group of related timings, such that the end result was the overall time of
the call, and nested timings of other calls executed during the dsl execution of that function.
These timings would all be named, and have a path for identification and include timing the
language compiler/execution as well as the function execution itself. It would be helpful
if they were tagged in some way as well, such that the consumer could filter during visitation.
> So I have written StackWatch to provide this functionality, and submitted it in a Metron
PR.
> From the PR description:
> StackWatch
> A set of utility classes under the new package stellar.common.timing have been added.
These provide the StackWatch functionality.
> StackWatch provides an abstraction over the Apache Commons StopWatch class that allows
callers to create multiple named and possibly nested timing operations.
> <…>
> This class may be more generally useful to this and other projects, but I am not sure
where it would live since we wouldn’t want it in common.
> StackWatch uses a combination of Deque and a custom Tree implementation to create, start
and end timing operations.
> A Visitor pattern is also implemented to allow for retrieving the results after the completion
of the operation.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message