← 返回 coinbase 的题目列表Log Stream Processing by Thread and Process
类型:online_judge
You are given a series of log streams. Your task is to group them by each thread and process, and track their activity. You need to read files, process the data, and store the results into the file system on a code testing platform. Implement an algorithm to achieve this.
Input:
log_stream: (List[str]) A list of log entries in the format of timestamp, thread_id, process_id, action.
start_time: (str) The start time for the query in "YYYY-MM-DD HH:MM:SS".
end_time: (str) The end time for the query.
Functionality description:
Group operation: For each log entry, group by thread thread_id and process process_id.
Find operation: Within the specified time period, find the threads and processes that appeared, and count the maximum number of occurrences during this period.
Requirements:
Process and group the log information.
Store to file for later access.
Support time period-based queries.
Output:
Generate a file containing information grouped by thread_id and process_id. Each line records the information of the thread and process and the number of actions taken.
Output the count of the maximum number of appearing threads and processes.
Example:
log_stream = [
"2023-07-14 10:00:00, 1, 100, start",
"2023-07-14 10:05:00, 2, 200, start",
"2023-07-14 10:10:00, 1, 100, stop",
"2023-07-14 10:20:00, 1, 100, start"
]
start_time = "2023-07-14 10:00:00"
end_time = "2023-07-14 10:15:00"
Generated file contents:
1, 100: 2
2, 200: 1
Count of maximum appearing threads and processes: 2
Example
Input
"2023-07-14 10:00:00, 1, 100, start", "2023-07-14 10:05:00, 2, 200, start", "2023-07-14 10:10:00, 1, 100, stop", "2023-07-14 10:20:00, 1, 100, start"; "2023-07-14 10:00:00"; "2023-07-14 10:15:00"