1 /* 2 * Copyright 2021 The Android Open Source Project 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 package com.android.server.appsearch.external.localstorage.stats; 17 18 import android.annotation.IntDef; 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.app.appsearch.AppSearchResult; 22 import android.app.appsearch.AppSearchSchema.StringPropertyConfig.JoinableValueType; 23 import android.app.appsearch.SearchSpec; 24 import android.app.appsearch.annotation.CanIgnoreReturnValue; 25 26 import com.android.internal.util.Preconditions; 27 28 import java.lang.annotation.Retention; 29 import java.lang.annotation.RetentionPolicy; 30 import java.util.Objects; 31 32 /** 33 * Class holds detailed stats for {@link android.app.appsearch.AppSearchSession#search(String, 34 * SearchSpec)} 35 * 36 * @hide 37 */ 38 public final class SearchStats { 39 @IntDef( 40 value = { 41 // Searches apps' own documents. 42 VISIBILITY_SCOPE_LOCAL, 43 // Searches the global documents. Including platform surfaceable and 3p-access. 44 VISIBILITY_SCOPE_GLOBAL, 45 VISIBILITY_SCOPE_UNKNOWN, 46 // TODO(b/173532925) Add THIRD_PARTY_ACCESS once we can distinguish platform 47 // surfaceable from 3p access(right both of them are categorized as 48 // VISIBILITY_SCOPE_GLOBAL) 49 }) 50 @Retention(RetentionPolicy.SOURCE) 51 public @interface VisibilityScope {} 52 53 // Searches apps' own documents. 54 public static final int VISIBILITY_SCOPE_LOCAL = 1; 55 // Searches the global documents. Including platform surfaceable and 3p-access. 56 public static final int VISIBILITY_SCOPE_GLOBAL = 2; 57 public static final int VISIBILITY_SCOPE_UNKNOWN = 3; 58 59 // TODO(b/173532925): Add a field searchType to indicate where the search is used(normal 60 // query vs in removeByQuery vs during migration) 61 62 @NonNull private final String mPackageName; 63 @Nullable private final String mDatabase; 64 /** 65 * The status code returned by {@link AppSearchResult#getResultCode()} for the call or internal 66 * state. 67 */ 68 @AppSearchResult.ResultCode private final int mStatusCode; 69 70 private final int mTotalLatencyMillis; 71 /** Time used to rewrite the search spec. */ 72 private final int mRewriteSearchSpecLatencyMillis; 73 /** Time used to rewrite the search results. */ 74 private final int mRewriteSearchResultLatencyMillis; 75 /** Time passed while waiting to acquire the lock during Java function calls. */ 76 private final int mJavaLockAcquisitionLatencyMillis; 77 /** 78 * Time spent on ACL checking. This is the time spent filtering namespaces based on package 79 * permissions and Android permission access. 80 */ 81 private final int mAclCheckLatencyMillis; 82 /** Defines the scope the query is searching over. */ 83 @VisibilityScope private final int mVisibilityScope; 84 /** Overall time used for the native function call. */ 85 private final int mNativeLatencyMillis; 86 /** Number of terms in the query string. */ 87 private final int mNativeNumTerms; 88 /** Length of the query string. */ 89 private final int mNativeQueryLength; 90 /** Number of namespaces filtered. */ 91 private final int mNativeNumNamespacesFiltered; 92 /** Number of schema types filtered. */ 93 private final int mNativeNumSchemaTypesFiltered; 94 /** The requested number of results in one page. */ 95 private final int mNativeRequestedPageSize; 96 /** The actual number of results returned in the current page. */ 97 private final int mNativeNumResultsReturnedCurrentPage; 98 /** 99 * Whether the function call is querying the first page. If it's not, Icing will fetch the 100 * results from cache so that some steps may be skipped. 101 */ 102 private final boolean mNativeIsFirstPage; 103 /** 104 * Time used to parse the query, including 2 parts: tokenizing and transforming tokens into an 105 * iterator tree. 106 */ 107 private final int mNativeParseQueryLatencyMillis; 108 /** Strategy of scoring and ranking. */ 109 @SearchSpec.RankingStrategy private final int mNativeRankingStrategy; 110 /** Number of documents scored. */ 111 private final int mNativeNumDocumentsScored; 112 /** Time used to score the raw results. */ 113 private final int mNativeScoringLatencyMillis; 114 /** Time used to rank the scored results. */ 115 private final int mNativeRankingLatencyMillis; 116 /** 117 * Time used to fetch the document protos. Note that it includes the time to snippet if {@link 118 * SearchStats#mNativeNumResultsWithSnippets} is greater than 0. 119 */ 120 private final int mNativeDocumentRetrievingLatencyMillis; 121 /** How many snippets are calculated. */ 122 private final int mNativeNumResultsWithSnippets; 123 /** Time passed while waiting to acquire the lock during native function calls. */ 124 private final int mNativeLockAcquisitionLatencyMillis; 125 /** Time used to send data across the JNI boundary from java to native side. */ 126 private final int mJavaToNativeJniLatencyMillis; 127 /** Time used to send data across the JNI boundary from native to java side. */ 128 private final int mNativeToJavaJniLatencyMillis; 129 /** The type of join performed. Zero if no join is performed */ 130 @JoinableValueType private final int mJoinType; 131 /** The total number of joined documents in the current page. */ 132 private final int mNativeNumJoinedResultsCurrentPage; 133 /** Time taken to join documents together. */ 134 private final int mNativeJoinLatencyMillis; 135 SearchStats(@onNull Builder builder)136 SearchStats(@NonNull Builder builder) { 137 Objects.requireNonNull(builder); 138 mPackageName = builder.mPackageName; 139 mDatabase = builder.mDatabase; 140 mStatusCode = builder.mStatusCode; 141 mTotalLatencyMillis = builder.mTotalLatencyMillis; 142 mRewriteSearchSpecLatencyMillis = builder.mRewriteSearchSpecLatencyMillis; 143 mRewriteSearchResultLatencyMillis = builder.mRewriteSearchResultLatencyMillis; 144 mJavaLockAcquisitionLatencyMillis = builder.mJavaLockAcquisitionLatencyMillis; 145 mAclCheckLatencyMillis = builder.mAclCheckLatencyMillis; 146 mVisibilityScope = builder.mVisibilityScope; 147 mNativeLatencyMillis = builder.mNativeLatencyMillis; 148 mNativeNumTerms = builder.mNativeNumTerms; 149 mNativeQueryLength = builder.mNativeQueryLength; 150 mNativeNumNamespacesFiltered = builder.mNativeNumNamespacesFiltered; 151 mNativeNumSchemaTypesFiltered = builder.mNativeNumSchemaTypesFiltered; 152 mNativeRequestedPageSize = builder.mNativeRequestedPageSize; 153 mNativeNumResultsReturnedCurrentPage = builder.mNativeNumResultsReturnedCurrentPage; 154 mNativeIsFirstPage = builder.mNativeIsFirstPage; 155 mNativeParseQueryLatencyMillis = builder.mNativeParseQueryLatencyMillis; 156 mNativeRankingStrategy = builder.mNativeRankingStrategy; 157 mNativeNumDocumentsScored = builder.mNativeNumDocumentsScored; 158 mNativeScoringLatencyMillis = builder.mNativeScoringLatencyMillis; 159 mNativeRankingLatencyMillis = builder.mNativeRankingLatencyMillis; 160 mNativeNumResultsWithSnippets = builder.mNativeNumResultsWithSnippets; 161 mNativeDocumentRetrievingLatencyMillis = builder.mNativeDocumentRetrievingLatencyMillis; 162 mNativeLockAcquisitionLatencyMillis = builder.mNativeLockAcquisitionLatencyMillis; 163 mJavaToNativeJniLatencyMillis = builder.mJavaToNativeJniLatencyMillis; 164 mNativeToJavaJniLatencyMillis = builder.mNativeToJavaJniLatencyMillis; 165 mJoinType = builder.mJoinType; 166 mNativeNumJoinedResultsCurrentPage = builder.mNativeNumJoinedResultsCurrentPage; 167 mNativeJoinLatencyMillis = builder.mNativeJoinLatencyMillis; 168 } 169 170 /** Returns the package name of the session. */ 171 @NonNull getPackageName()172 public String getPackageName() { 173 return mPackageName; 174 } 175 176 /** 177 * Returns the database name of the session. 178 * 179 * @return database name used by the session. {@code null} if and only if it is a global 180 * search(visibilityScope is {@link SearchStats#VISIBILITY_SCOPE_GLOBAL}). 181 */ 182 @Nullable getDatabase()183 public String getDatabase() { 184 return mDatabase; 185 } 186 187 /** Returns status of the search. */ 188 @AppSearchResult.ResultCode getStatusCode()189 public int getStatusCode() { 190 return mStatusCode; 191 } 192 193 /** Returns the total latency of the search. */ getTotalLatencyMillis()194 public int getTotalLatencyMillis() { 195 return mTotalLatencyMillis; 196 } 197 198 /** Returns how much time spent on rewriting the {@link SearchSpec}. */ getRewriteSearchSpecLatencyMillis()199 public int getRewriteSearchSpecLatencyMillis() { 200 return mRewriteSearchSpecLatencyMillis; 201 } 202 203 /** Returns how much time spent on rewriting the {@link android.app.appsearch.SearchResult}. */ getRewriteSearchResultLatencyMillis()204 public int getRewriteSearchResultLatencyMillis() { 205 return mRewriteSearchResultLatencyMillis; 206 } 207 208 /** Returns time passed while waiting to acquire the lock during Java function calls */ getJavaLockAcquisitionLatencyMillis()209 public int getJavaLockAcquisitionLatencyMillis() { 210 return mJavaLockAcquisitionLatencyMillis; 211 } 212 213 /** 214 * Returns time spent on ACL checking, which is the time spent filtering namespaces based on 215 * package permissions and Android permission access. 216 */ getAclCheckLatencyMillis()217 public int getAclCheckLatencyMillis() { 218 return mAclCheckLatencyMillis; 219 } 220 221 /** Returns the visibility scope of the search. */ 222 @VisibilityScope getVisibilityScope()223 public int getVisibilityScope() { 224 return mVisibilityScope; 225 } 226 227 /** Returns how much time spent on the native calls. */ getNativeLatencyMillis()228 public int getNativeLatencyMillis() { 229 return mNativeLatencyMillis; 230 } 231 232 /** Returns number of terms in the search string. */ getTermCount()233 public int getTermCount() { 234 return mNativeNumTerms; 235 } 236 237 /** Returns the length of the search string. */ getQueryLength()238 public int getQueryLength() { 239 return mNativeQueryLength; 240 } 241 242 /** Returns number of namespaces filtered. */ getFilteredNamespaceCount()243 public int getFilteredNamespaceCount() { 244 return mNativeNumNamespacesFiltered; 245 } 246 247 /** Returns number of schema types filtered. */ getFilteredSchemaTypeCount()248 public int getFilteredSchemaTypeCount() { 249 return mNativeNumSchemaTypesFiltered; 250 } 251 252 /** Returns the requested number of results in one page. */ getRequestedPageSize()253 public int getRequestedPageSize() { 254 return mNativeRequestedPageSize; 255 } 256 257 /** Returns the actual number of results returned in the current page. */ getCurrentPageReturnedResultCount()258 public int getCurrentPageReturnedResultCount() { 259 return mNativeNumResultsReturnedCurrentPage; 260 } 261 262 // TODO(b/185184738) Make it an integer to show how many pages having been returned. 263 /** Returns whether the function call is querying the first page. */ isFirstPage()264 public boolean isFirstPage() { 265 return mNativeIsFirstPage; 266 } 267 268 /** 269 * Returns time used to parse the query, including 2 parts: tokenizing and transforming tokens 270 * into an iterator tree. 271 */ getParseQueryLatencyMillis()272 public int getParseQueryLatencyMillis() { 273 return mNativeParseQueryLatencyMillis; 274 } 275 276 /** Returns strategy of scoring and ranking. */ 277 @SearchSpec.RankingStrategy getRankingStrategy()278 public int getRankingStrategy() { 279 return mNativeRankingStrategy; 280 } 281 282 /** Returns number of documents scored. */ getScoredDocumentCount()283 public int getScoredDocumentCount() { 284 return mNativeNumDocumentsScored; 285 } 286 287 /** Returns time used to score the raw results. */ getScoringLatencyMillis()288 public int getScoringLatencyMillis() { 289 return mNativeScoringLatencyMillis; 290 } 291 292 /** Returns time used to rank the scored results. */ getRankingLatencyMillis()293 public int getRankingLatencyMillis() { 294 return mNativeRankingLatencyMillis; 295 } 296 297 /** 298 * Returns time used to fetch the document protos. Note that it includes the time to snippet if 299 * {@link SearchStats#mNativeNumResultsWithSnippets} is not zero. 300 */ getDocumentRetrievingLatencyMillis()301 public int getDocumentRetrievingLatencyMillis() { 302 return mNativeDocumentRetrievingLatencyMillis; 303 } 304 305 /** Returns the number of the results in the page returned were snippeted. */ getResultWithSnippetsCount()306 public int getResultWithSnippetsCount() { 307 return mNativeNumResultsWithSnippets; 308 } 309 310 /** Returns time passed while waiting to acquire the lock during native function calls. */ getNativeLockAcquisitionLatencyMillis()311 public int getNativeLockAcquisitionLatencyMillis() { 312 return mNativeLockAcquisitionLatencyMillis; 313 } 314 315 /** Returns time used to send data across the JNI boundary from java to native side. */ getJavaToNativeJniLatencyMillis()316 public int getJavaToNativeJniLatencyMillis() { 317 return mJavaToNativeJniLatencyMillis; 318 } 319 320 /** Returns time used to send data across the JNI boundary from native to java side. */ getNativeToJavaJniLatencyMillis()321 public int getNativeToJavaJniLatencyMillis() { 322 return mNativeToJavaJniLatencyMillis; 323 } 324 325 /** Returns the type of join performed. Blank if no join is performed */ getJoinType()326 public @JoinableValueType int getJoinType() { 327 return mJoinType; 328 } 329 330 /** Returns the total number of joined documents in the current page. */ getNumJoinedResultsCurrentPage()331 public int getNumJoinedResultsCurrentPage() { 332 return mNativeNumJoinedResultsCurrentPage; 333 } 334 335 /** Returns the time taken to join documents together. */ getJoinLatencyMillis()336 public int getJoinLatencyMillis() { 337 return mNativeJoinLatencyMillis; 338 } 339 340 /** Builder for {@link SearchStats} */ 341 public static class Builder { 342 @NonNull final String mPackageName; 343 @Nullable String mDatabase; 344 @AppSearchResult.ResultCode int mStatusCode; 345 int mTotalLatencyMillis; 346 int mRewriteSearchSpecLatencyMillis; 347 int mRewriteSearchResultLatencyMillis; 348 int mJavaLockAcquisitionLatencyMillis; 349 int mAclCheckLatencyMillis; 350 int mVisibilityScope; 351 int mNativeLatencyMillis; 352 int mNativeNumTerms; 353 int mNativeQueryLength; 354 int mNativeNumNamespacesFiltered; 355 int mNativeNumSchemaTypesFiltered; 356 int mNativeRequestedPageSize; 357 int mNativeNumResultsReturnedCurrentPage; 358 boolean mNativeIsFirstPage; 359 int mNativeParseQueryLatencyMillis; 360 int mNativeRankingStrategy; 361 int mNativeNumDocumentsScored; 362 int mNativeScoringLatencyMillis; 363 int mNativeRankingLatencyMillis; 364 int mNativeNumResultsWithSnippets; 365 int mNativeDocumentRetrievingLatencyMillis; 366 int mNativeLockAcquisitionLatencyMillis; 367 int mJavaToNativeJniLatencyMillis; 368 int mNativeToJavaJniLatencyMillis; 369 @JoinableValueType int mJoinType; 370 int mNativeNumJoinedResultsCurrentPage; 371 int mNativeJoinLatencyMillis; 372 373 /** 374 * Constructor 375 * 376 * @param visibilityScope scope for the corresponding search. 377 * @param packageName name of the calling package. 378 */ Builder(@isibilityScope int visibilityScope, @NonNull String packageName)379 public Builder(@VisibilityScope int visibilityScope, @NonNull String packageName) { 380 mVisibilityScope = visibilityScope; 381 mPackageName = Objects.requireNonNull(packageName); 382 } 383 384 /** Sets the database used by the session. */ 385 @CanIgnoreReturnValue 386 @NonNull setDatabase(@ullable String database)387 public Builder setDatabase(@Nullable String database) { 388 mDatabase = database; 389 return this; 390 } 391 392 /** Sets the status of the search. */ 393 @CanIgnoreReturnValue 394 @NonNull setStatusCode(@ppSearchResult.ResultCode int statusCode)395 public Builder setStatusCode(@AppSearchResult.ResultCode int statusCode) { 396 mStatusCode = statusCode; 397 return this; 398 } 399 400 /** Sets total latency for the search. */ 401 @CanIgnoreReturnValue 402 @NonNull setTotalLatencyMillis(int totalLatencyMillis)403 public Builder setTotalLatencyMillis(int totalLatencyMillis) { 404 mTotalLatencyMillis = totalLatencyMillis; 405 return this; 406 } 407 408 /** Sets time used to rewrite the search spec. */ 409 @CanIgnoreReturnValue 410 @NonNull setRewriteSearchSpecLatencyMillis(int rewriteSearchSpecLatencyMillis)411 public Builder setRewriteSearchSpecLatencyMillis(int rewriteSearchSpecLatencyMillis) { 412 mRewriteSearchSpecLatencyMillis = rewriteSearchSpecLatencyMillis; 413 return this; 414 } 415 416 /** Sets time used to rewrite the search results. */ 417 @CanIgnoreReturnValue 418 @NonNull setRewriteSearchResultLatencyMillis(int rewriteSearchResultLatencyMillis)419 public Builder setRewriteSearchResultLatencyMillis(int rewriteSearchResultLatencyMillis) { 420 mRewriteSearchResultLatencyMillis = rewriteSearchResultLatencyMillis; 421 return this; 422 } 423 424 /** Sets time passed while waiting to acquire the lock during Java function calls. */ 425 @CanIgnoreReturnValue 426 @NonNull setJavaLockAcquisitionLatencyMillis(int javaLockAcquisitionLatencyMillis)427 public Builder setJavaLockAcquisitionLatencyMillis(int javaLockAcquisitionLatencyMillis) { 428 mJavaLockAcquisitionLatencyMillis = javaLockAcquisitionLatencyMillis; 429 return this; 430 } 431 432 /** 433 * Sets time spent on ACL checking, which is the time spent filtering namespaces based on 434 * package permissions and Android permission access. 435 */ 436 @CanIgnoreReturnValue 437 @NonNull setAclCheckLatencyMillis(int aclCheckLatencyMillis)438 public Builder setAclCheckLatencyMillis(int aclCheckLatencyMillis) { 439 mAclCheckLatencyMillis = aclCheckLatencyMillis; 440 return this; 441 } 442 443 /** Sets overall time used for the native function calls. */ 444 @CanIgnoreReturnValue 445 @NonNull setNativeLatencyMillis(int nativeLatencyMillis)446 public Builder setNativeLatencyMillis(int nativeLatencyMillis) { 447 mNativeLatencyMillis = nativeLatencyMillis; 448 return this; 449 } 450 451 /** Sets number of terms in the search string. */ 452 @CanIgnoreReturnValue 453 @NonNull setTermCount(int termCount)454 public Builder setTermCount(int termCount) { 455 mNativeNumTerms = termCount; 456 return this; 457 } 458 459 /** Sets length of the search string. */ 460 @CanIgnoreReturnValue 461 @NonNull setQueryLength(int queryLength)462 public Builder setQueryLength(int queryLength) { 463 mNativeQueryLength = queryLength; 464 return this; 465 } 466 467 /** Sets number of namespaces filtered. */ 468 @CanIgnoreReturnValue 469 @NonNull setFilteredNamespaceCount(int filteredNamespaceCount)470 public Builder setFilteredNamespaceCount(int filteredNamespaceCount) { 471 mNativeNumNamespacesFiltered = filteredNamespaceCount; 472 return this; 473 } 474 475 /** Sets number of schema types filtered. */ 476 @CanIgnoreReturnValue 477 @NonNull setFilteredSchemaTypeCount(int filteredSchemaTypeCount)478 public Builder setFilteredSchemaTypeCount(int filteredSchemaTypeCount) { 479 mNativeNumSchemaTypesFiltered = filteredSchemaTypeCount; 480 return this; 481 } 482 483 /** Sets the requested number of results in one page. */ 484 @CanIgnoreReturnValue 485 @NonNull setRequestedPageSize(int requestedPageSize)486 public Builder setRequestedPageSize(int requestedPageSize) { 487 mNativeRequestedPageSize = requestedPageSize; 488 return this; 489 } 490 491 /** Sets the actual number of results returned in the current page. */ 492 @CanIgnoreReturnValue 493 @NonNull setCurrentPageReturnedResultCount(int currentPageReturnedResultCount)494 public Builder setCurrentPageReturnedResultCount(int currentPageReturnedResultCount) { 495 mNativeNumResultsReturnedCurrentPage = currentPageReturnedResultCount; 496 return this; 497 } 498 499 /** 500 * Sets whether the function call is querying the first page. If it's not, Icing will fetch 501 * the results from cache so that some steps may be skipped. 502 */ 503 @CanIgnoreReturnValue 504 @NonNull setIsFirstPage(boolean nativeIsFirstPage)505 public Builder setIsFirstPage(boolean nativeIsFirstPage) { 506 mNativeIsFirstPage = nativeIsFirstPage; 507 return this; 508 } 509 510 /** 511 * Sets time used to parse the query, including 2 parts: tokenizing and transforming tokens 512 * into an iterator tree. 513 */ 514 @CanIgnoreReturnValue 515 @NonNull setParseQueryLatencyMillis(int parseQueryLatencyMillis)516 public Builder setParseQueryLatencyMillis(int parseQueryLatencyMillis) { 517 mNativeParseQueryLatencyMillis = parseQueryLatencyMillis; 518 return this; 519 } 520 521 /** Sets strategy of scoring and ranking. */ 522 @CanIgnoreReturnValue 523 @NonNull setRankingStrategy(@earchSpec.RankingStrategy int rankingStrategy)524 public Builder setRankingStrategy(@SearchSpec.RankingStrategy int rankingStrategy) { 525 mNativeRankingStrategy = rankingStrategy; 526 return this; 527 } 528 529 /** Sets number of documents scored. */ 530 @CanIgnoreReturnValue 531 @NonNull setScoredDocumentCount(int scoredDocumentCount)532 public Builder setScoredDocumentCount(int scoredDocumentCount) { 533 mNativeNumDocumentsScored = scoredDocumentCount; 534 return this; 535 } 536 537 /** Sets time used to score the raw results. */ 538 @CanIgnoreReturnValue 539 @NonNull setScoringLatencyMillis(int scoringLatencyMillis)540 public Builder setScoringLatencyMillis(int scoringLatencyMillis) { 541 mNativeScoringLatencyMillis = scoringLatencyMillis; 542 return this; 543 } 544 545 /** Sets time used to rank the scored results. */ 546 @CanIgnoreReturnValue 547 @NonNull setRankingLatencyMillis(int rankingLatencyMillis)548 public Builder setRankingLatencyMillis(int rankingLatencyMillis) { 549 mNativeRankingLatencyMillis = rankingLatencyMillis; 550 return this; 551 } 552 553 /** Sets time used to fetch the document protos. */ 554 @CanIgnoreReturnValue 555 @NonNull setDocumentRetrievingLatencyMillis(int documentRetrievingLatencyMillis)556 public Builder setDocumentRetrievingLatencyMillis(int documentRetrievingLatencyMillis) { 557 mNativeDocumentRetrievingLatencyMillis = documentRetrievingLatencyMillis; 558 return this; 559 } 560 561 /** Sets how many snippets are calculated. */ 562 @CanIgnoreReturnValue 563 @NonNull setResultWithSnippetsCount(int resultWithSnippetsCount)564 public Builder setResultWithSnippetsCount(int resultWithSnippetsCount) { 565 mNativeNumResultsWithSnippets = resultWithSnippetsCount; 566 return this; 567 } 568 569 /** Sets time passed while waiting to acquire the lock during native function calls. */ 570 @CanIgnoreReturnValue 571 @NonNull setNativeLockAcquisitionLatencyMillis( int nativeLockAcquisitionLatencyMillis)572 public Builder setNativeLockAcquisitionLatencyMillis( 573 int nativeLockAcquisitionLatencyMillis) { 574 mNativeLockAcquisitionLatencyMillis = nativeLockAcquisitionLatencyMillis; 575 return this; 576 } 577 578 /** Sets time used to send data across the JNI boundary from java to native side. */ 579 @CanIgnoreReturnValue 580 @NonNull setJavaToNativeJniLatencyMillis(int javaToNativeJniLatencyMillis)581 public Builder setJavaToNativeJniLatencyMillis(int javaToNativeJniLatencyMillis) { 582 mJavaToNativeJniLatencyMillis = javaToNativeJniLatencyMillis; 583 return this; 584 } 585 586 /** Sets time used to send data across the JNI boundary from native to java side. */ 587 @CanIgnoreReturnValue 588 @NonNull setNativeToJavaJniLatencyMillis(int nativeToJavaJniLatencyMillis)589 public Builder setNativeToJavaJniLatencyMillis(int nativeToJavaJniLatencyMillis) { 590 mNativeToJavaJniLatencyMillis = nativeToJavaJniLatencyMillis; 591 return this; 592 } 593 594 /** Sets whether or not this is a join query */ 595 @NonNull setJoinType(@oinableValueType int joinType)596 public Builder setJoinType(@JoinableValueType int joinType) { 597 mJoinType = joinType; 598 return this; 599 } 600 601 /** Set the total number of joined documents in a page. */ 602 @NonNull setNativeNumJoinedResultsCurrentPage(int nativeNumJoinedResultsCurrentPage)603 public Builder setNativeNumJoinedResultsCurrentPage(int nativeNumJoinedResultsCurrentPage) { 604 mNativeNumJoinedResultsCurrentPage = nativeNumJoinedResultsCurrentPage; 605 return this; 606 } 607 608 /** Sets time it takes to join documents together in icing. */ 609 @NonNull setNativeJoinLatencyMillis(int nativeJoinLatencyMillis)610 public Builder setNativeJoinLatencyMillis(int nativeJoinLatencyMillis) { 611 mNativeJoinLatencyMillis = nativeJoinLatencyMillis; 612 return this; 613 } 614 615 /** 616 * Constructs a new {@link SearchStats} from the contents of this {@link 617 * SearchStats.Builder}. 618 */ 619 @NonNull build()620 public SearchStats build() { 621 if (mDatabase == null) { 622 Preconditions.checkState( 623 mVisibilityScope != SearchStats.VISIBILITY_SCOPE_LOCAL, 624 "database can not be null if visibilityScope is local."); 625 } 626 627 return new SearchStats(/* builder= */ this); 628 } 629 } 630 } 631