• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package io.perfmark;
18 
19 import javax.annotation.Nullable;
20 
21 public class Impl {
22   static final String NO_TAG_NAME = "";
23   static final long NO_TAG_ID = Long.MIN_VALUE;
24   /**
25    * This value is current {@link Long#MIN_VALUE}, but it could also be {@code 0}. The invariant
26    * {@code NO_LINK_ID == -NO_LINK_ID} must be maintained to work when PerfMark is disabled.
27    */
28   private static final long NO_LINK_ID = Long.MIN_VALUE;
29 
30   static final Tag NO_TAG = new Tag(Impl.NO_TAG_NAME, Impl.NO_TAG_ID);
31   static final Link NO_LINK = new Link(Impl.NO_LINK_ID);
32 
33   /** The Noop implementation */
Impl(Tag key)34   protected Impl(Tag key) {
35     if (key != NO_TAG) {
36       throw new AssertionError("nope");
37     }
38   }
39 
setEnabled(boolean value)40   protected void setEnabled(boolean value) {}
41 
setEnabled(boolean value, boolean overload)42   protected boolean setEnabled(boolean value, boolean overload) {
43     return false;
44   }
45 
startTask(T taskNameObject, StringFunction<? super T> taskNameFunc)46   protected <T> void startTask(T taskNameObject, StringFunction<? super T> taskNameFunc) {}
47 
startTask(String taskName, Tag tag)48   protected void startTask(String taskName, Tag tag) {}
49 
startTask(String taskName)50   protected void startTask(String taskName) {}
51 
startTask(String taskName, String subTaskName)52   protected void startTask(String taskName, String subTaskName) {}
53 
event(String eventName, Tag tag)54   protected void event(String eventName, Tag tag) {}
55 
event(String eventName)56   protected void event(String eventName) {}
57 
event(String eventName, String subEventName)58   protected void event(String eventName, String subEventName) {}
59 
stopTask()60   protected void stopTask() {}
61 
stopTask(String taskName, Tag tag)62   protected void stopTask(String taskName, Tag tag) {}
63 
stopTask(String taskName)64   protected void stopTask(String taskName) {}
65 
stopTask(String taskName, String subTaskName)66   protected void stopTask(String taskName, String subTaskName) {}
67 
linkOut()68   protected Link linkOut() {
69     return NO_LINK;
70   }
71 
linkIn(Link link)72   protected void linkIn(Link link) {}
73 
attachTag(Tag tag)74   protected void attachTag(Tag tag) {}
75 
attachTag(String tagName, String tagValue)76   protected void attachTag(String tagName, String tagValue) {}
77 
attachTag(String tagName, long tagValue)78   protected void attachTag(String tagName, long tagValue) {}
79 
attachTag(String tagName, long tagValue0, long tagValue1)80   protected void attachTag(String tagName, long tagValue0, long tagValue1) {}
81 
attachTag( String tagName, T tagObject, StringFunction<? super T> stringFunction)82   protected <T> void attachTag(
83       String tagName, T tagObject, StringFunction<? super T> stringFunction) {}
84 
createTag(@ullable String tagName, long tagId)85   protected Tag createTag(@Nullable String tagName, long tagId) {
86     return NO_TAG;
87   }
88 
89   @Nullable
unpackTagName(Tag tag)90   protected static String unpackTagName(Tag tag) {
91     return tag.tagName;
92   }
93 
unpackTagId(Tag tag)94   protected static long unpackTagId(Tag tag) {
95     return tag.tagId;
96   }
97 
unpackLinkId(Link link)98   protected static long unpackLinkId(Link link) {
99     return link.linkId;
100   }
101 
packTag(@ullable String tagName, long tagId)102   protected static Tag packTag(@Nullable String tagName, long tagId) {
103     return new Tag(tagName, tagId);
104   }
105 
packLink(long linkId)106   protected static Link packLink(long linkId) {
107     return new Link(linkId);
108   }
109 }
110