2014 snapchat source code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.2 KiB

  1. //
  2. // SCManagedVideoCapturerLogger.m
  3. // Snapchat
  4. //
  5. // Created by Pinlin on 12/04/2017.
  6. // Copyright © 2017 Snapchat, Inc. All rights reserved.
  7. //
  8. #import "SCManagedVideoCapturerLogger.h"
  9. #import <SCFoundation/SCAssertWrapper.h>
  10. #import <SCFoundation/SCLog.h>
  11. #import <SCLogger/SCCameraMetrics.h>
  12. #import <SCLogger/SCLogger.h>
  13. @import QuartzCore;
  14. @interface SCManagedVideoCapturerLogger () {
  15. // For time profiles metric during start recording
  16. NSMutableDictionary *_startingStepsDelayTime;
  17. NSTimeInterval _beginStartTime;
  18. NSTimeInterval _lastCheckpointTime;
  19. NSTimeInterval _startedTime;
  20. }
  21. @end
  22. @implementation SCManagedVideoCapturerLogger
  23. - (instancetype)init
  24. {
  25. self = [super init];
  26. if (self) {
  27. _startingStepsDelayTime = [NSMutableDictionary dictionary];
  28. }
  29. return self;
  30. }
  31. - (void)prepareForStartingLog
  32. {
  33. _beginStartTime = CACurrentMediaTime();
  34. _lastCheckpointTime = _beginStartTime;
  35. [_startingStepsDelayTime removeAllObjects];
  36. }
  37. - (void)logStartingStep:(NSString *)stepname
  38. {
  39. SCAssert(_beginStartTime > 0, @"logger is not ready yet, please call prepareForStartingLog at first");
  40. NSTimeInterval currentCheckpointTime = CACurrentMediaTime();
  41. _startingStepsDelayTime[stepname] = @(currentCheckpointTime - _lastCheckpointTime);
  42. _lastCheckpointTime = currentCheckpointTime;
  43. }
  44. - (void)endLoggingForStarting
  45. {
  46. SCAssert(_beginStartTime > 0, @"logger is not ready yet, please call prepareForStartingLog at first");
  47. _startedTime = CACurrentMediaTime();
  48. [self logStartingStep:kSCCapturerStartingStepStartingWriting];
  49. _startingStepsDelayTime[kCapturerStartingTotalDelay] = @(CACurrentMediaTime() - _beginStartTime);
  50. }
  51. - (void)logEventIfStartingTooSlow
  52. {
  53. if (_beginStartTime > 0) {
  54. if (_startingStepsDelayTime.count == 0) {
  55. // It should not be here. We only need to log once.
  56. return;
  57. }
  58. SCLogGeneralWarning(@"Capturer starting delay(in second):%f", _startedTime - _beginStartTime);
  59. [[SCLogger sharedInstance] logEvent:kSCCameraMetricsVideoCapturerStartDelay parameters:_startingStepsDelayTime];
  60. // Clean all delay times after logging
  61. [_startingStepsDelayTime removeAllObjects];
  62. _beginStartTime = 0;
  63. }
  64. }
  65. @end