File: add_delayms.patch

package info (click to toggle)
firefox 147.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,484 kB
  • sloc: cpp: 7,607,246; javascript: 6,533,185; ansic: 3,775,227; python: 1,415,393; xml: 634,561; asm: 438,951; java: 186,241; sh: 62,752; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (96 lines) | stat: -rw-r--r-- 4,593 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
From a8797622ec030dcfb8a51d2d473111bc872a4fa5 Mon Sep 17 00:00:00 2001
From: David P <daparks@mozilla.com>
Date: Mon, 3 Feb 2025 10:51:45 -0800
Subject: [PATCH] Bug 1936020: Part 10 - Add --delaysMs to content analysis
 demo agent r=#dlp-reviewers!

Allows us to delay at a granularity finer than one second.

diff --git a/demo/agent.cc b/demo/agent.cc
index 3e168b0915a0c..4460a164722f5 100644
--- a/demo/agent.cc
+++ b/demo/agent.cc
@@ -25,7 +25,7 @@ constexpr char kPathSystem[] = "brcm_chrm_cas";
 std::string path = kPathSystem;
 bool use_queue = false;
 bool user_specific = false;
-std::vector<unsigned long> delays = {0};  // In seconds.
+std::vector<unsigned long> delays = {0};  // In milliseconds.
 unsigned long num_threads = 8u;
 std::string save_print_data_path = "";
 RegexArray toBlock, toWarn, toReport;
@@ -34,6 +34,7 @@ static std::string modeStr;
 
 // Command line parameters.
 constexpr const char* kArgDelaySpecific = "--delays=";
+constexpr const char* kArgDelayMsSpecific = "--delaysMs=";
 constexpr const char* kArgPath = "--path=";
 constexpr const char* kArgQueued = "--queued";
 constexpr const char* kArgThreads = "--threads=";
@@ -80,23 +81,22 @@ bool ParseCommandLine(int argc, char* argv[]) {
       }
       path = kPathUser;
       user_specific = true;
-    } else if (arg.find(kArgDelaySpecific) == 0) {
-      std::string delaysStr = arg.substr(strlen(kArgDelaySpecific));
+    } else if ((arg.find(kArgDelaySpecific) == 0) ||
+               (arg.find(kArgDelayMsSpecific) == 0)) {
+      bool isSecs = (arg.find(kArgDelaySpecific) == 0);
+      std::string delaysStr = arg.substr(strlen(isSecs ? kArgDelaySpecific : kArgDelayMsSpecific));
+      unsigned long scale = isSecs ? 1000 : 1;
       delays.clear();
       size_t posStart = 0, posEnd;
       unsigned long delay;
       while ((posEnd = delaysStr.find(',', posStart)) != std::string::npos) {
         delay = std::stoul(delaysStr.substr(posStart, posEnd - posStart));
-        if (delay > 30) {
-            delay = 30;
-        }
+        delay = std::min(delay*scale, 30*1000ul);
         delays.push_back(delay);
         posStart = posEnd + 1;
       }
       delay = std::stoul(delaysStr.substr(posStart));
-      if (delay > 30) {
-          delay = 30;
-      }
+      delay = std::min(delay*scale, 30*1000ul);
       delays.push_back(delay);
     } else if (arg.find(kArgPath) == 0) {
       path = arg.substr(strlen(kArgPath));
@@ -132,6 +132,7 @@ void PrintHelp() {
     << "Data containing the string 'block' blocks the request data from being used." << std::endl
     << std::endl << "Options:"  << std::endl
     << kArgDelaySpecific << "<delay1,delay2,...> : Add delays to request processing in seconds. Delays are limited to 30 seconds and are applied round-robin to requests. Default is 0." << std::endl
+    << kArgDelayMsSpecific << "<delay1,delay2,...> : Like --delays but takes durations in milliseconds." << std::endl
     << kArgPath << " <path> : Used the specified path instead of default. Must come after --user." << std::endl
     << kArgQueued << " : Queue requests for processing in a background thread" << std::endl
     << kArgThreads << " : When queued, number of threads in the request processing thread pool" << std::endl
diff --git a/demo/handler.h b/demo/handler.h
index 88599963c51b0..c578d72012848 100644
--- a/demo/handler.h
+++ b/demo/handler.h
@@ -131,9 +131,9 @@ class Handler : public content_analysis::sdk::AgentEventHandler {
     unsigned long delay = delays_[nextDelayIndex % delays_.size()];
     if (delay > 0) {
       aout.stream() << "Delaying response to " << event->GetRequest().request_token()
-                    << " for " << delay << "s" << std::endl<< std::endl;
+                    << " for " << delay << "ms" << std::endl<< std::endl;
       aout.flush();
-      std::this_thread::sleep_for(std::chrono::seconds(delay));
+      std::this_thread::sleep_for(std::chrono::milliseconds(delay));
     }
 
     // Send the response back to Google Chrome.
@@ -485,7 +485,7 @@ class QueuingHandler : public Handler {
       aout.stream() << "Thread: " << std::this_thread::get_id()
                     << std::endl;
       aout.stream() << "Delaying request processing for "
-                    << handler->delays()[handler->nextDelayIndex() % handler->delays().size()] << "s" << std::endl << std::endl;
+                    << handler->delays()[handler->nextDelayIndex() % handler->delays().size()] << "ms" << std::endl << std::endl;
       aout.flush();
 
       handler->AnalyzeContent(aout, std::move(event));
-- 
2.37.1.windows.1